From 9785b08c1850559887d57338615503a65f7722f4 Mon Sep 17 00:00:00 2001 From: jalowaini Date: Wed, 23 Apr 2025 13:50:38 +0300 Subject: [PATCH 1/2] Add GitHub Actions CI workflow for PR --- .github/workflows/ci-pr.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/ci-pr.yml diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml new file mode 100644 index 0000000..e8750f8 --- /dev/null +++ b/.github/workflows/ci-pr.yml @@ -0,0 +1,26 @@ +name: CI on Pull Request + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build with Maven + run: mvn clean install + + - name: Run Unit Tests + run: mvn test From eb10b62d64aa5a8f8f43a90cd5d1adb13dce8d55 Mon Sep 17 00:00:00 2001 From: jalowaini Date: Wed, 23 Apr 2025 18:06:15 +0300 Subject: [PATCH 2/2] Add GitHub Actions CD pipeline to deploy to EKS --- .github/workflows/cd-deploy.yml | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/cd-deploy.yml diff --git a/.github/workflows/cd-deploy.yml b/.github/workflows/cd-deploy.yml new file mode 100644 index 0000000..124608b --- /dev/null +++ b/.github/workflows/cd-deploy.yml @@ -0,0 +1,43 @@ + +name: CD on Push to Main + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Login to Amazon ECR + run: | + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REPO_URI }} + + - name: Build Docker image + run: | + docker build -t java-app:latest . + docker tag java-app:latest ${{ secrets.ECR_REPO_URI }}:latest + + - name: Push image to ECR + run: docker push ${{ secrets.ECR_REPO_URI }}:latest + + - name: Update kubeconfig for EKS + run: | + aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }} + + - name: Deploy to EKS + run: | + kubectl apply -f deployment.yaml + kubectl apply -f service.yaml