diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index a002542..112366f 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -10,35 +10,65 @@ env: jobs: build: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 + - name: Cache Target + id: cache-target + uses: actions/cache@v4 + with: + path: target + key: maven-target-${{ github.run.id }} - name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: 17 distribution: 'temurin' server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - - name: Build with Maven run: mvn -B package --file pom.xml - + publish_maven: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Restore cached Target + id: cache-primes-restore + uses: actions/cache/restore@v4 + with: + path: target/ + key: maven-target-${{ github.run.id }} - name: Publish to GitHub Packages Apache Maven run: mvn deploy env: GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password - + publish_container: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Restore cached Target + id: cache-primes-restore + uses: actions/cache/restore@v4 + with: + path: target/ + key: maven-target-${{ github.run.id }} + - uses: docker/metadata-action@v3 + id: metadata + with: + images: ghcr.io/${{ github.repository }} - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' - uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and Push the Docker image - run: | - docker build . --file Dockerfile --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/} - docker push -a ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and Push the container image + uses: int128/kaniko-action@v1 + with: + push: true + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + cache: true + cache-repository: ghcr.io/${{ github.repository }}/cache