Skip to content

Commit 29df78c

Browse files
authoredMar 8, 2021
👷 Add Docker Workflow (#10)
1 parent 0e2f63e commit 29df78c

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
 

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# Publish `master` as Docker `latest` image.
6+
branches:
7+
- master
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
# TODO: Change variable to your image's name.
18+
IMAGE_NAME: dev-scribble
19+
20+
jobs:
21+
# Run tests.
22+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
23+
test:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- name: Run tests
30+
run: |
31+
if [ -f docker-compose.test.yml ]; then
32+
docker-compose --file docker-compose.test.yml build
33+
docker-compose --file docker-compose.test.yml run sut
34+
else
35+
docker build . --file Dockerfile
36+
fi
37+
38+
# Push image to GitHub Packages.
39+
# See also https://docs.docker.com/docker-hub/builds/
40+
push:
41+
# Ensure test job passes before pushing image.
42+
needs: test
43+
44+
runs-on: ubuntu-latest
45+
if: github.event_name == 'push'
46+
47+
steps:
48+
- uses: actions/checkout@v2
49+
50+
- name: Build image
51+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
52+
53+
- name: Log into registry
54+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
55+
56+
- name: Push image
57+
run: |
58+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
59+
60+
# Change all uppercase to lowercase
61+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
62+
63+
# Strip git ref prefix from version
64+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
65+
66+
# Strip "v" prefix from tag name
67+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
68+
69+
# Use Docker `latest` tag convention
70+
[ "$VERSION" == "master" ] && VERSION=latest
71+
72+
echo IMAGE_ID=$IMAGE_ID
73+
echo VERSION=$VERSION

‎Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:lts-alpine
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY . .
6+
7+
RUN npm ci
8+
9+
RUN npm run build
10+
11+
EXPOSE 8080
12+
13+
CMD ["npm", "start"]

0 commit comments

Comments
 (0)
Please sign in to comment.