ci: improve ci workflow #3
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} | |
| echo "IMAGE_REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
| cat $GITHUB_ENV | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.DOCKER_PAT }} | |
| - name: Build run image | |
| run: | | |
| docker build \ | |
| --target builder \ | |
| --cache-from $IMAGE_REPOSITORY:cache-builder \ | |
| --tag $IMAGE_REPOSITORY:cache-builder \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| "docker/run-image" | |
| - name: Push run image | |
| run: docker push $IMAGE_REPOSITORY:cache-builder | |
| - name: Build Docker Image with bootBuildImage | |
| run: | | |
| ./gradlew bootBuildImage \ | |
| --imageName=$IMAGE_REPOSITORY \ | |
| -Pversion=$IMAGE_TAG | |
| -PrunImageName=$IMAGE_REPOSITORY:cache-builder | |
| - name: Push Docker Image | |
| run: docker push $IMAGE_REPOSITORY:$IMAGE_TAG |