diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 147f19b..68fe941 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,16 @@ jobs: distribution: 'temurin' java-version: '25' + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 @@ -45,6 +55,9 @@ jobs: publish: needs: build runs-on: ubuntu-latest + container: + image: gcr.io/kaniko-project/executor:debug + options: --entrypoint "" steps: - name: Checkout code @@ -56,37 +69,33 @@ jobs: name: build-artifact path: build/libs - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ env.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Generate version tag id: version run: | - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION_TAG=${GITHUB_REF#refs/tags/v} - elif [[ $GITHUB_REF == refs/heads/main ]]; then - SHORT_SHA=$(git rev-parse --short HEAD) + if [ "${GITHUB_REF#refs/tags/}" != "$GITHUB_REF" ]; then + VERSION_TAG=$(echo "$GITHUB_REF" | sed 's|refs/tags/v||') + elif [ "$GITHUB_REF" = "refs/heads/main" ]; then + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7) VERSION_TAG="main-${SHORT_SHA}" else - SHORT_SHA=$(git rev-parse --short HEAD) + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7) VERSION_TAG="develop-${SHORT_SHA}" fi echo "tag=$VERSION_TAG" >> $GITHUB_OUTPUT - echo "Generated version tag: $VERSION_TAG" - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: | - ${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:${{ steps.version.outputs.tag }} - ${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:latest - cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + - name: Set up Kaniko Docker config + run: | + mkdir -p /kaniko/.docker + echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"$(echo -n $DOCKERHUB_USERNAME:$DOCKERHUB_TOKEN | base64)\"}}}" > /kaniko/.docker/config.json + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image with Kaniko + run: | + /kaniko/executor \ + --context=$GITHUB_WORKSPACE \ + --dockerfile=$GITHUB_WORKSPACE/Dockerfile \ + --destination=${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:${{ steps.version.outputs.tag }} \ + --destination=${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:latest \ + --cache=true \ + --cache-repo=${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc-cache \ No newline at end of file diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 8ff5094..51ed626 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -20,6 +20,16 @@ jobs: distribution: 'temurin' java-version: '25' + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + - name: Setup Gradle uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d