From bda3f1ebd7b72264c28ff878ad3ccfdc0b3d2d57 Mon Sep 17 00:00:00 2001 From: Favour Date: Mon, 8 Dec 2025 11:29:53 +0100 Subject: [PATCH] Add backend CI/CD pipeline --- .github/workflows/backend-container.yml | 80 +++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/backend-container.yml diff --git a/.github/workflows/backend-container.yml b/.github/workflows/backend-container.yml new file mode 100644 index 0000000..7a58169 --- /dev/null +++ b/.github/workflows/backend-container.yml @@ -0,0 +1,80 @@ +name: Java Backend Container CI/CD + +on: + push: + branches: [ main, master ] + paths: + - 'src/**' + - 'pom.xml' + - 'Dockerfile' + - '.github/workflows/backend-container.yml' + pull_request: + branches: [ main, master ] + paths: + - 'src/**' + - 'pom.xml' + - 'Dockerfile' + +jobs: + test-and-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn clean package -DskipTests + + - name: Run tests + run: mvn test + + - name: Run dependency check + run: mvn org.owasp:dependency-check-maven:check + + build-and-push-container: + needs: test-and-build + runs-on: ubuntu-latest + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKER_USERNAME }}/bank-backend + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=sha,prefix=commit- + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file