Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 179878c

Browse files
Create docker-publish.yml
1 parent c599231 commit 179878c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/docker-publish.yml

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

0 commit comments

Comments
 (0)