Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated main.yaml #1

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
111 changes: 111 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Hprofile Actions
on: [push, workflow_dispatch]
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: actapp
ECS_SERVICE: vproapp-act-svc
ECS_CLUSTER: vproapp-act
ECS_TASK_DEFINITION: aws-files/taskdeffile.json
CONTAINER_NAME: vproapp
jobs:
Testing:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Maven test
run: mvn test

- name: Checkstyle
run: mvn checkstyle:checkstyle

# Setup java 17 to be default (sonar-scanner requirement as of 5.x)
- name: Set Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'

# 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/

# Check the Quality Gate status.
- 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 }} #This is OPTIONAL

BUILD_AND_PUBLISH:
needs: Testing
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.RDS_USER }}/" src/main/resources/application.properties
sed -i "s/^jdbc.password.*$/jdbc.password\=${{ secrets.RDS_PASS }}/" src/main/resources/application.properties
sed -i "s/db01/${{ secrets.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_ACCESS_KEY }}
registry: ${{ secrets.REGISTRY }}
repo: actapp
region: ${{ env.AWS_REGION }}
tags: latest,${{ github.run_number }}
daemon_off: false
dockerfile: ./Dockerfile
context: ./

Deploy:
needs: BUILD_AND_PUBLISH
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_ACCESS_KEY }}
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_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ secrets.REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.run_number }}

- 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Prerequisites
#####
##
- JDK 11
- Maven 3
- MySQL 8
Expand Down
52 changes: 45 additions & 7 deletions aws-files/taskdeffile.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"family": "vproappstagetask",
"taskDefinitionArn": "arn:aws:ecs:us-east-1:895792017190:task-definition/vproapp-act-tdef:1",
"containerDefinitions": [
{
"name": "vproapp",
"image": "716657688884.dkr.ecr.us-east-2.amazonaws.com/actapp:latest",
"image": "895792017190.dkr.ecr.us-east-1.amazonaws.com/actapp",
"cpu": 0,
"portMappings": [
{
Expand All @@ -24,16 +24,52 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/vproappstagetask",
"awslogs-region": "us-east-2",
"awslogs-group": "/ecs/vproapp-act-tdef",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
}
},
"systemControls": []
}
],
"executionRoleArn": "arn:aws:iam::716657688884:role/ecsTaskExecutionRole",
"family": "vproapp-act-tdef",
"executionRoleArn": "arn:aws:iam::895792017190:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 1,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": [
"FARGATE"
],
Expand All @@ -43,10 +79,12 @@
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2024-05-29T21:45:22.017Z",
"registeredBy": "arn:aws:iam::895792017190:user/iamadmin",
"tags": [
{
"key": "Name",
"value": "vprofileappstagtaskdef"
"value": "vproapp-act-tdef"
}
]
}