Skip to content

Commit 129b9fd

Browse files
authored
Create docker-publish.yml
1 parent 2dccdd9 commit 129b9fd

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

.github/workflows/docker-publish.yml

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

0 commit comments

Comments
 (0)