Skip to content

Commit 6101055

Browse files
authored
Create docker.yml
1 parent 7ce9d04 commit 6101055

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

.github/workflows/docker.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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: pythainlp-webdemo
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
74+
75+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
76+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)