Build and publish docker image #193
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and publish docker image | |
| on: | |
| push: | |
| branches: | |
| - 'master' | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: 'Git ref (branch or tag) to build' | |
| required: false | |
| default: 'master' | |
| image_tag: | |
| description: 'Docker image tag to push (defaults to <branch>-<short-sha>)' | |
| required: false | |
| default: '' | |
| jobs: | |
| build-docker-image: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| # This is used to complete the identity challenge | |
| # with sigstore/fulcio when running outside of PRs. | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Build with Gradle | |
| uses: gradle/gradle-build-action@v2 | |
| - name: Run build with Gradle Wrapper | |
| run: ./gradlew build -x check -x :e2e-tests:build | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Compute image tag | |
| id: meta | |
| shell: bash | |
| run: | | |
| REF_INPUT='${{ inputs.ref }}' | |
| if [ -n "$REF_INPUT" ]; then | |
| REF="$REF_INPUT" | |
| else | |
| REF='${{ github.ref }}' | |
| fi | |
| # normalize to short branch/tag name | |
| REF_NAME="${REF##*/}" | |
| SHORT_SHA="${GITHUB_SHA::7}" | |
| if [ -n '${{ inputs.image_tag }}' ]; then | |
| TAG='${{ inputs.image_tag }}' | |
| else | |
| TAG="${REF_NAME}-${SHORT_SHA}" | |
| fi | |
| echo "IMAGE_TAG=$TAG" >> "$GITHUB_ENV" | |
| echo "REF_NAME=$REF_NAME" >> "$GITHUB_ENV" | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: '.' | |
| file: deploy/qyoga/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/ergonomic-code/trainer-advisor:${{ env.IMAGE_TAG }} | |
| - name: Also tag as latest (master only) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: '.' | |
| file: deploy/qyoga/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/ergonomic-code/trainer-advisor:latest |