Create README.md #29
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 App PipeLine | |
on: | |
push: | |
branches: [ "prod" ] | |
pull_request: | |
branches: [ "prod" ] | |
jobs: | |
app: | |
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' | |
- name: Cache Maven dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Login to Amazon ECR Private | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build Application JAR | |
run: mvn clean package | |
- name: List files | |
run: ls -R | |
- name: Docker Compose Build | |
run: docker compose build | |
- name: Tag and push docker image to Amazon ECR | |
run: | | |
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.IMAGE_REPO_URL }}:${{ github.run_id }} | |
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.IMAGE_REPO_URL }}:latest | |
docker push ${{ secrets.IMAGE_REPO_URL }}:${{ github.run_id }} | |
docker push ${{ secrets.IMAGE_REPO_URL }}:latest | |
- name: Download task definition | |
run: | | |
aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINITION_NAME }} --query taskDefinition > task-definition.json | |
- 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: task-definition.json | |
container-name: ${{ secrets.CONTAINER_NAME }} | |
image: ${{ secrets.IMAGE_REPO_URL }}:latest | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ secrets.SERVICE_NAME }} | |
cluster: ${{ secrets.CLUSTER_NAME }} | |
wait-for-service-stability: true | |
- name: Push to Docker Hub Container Registry | |
run: | | |
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.DOCKER_USERNAME }}/blog-api-server:${{ github.run_id }} | |
docker push ${{ secrets.DOCKER_USERNAME }}/blog-api-server:${{ github.run_id }} | |
docker push ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest | |