Tax Calculator Spring CI/CD to AWS EKS #1
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: Tax Calculator Spring CI/CD to AWS EKS | |
| on: | |
| # push | |
| workflow_dispatch | |
| jobs: | |
| build-test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| service: [service-a, service-b] | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' # See 'Supported distributions' for available options | |
| java-version: '21' | |
| - name: Build and Test (Maven) | |
| working-directory: docker/app2-tax-calculator/spring/${{ matrix.service }} | |
| run: mvn -B clean verify | |
| - name: Upload Test Reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports | |
| path: docker/app2-tax-calculator/spring/${{ matrix.service }}/target/surefire-reports | |
| docker-build-push: | |
| runs-on: ubuntu-latest | |
| needs: build-test | |
| strategy: | |
| matrix: | |
| service: | |
| - { name: "service-a", docker_name: "tax-service-a", path: "docker/app2-tax-calculator/spring/service-a"} | |
| - { name: "service-b", docker_name: "tax-service-b", path: "docker/app2-tax-calculator/spring/service-b"} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' # See 'Supported distributions' for available options | |
| java-version: '21' | |
| - name: Build JAR for Docker | |
| working-directory: ${{ matrix.service.path }} | |
| run: mvn -B clean package -DskipTests | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ matrix.service.path }} | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/${{ matrix.service.docker_name }}:latest | |
| deploy-aws-eks: | |
| runs-on: ubuntu-latest | |
| needs: docker-build-push | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v5.1.1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-south-1 | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v4 | |
| - name: Update kubeconfig for EKS | |
| run: | | |
| aws eks update-kubeconfig --name hello-cluster --region ap-south-1 | |
| - name: Verify connection | |
| run: kubectl get nodes | |
| - name: Deploy to AWS (Kubernetes) | |
| run: | | |
| kubectl apply -f k8s/aws/app2-tax-calculator/service-a | |
| kubectl apply -f k8s/aws/app2-tax-calculator/service-b | |