ci: improve ci workflow #4
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 Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-push: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| environment: release | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 23 | |
| - uses: gradle/actions/setup-gradle@v4 | |
| - name: Get release version | |
| run: | | |
| VERSION=${{ github.event.release.tag_name || 'develop' }} | |
| # Remove the "v" prefix, if it exists | |
| IMAGE_TAG=${VERSION#v} | |
| RUN_IMAGE_REPOSITORY=${{ github.repository_owner }}/run-jammy-tiny-diagnostic | |
| echo "IMAGE_REPOSITORY=${{ github.repository }}" >> .env-add | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> .env-add | |
| echo "RUN_IMAGE_REPOSITORY=$RUN_IMAGE_REPOSITORY" >> .env-add | |
| echo "RUN_IMAGE_BUILDER_CACHE_REF=$RUN_IMAGE_REPOSITORY:cache-builder" >> .env-add | |
| cat .env-add | |
| cat .env-add >> $GITHUB_ENV | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.DOCKER_PAT }} | |
| - name: Run image - Cache builder | |
| run: | | |
| docker build \ | |
| --target builder \ | |
| --cache-from $RUN_IMAGE_BUILDER_CACHE_REF \ | |
| --tag $RUN_IMAGE_BUILDER_CACHE_REF \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| "docker/run-image" | |
| - name: Run image - build | |
| run: | | |
| docker build \ | |
| --cache-from $RUN_IMAGE_BUILDER_CACHE_REF \ | |
| --cache-from $RUN_IMAGE_REPOSITORY:latest \ | |
| --cache-from $RUN_IMAGE_REPOSITORY:develop \ | |
| --tag $RUN_IMAGE_REPOSITORY:develop \ | |
| --tag $RUN_IMAGE_REPOSITORY:$IMAGE_TAG \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| "docker/run-image" | |
| - name: Push image | |
| run: docker push $RUN_IMAGE_REPOSITORY --all-tags | |
| - name: Build Docker Image with bootBuildImage | |
| run: | | |
| ./gradlew bootBuildImage \ | |
| --imageName=$IMAGE_REPOSITORY \ | |
| -Pversion=$IMAGE_TAG | |
| -PrunImageName=$RUN_IMAGE_REPOSITORY:$IMAGE_TAG | |
| - name: Push Docker Image | |
| run: docker push $IMAGE_REPOSITORY --all-tags |