Skip to content

Commit 12ac5dc

Browse files
Add support for ghcr (#2)
1 parent 989cf8f commit 12ac5dc

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

.github/workflows/docker-build.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 `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: mailcheck
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+
permissions:
47+
contents: read
48+
packages: write
49+
50+
steps:
51+
- uses: actions/checkout@v2
52+
53+
- name: Build image
54+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
55+
56+
- name: Log into registry
57+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
58+
59+
- name: Push image
60+
run: |
61+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
62+
63+
# Change all uppercase to lowercase
64+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
65+
66+
# Strip git ref prefix from version
67+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
68+
69+
# Use Docker `latest` tag convention
70+
[ "$VERSION" == "main" ] && 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)