# Based on: https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md # Trigger and tag naming rules are based on the settings we were previously using at Docker Hub. name: Packaging Docker on: push: branches: - main tags: - 'v[0-9]+.[0-9]+.[0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - name: Extract metadata for tagging the Docker image id: meta uses: docker/metadata-action@v3 with: images: nlnetlabs/routinator flavor: | latest=false tags: | type=semver,pattern={{raw}} type=raw,value=unstable,enable=${{ github.ref == 'refs/heads/main' }} type=raw,value=latest,enable=${{ github.ref != 'refs/heads/main' && !contains(github.ref, '-') }} - name: Log into Docker Hub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_HUB_ID }} password: ${{ secrets.DOCKER_HUB_TOKEN }} # Build the image and tag it with a test tag we can use in the subsequent step when we invoke 'docker run'. - name: Build Docker image uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64 push: false load: true tags: nlnetlabs/routinator:sanitycheck # Do a basic sanity check of the created image using the test tag to select the image to run. - name: Sanity check run: | docker run --rm nlnetlabs/routinator:sanitycheck --version # Push the image and tags to Docker Hub. # The build uses the cached build outputs from the step above so we don't have to wait for the build again. # # On push of a tag to refs/tags/v1.2.3 the Docker tags will be 'v1.2.3' and 'latest' because of: # type=semver,pattern={{raw}} # type=raw,value=latest,enable=${{ github.ref != 'refs/heads/main' && !contains(github.ref, '-') }} # ^^^^^^^^^^^^^ true, not main ^^^^^^^^^ true, no dash found # # On push of a tag to refs/tags/v1.2.3-rc1 the Docker tags will be 'v1.2.3' but NOT 'latest' because of: # type=semver,pattern={{raw}} # type=raw,value=latest,enable=${{ github.ref != 'refs/heads/main' && !contains(github.ref, '-') }} # ^^^^^^^^^^^^^ true, not main ^^^^^^^^^ false, dash found # # On push to refs/heads/main the Docker tag will be 'unstable' because of: # type=raw,value=unstable,enable=${{ github.ref == 'refs/heads/main' }} - name: Push built Docker image to Docker Hub uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64 push: true tags: ${{ steps.meta.outputs.tags }}