Skip to content

Commit 4281c3f

Browse files
committed
Deploy to GCR with Github Actions
1 parent edba7a2 commit 4281c3f

File tree

7 files changed

+124
-5
lines changed

7 files changed

+124
-5
lines changed

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
chart/*
2+
dist/*
3+
.editorconfig
4+
.env
5+
*.env
6+
.git/*
7+
.github/*
8+
.gitignore
9+
*.md
10+
node_modules/*
11+
nodemon.json
12+
now.json
13+
*.sh
14+
tmp/*

.github/workflows/gcr-deploy.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
# Environment variables available to all jobs and steps in this workflow
10+
# NOTE: these aren't really secret, but there aren't non-secret settings
11+
env:
12+
RUN_PROJECT: ${{ secrets.RUN_PROJECT }}
13+
RUN_REGION: ${{ secrets.RUN_REGION }}
14+
RUN_SERVICE: ${{ secrets.RUN_SERVICE }}
15+
16+
jobs:
17+
setup-build-deploy:
18+
name: Setup, Build, and Deploy
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v1
24+
25+
# Setup gcloud CLI
26+
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
27+
with:
28+
version: '275.0.0'
29+
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
30+
service_account_key: ${{ secrets.GCP_SA_KEY }}
31+
32+
# Configure gcloud CLI
33+
- name: gcloud Set up
34+
run: |
35+
gcloud config set project ${RUN_PROJECT}
36+
37+
# Build and push image to Google Container Registry
38+
- name: Build
39+
run: |
40+
docker build \
41+
--build-arg COMMIT=${GITHUB_SHA:0:7} \
42+
--build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
43+
--tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA .
44+
45+
- name: GCloud auth to docker
46+
run: |
47+
gcloud auth configure-docker
48+
49+
- name: Push to registry
50+
run: |
51+
docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA
52+
53+
# Deploy image to Cloud Run
54+
- name: Deploy
55+
run: |
56+
gcloud run deploy ${RUN_SERVICE} \
57+
--allow-unauthenticated \
58+
--image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
59+
--platform managed \
60+
--project ${RUN_PROJECT} \
61+
--region ${RUN_REGION}

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:14 as base
2+
RUN groupadd -r appuser && \
3+
useradd --create-home --gid appuser --home-dir /app --no-log-init --system appuser
4+
5+
FROM base AS build
6+
WORKDIR /app
7+
USER appuser
8+
COPY --chown=appuser:appuser . .
9+
RUN yarn install && \
10+
yarn run build
11+
12+
FROM base AS run
13+
ARG COMMIT="(not set)"
14+
ARG LASTMOD="(not set)"
15+
ENV COMMIT=$COMMIT
16+
ENV LASTMOD=$LASTMOD
17+
WORKDIR /app
18+
USER appuser
19+
COPY --chown=appuser:appuser . .
20+
#COPY --chown=appuser:appuser --from=build /app/dist /app/dist
21+
RUN yarn install --production
22+
EXPOSE 4000
23+
ENV PORT 4000
24+
CMD ["yarn", "run", "start"]
25+

docker-run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
docker build -t regexplanet-xregexp .
8+
docker run \
9+
-it \
10+
--publish 4000:4000 \
11+
--expose 4000 \
12+
--env PORT='4000' \
13+
--env COMMIT=$(git rev-parse --short HEAD)-local \
14+
--env LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
15+
regexplanet-xregexp
16+

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
"version": "0.0.1",
44
"main": "server.js",
55
"scripts": {
6+
"build": "true",
67
"start": "node server.js"
78
},
8-
"dependencies": {
9-
"express": "^4.15.4"
10-
},
9+
"dependencies": {},
1110
"engines": {
12-
"node": "10"
11+
"node": "14"
1312
},
1413
"repository": {
1514
"url": "https://www.github.com/fileformat/regexplanet-xregexp"

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,4 @@ http.createServer(function (request, response)
468468

469469
}).listen(port);
470470

471-
util.puts("Server running on port " + port);
471+
console.log("Server running on port " + port);

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+

0 commit comments

Comments
 (0)