git init
npm init
npm i -S express
index.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log('Hello world received a request.');
const target = process.env.TARGET || 'World';
res.send(`Hello ${target}!`);
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Hello world listening on port', port);
});
Dockerfile.
FROM node:10
WORKDIR /usr/src/app
COPY package.json package*.json ./
RUN npm install --only=production
COPY . .
CMD [ "node", "index.js" ]
gcloud config get-value project
gcloud builds submit --tag gcr.io/[PROJECT-ID]/helloworld
gcloud beta run deploy --image gcr.io/[PROJECT-ID]/helloworld
