diff --git a/.github/workflows/build-service.yml b/.github/workflows/build-service.yml index ed6ae3b5..40378e5d 100644 --- a/.github/workflows/build-service.yml +++ b/.github/workflows/build-service.yml @@ -24,33 +24,51 @@ env: jobs: build: - if: github.event_name == 'pull_request' runs-on: ubuntu-latest + defaults: + run: + working-directory: power-pay-backend steps: - - uses: actions/checkout@v4 + - name: Clone the project + uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - name: Maven build - run: cd power-pay-backend && mvn clean package -q - + run: mvn clean package -q + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: power-pay-backend + path: power-pay-backend/target/*.jar + docker-build: - if: github.event_name != 'pull_request' + needs: + - build runs-on: ubuntu-latest + defaults: + run: + working-directory: power-pay-backend permissions: contents: read packages: write steps: - - uses: actions/checkout@v4 - + - name: Clone the project + uses: actions/checkout@v4 + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: power-pay-backend + path: power-pay-backend/power-pay-backend/target + - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: - registry: ghcr.io + registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} @@ -58,7 +76,7 @@ jobs: uses: ASzc/change-string-case-action@v6 with: string: ${{ env.IMAGE_NAME}} - + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 @@ -67,11 +85,8 @@ jobs: - name: Build and push image uses: docker/build-push-action@v5 - if: github.event_name != 'pull_request' with: - context: ./power-pay-backend - file: ./power-pay-backend/Dockerfile - push: true + push: "${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}" tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/power-pay-backend/.dockerignore b/power-pay-backend/.dockerignore index a2d4d320..41bfb2b2 100644 --- a/power-pay-backend/.dockerignore +++ b/power-pay-backend/.dockerignore @@ -2,4 +2,6 @@ !src !pom.xml !mvnw -!.mvn \ No newline at end of file +!.mvn +# ignore target folder but not the jar files in it +!target/*.jar \ No newline at end of file diff --git a/power-pay-backend/Dockerfile b/power-pay-backend/Dockerfile index 48cea0b2..ddb9a712 100644 --- a/power-pay-backend/Dockerfile +++ b/power-pay-backend/Dockerfile @@ -1,12 +1,3 @@ -FROM eclipse-temurin:21-jdk as builder - -WORKDIR /app - -COPY . . - -RUN ./mvnw clean package - - FROM eclipse-temurin:21-jre-alpine LABEL maintainer="PowerPay Team " @@ -14,7 +5,7 @@ LABEL application="power-pay-backend" ENV APP_VERSION=0.0.1-SNAPSHOT -COPY --from=builder /app/target/power-pay-backend-${APP_VERSION}.jar /app/app.jar +COPY ./target/power-pay-backend-${APP_VERSION}.jar /app/app.jar EXPOSE 8080