99 - v*
1010 # Run tests for any PRs.
1111 pull_request :
12-
13- # Sets permissions of the GITHUB_TOKEN
14- permissions :
15- contents : read
16- packages : write
17-
1812env :
1913 # TODO: Change variable to your image's name.
2014 IMAGE_NAME : syncstreamapi
@@ -25,66 +19,62 @@ jobs:
2519 runs-on : ubuntu-latest
2620 steps :
2721 - uses : actions/checkout@v2
28- - name : Set up QEMU
29- uses : docker/setup-qemu-action@v2
30- - name : Set up Docker Buildx
31- uses : docker/setup-buildx-action@v2
3222 - name : Run tests
3323 run : |
3424 if [ -f docker-compose.test.yml ]; then
3525 docker-compose --file docker-compose.test.yml build
3626 docker-compose --file docker-compose.test.yml run sut
3727 else
38- # Test build for amd64 only to save time
39- docker buildx build . --file Dockerfile --platform linux/amd64
28+ docker build . --file Dockerfile
4029 fi
41- # Push image to GitHub Packages.
42- # See also https://docs.docker.com/docker-hub/builds/
30+ # Push multi-architecture image to GitHub Packages.
4331 push :
4432 # Ensure test job passes before pushing image.
4533 needs : test
4634 runs-on : ubuntu-latest
4735 if : github.event_name == 'push'
4836 steps :
49- - uses : actions/checkout@v2
37+ - name : Checkout code
38+ uses : actions/checkout@v2
39+
5040 - name : Set up QEMU
51- uses : docker/setup-qemu-action@v2
41+ uses : docker/setup-qemu-action@v1
42+
5243 - name : Set up Docker Buildx
53- uses : docker/setup-buildx-action@v2
54- - name : Prepare
44+ uses : docker/setup-buildx-action@v1
45+
46+ - name : Login to GitHub Container Registry
47+ uses : docker/login-action@v1
48+ with :
49+ registry : docker.pkg.github.com
50+ username : ${{ github.actor }}
51+ password : ${{ secrets.GITHUB_TOKEN }}
52+
53+ - name : Prepare image metadata
5554 id : prep
5655 run : |
57- VERSION=noop
58- if [ "${{ github.event_name }}" = "schedule" ]; then
59- VERSION=nightly
60- elif [[ $GITHUB_REF == refs/tags/* ]]; then
61- VERSION=${GITHUB_REF#refs/tags/}
62- elif [[ $GITHUB_REF == refs/heads/* ]]; then
63- VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
64- if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
65- VERSION=latest
66- fi
67- elif [[ $GITHUB_REF == refs/pull/* ]]; then
68- VERSION=pr-${{ github.event.number }}
69- fi
70- echo "version=${VERSION}" >> $GITHUB_OUTPUT
71- echo "VERSION=${VERSION}" >> $GITHUB_ENV
56+ IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
7257
73- IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}
7458 # Change all uppercase to lowercase
7559 IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
76- echo "image=${IMAGE_ID}" >> $GITHUB_OUTPUT
77- echo "IMAGE_ID=${IMAGE_ID}" >> $GITHUB_ENV
78- - name : Log into registry
79- uses : docker/login-action@v2
80- with :
81- registry : docker.pkg.github.com
82- username : ${{ github.actor }}
83- password : ${{ secrets.GITHUB_TOKEN }}
84- - name : Build and push image
85- uses : docker/build-push-action@v4
60+
61+ # Strip git ref prefix from version
62+ VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
63+
64+ # Strip "v" prefix from tag name
65+ [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
66+
67+ # Use Docker `latest` tag convention
68+ [ "$VERSION" == "master" ] && VERSION=latest
69+
70+ echo "::set-output name=image::$IMAGE_ID"
71+ echo "::set-output name=version::$VERSION"
72+
73+ - name : Build and push
74+ uses : docker/build-push-action@v2
8675 with :
8776 context : .
77+ file : ./Dockerfile
8878 platforms : linux/amd64,linux/arm64
8979 push : true
90- tags : ${{ env.IMAGE_ID }}:${{ env.VERSION }}
80+ tags : ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.version }}
0 commit comments