It's quite possible to do this using the Cloud Build API. Here's a simple example using the client libary for Node.js.
exports.createDockerBuild = async (req, res) => {
const google = require('googleapis').google;
const cloudbuild = google.cloudbuild({version: 'v1'});
const client = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform']
});
const projectId = await google.auth.getProjectId();
const resource = {
"source": {
"storageSource": {
"bucket": "my-source-bucket",
"object": "my-nodejs-source.tar.gz"
}
},
"steps": [{
"name": "gcr.io/cloud-builders/docker",
"args": [
"build",
"-t",
"gcr.io/my-project-name/my-nodejs-image",
"standard-hello-world"
]
}],
"images": ["gcr.io/$PROJECT_ID/my-nodejs-image"]
};
const params = {projectId, resource, auth: client};
result= await cloudbuild.projects.builds.create(params);
res.status(200).send("200 - Build Submitted");
};
My source code was in a bucket but you could pull it from a repo just as easily.
Bear in mind that you'll need to use the Node.js 8 beta runtime for the async stuff to work.