package icon indicating copy to clipboard operation
package copied to clipboard

Support Google Container Registry

Open DazWilkin opened this issue 7 years ago • 3 comments

[Am a Googler ;-)] Google Container Registry (GCR) provides Google Cloud Platform (GCP) users with a convenient private Docker registry. The GCP command-line aka gcloud provides convenience wrappers for docker push|pull so it's trivial to extend metaparticle to support GCR with a slightly revised 'push' function.

Here for JavaScript but other languages are same-same...

Add e.g. gcr-builder.js:

(function () {
    var shell = require('shelljs');

    module.exports.build = (img) => {
        shell.exec(`docker build -t ${img} .`);
    };

    module.exports.publish = (img) => {
        shell.exec(`gcloud docker -- push ${img}`);
    };
})();

Augment index.js:

    selectBuilder = (buildSpec) => {
        switch(buildSpec) {
            case 'docker':
                return require('./docker-builder');
            case 'gcr':
                return require('./gcr-builder');
            default:
                throw `Unknown builder: ${buildSpec}`;
        }
    }

Then, reflect the new config in mp.containerize:

const projectID = [PROJECT-ID]
const GCR = `gcr.io/${projectID}`
...
mp.containerize(
	{
		builder: "gcr",
		ports: [8080],
		repository: GCR,
		publish: true,
		public: true,
	},
	() => {
		server.listen(port, (err) => {
			if (err) {
				return console.log("server startup error: ", err);
			}
			console.log(`server up on ${port}`);
		});
	}
);

Then npm start:

npm start

> [email protected] start /.../metaparticle/package/tutorials/javascript
> node ./index.js

Sending build context to Docker daemon  670.2kB
Step 1/4 : FROM node:6-alpine
 ---> 29428556c0cb
Step 2/4 : COPY ./ /metaparticle-example/
 ---> bfa18eb16959
Step 3/4 : RUN npm --prefix /metaparticle-example/ install
 ---> Running in 8343230e3a75
npm WARN [email protected] No repository field.
 ---> a122411d31fd
Removing intermediate container 8343230e3a75
Step 4/4 : CMD npm --prefix /metaparticle-example/ start
 ---> Running in 37356ae1e80d
 ---> e27343f47400
Removing intermediate container 37356ae1e80d
Successfully built e27343f47400
Successfully tagged gcr.io/[PROJECT-ID]/metaparticle-example:latest
The push refers to a repository [gcr.io/[PROJECT-ID]/metaparticle-example]
0163fc9a0d9d: Preparing
d8b55f59c7cc: Preparing
06a3955bac48: Preparing
8aebbd0f4dee: Preparing
52a5560f4ca0: Preparing
8aebbd0f4dee: Layer already exists
06a3955bac48: Layer already exists
52a5560f4ca0: Layer already exists
0163fc9a0d9d: Pushed
d8b55f59c7cc: Pushed
latest: digest: sha256:2a17daae09a4e3b7fc76b7f861fb734aca28f4c423792f65a3a05ed6c79bf25e size: 1368
3bcddd5dce12db8e7079996794112169a437bdb5095c0874dc56971387098040

> [email protected] start /metaparticle-example
> node ./index.js

server up on 8080

and:

image

DazWilkin avatar Dec 08 '17 23:12 DazWilkin

Would be happy to see a PR for this :)

brendandburns avatar Dec 10 '17 05:12 brendandburns

(would be interested to see how Google Container Builder could fit in here too)

brendandburns avatar Dec 10 '17 05:12 brendandburns

@brendanburns just off the top of my head,

The user could set up the metaparticle binary to run in GCB via CI with the cloud-builders/docker image, but this sounds like a strange workflow.

We could also use gcloud locally to send the build context to GCB via a build request. This seems more in line with how metaparticle currently works, but the local CLI for container builder is seeing active development.

stealthybox avatar Dec 11 '17 17:12 stealthybox