|
| 1 | +# jerm-IT Docker image build for hub.docker.com |
| 2 | +name: Docker images |
| 3 | + |
| 4 | +# Run this Build for all pushes to 'master' or develop branch, or tagged releases. |
| 5 | +# Also run for PRs to ensure PR doesn't break Docker build process |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + - main |
| 11 | + - develop |
| 12 | + tags: |
| 13 | + - 'v**' |
| 14 | + # Allows you to run this workflow manually from the Actions tab |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | + pull_request: |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + docker: |
| 24 | + # Ensure this job never runs on forked repos. It's only executed for 'jerm/snipe-it' |
| 25 | + if: github.repository == 'grokability/jerm-it' |
| 26 | + runs-on: ubuntu-latest-arm |
| 27 | + env: |
| 28 | + # Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action) |
| 29 | + # For a new commit on default branch (master), use the literal tag 'latest' on Docker image. |
| 30 | + # For a new commit on other branches, use the branch name as the tag for Docker image. |
| 31 | + # For a new tag, copy that tag name as the tag for Docker image. |
| 32 | + IMAGE_TAGS: | |
| 33 | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} |
| 34 | + type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} |
| 35 | + type=ref,event=tag |
| 36 | + type=semver,pattern=v{{major}}-latest |
| 37 | + type=pep440,pattern=v{{major}}-latest-release |
| 38 | + # Define default tag "flavor" for docker/metadata-action per |
| 39 | + # https://github.com/docker/metadata-action#flavor-input |
| 40 | + # We turn off 'latest' tag by default. |
| 41 | + TAGS_FLAVOR: | |
| 42 | + latest=false |
| 43 | +
|
| 44 | + steps: |
| 45 | + # https://github.com/actions/checkout |
| 46 | + - name: Checkout codebase |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + # https://github.com/docker/setup-buildx-action |
| 50 | + - name: Setup Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@v3 |
| 52 | + |
| 53 | + # https://github.com/docker/login-action |
| 54 | + - name: Login to DockerHub |
| 55 | + # Only login if not a PR, as PRs only trigger a Docker build and not a push |
| 56 | + if: github.event_name != 'pull_request' |
| 57 | + uses: docker/login-action@v3 |
| 58 | + with: |
| 59 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} |
| 61 | + |
| 62 | + ############################################### |
| 63 | + # Build/Push the 'jermgroks/jerm-it' image |
| 64 | + ############################################### |
| 65 | + # https://github.com/docker/metadata-action |
| 66 | + # Get Metadata for docker_build step below |
| 67 | + - name: Sync metadata (tags, labels) from GitHub to Docker for 'jerm-it' image |
| 68 | + id: meta_build |
| 69 | + uses: docker/metadata-action@v5 |
| 70 | + with: |
| 71 | + images: jermgroks/jerm-it |
| 72 | + tags: ${{ env.IMAGE_TAGS }} |
| 73 | + flavor: ${{ env.TAGS_FLAVOR }} |
| 74 | + |
| 75 | + # https://github.com/docker/build-push-action |
| 76 | + - name: Build and push 'jerm-it' image |
| 77 | + id: docker_build |
| 78 | + uses: docker/build-push-action@v6 |
| 79 | + with: |
| 80 | + context: . |
| 81 | + file: ./Dockerfile |
| 82 | + platforms: linux/arm64 |
| 83 | + # For pull requests, we run the Docker build (to ensure no PR changes break the build), |
| 84 | + # but we ONLY do an image push to DockerHub if it's NOT a PR |
| 85 | + push: ${{ github.event_name != 'pull_request' }} |
| 86 | + # Use tags / labels provided by 'docker/metadata-action' above |
| 87 | + tags: ${{ steps.meta_build.outputs.tags }} |
| 88 | + labels: ${{ steps.meta_build.outputs.labels }} |
0 commit comments