CI/CD Pipeline #21
This file contains 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: CI/CD Pipeline | ||
env: | ||
AWS_REGION: us-east-1 | ||
ECR_REPO: actions_repo | ||
ECS_CLUSTER: github-action-cluster | ||
ECS_TASK_DEF: task-def-json/taskdef.json | ||
ECS_SERVICE: cicd-actions-service | ||
CONTAINER_NAME: actions | ||
on: workflow_dispatch | ||
jobs: | ||
TEST-CQ-steps: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: for Testing | ||
uses: actions/checkout@v4 | ||
- name: Maven test | ||
run: mvn test install | ||
- name: Checkstyle | ||
run: mvn checkstyle:checkstyle | ||
- name: Set Java 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: "temurin" | ||
java-version: "11" | ||
# Setup sonar-scanner | ||
- name: Setup SonarQube | ||
uses: warchant/setup-sonar-scanner@v7 | ||
# Run sonar-scanner | ||
- name: SonarQube Scan | ||
run: sonar-scanner | ||
-Dsonar.host.url=${{ secrets.SONAR_URL }} | ||
-Dsonar.login=${{ secrets.SONAR_TOKEN}} | ||
-Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} | ||
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} | ||
-Dsonar.sources=src/ | ||
-Dsonar.junit.reportsPath=target/surefire-reports/ | ||
-Dsonar.jacoco.reportsPath=target/jacoco.exec | ||
-Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml | ||
-Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ | ||
- name: SonarQube Quality Gate check | ||
id: sonarqube-quality-gate-check | ||
uses: sonarsource/sonarqube-quality-gate-action@master | ||
# Force to fail step after specific time. | ||
timeout-minutes: 5 | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
SONAR_HOST_URL: ${{ secrets.SONAR_URL }} | ||
BUILD_AND_PUSH: | ||
needs: TEST-CQ-steps | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Code checkout | ||
uses: actions/checkout@v4 | ||
- name: Update application.properties file | ||
run: | | ||
sed -i "s/^jdbc.username.*$/jdbc.username\=${{ secrets.AWS_RDS_USER }}/" src/main/resources/application.properties | ||
sed -i "s/^jdbc.password.*$/jdbc.password\=${{ secrets.AWS_RDS_PASS }}/" src/main/resources/application.properties | ||
sed -i "s/db01/${{ secrets.AWS_RDS_ENDPOINT }}/" src/main/resources/application.properties | ||
- name: Build & Upload image to ECR | ||
uses: appleboy/docker-ecr-action@master | ||
with: | ||
access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
secret_key: ${{ secrets.AWS_SECRET_KEY_ID }} | ||
registry: ${{ secrets.AWS_ECR_ID }} | ||
repo: actions_repo | ||
region: ${{ env.AWS_REGION }} | ||
tags: latest,${{ github.run_number }} | ||
daemon_off: false | ||
dockerfile: ./Dockerfile | ||
context: ./ | ||
DEPLOY_ON_ECS: | ||
needs: BUILD_AND_PUSH | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Code checkout | ||
uses: actions/checkout@v4 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_ID }} | ||
aws-region: ${{env.AWS_REGION}} | ||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: ${{env.ECS_TASK_DEF}} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ secret.AWS_ECR_ID }}/${{ env.ECR_REPO }}:${{ github.run_number }} | ||
Check failure on line 101 in .github/workflows/main.yml GitHub Actions / CI/CD PipelineInvalid workflow file
|
||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{env.ECS_SERVICE}} | ||
cluster: ${{env.ECS_CLUSTER}} | ||
wait-for-service-stability: true |