Update README.md #11
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: Java CI with Maven | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build and test with Maven | |
run: mvn -B clean package --file pom.xml | |
- name: Build Docker image | |
run: | | |
docker build -t spring-boot-app . | |
- name: Tag Docker image | |
env: | |
USER_ID: ${{ secrets.USER_ID }} | |
ECR_REPOSITORY_NAME: ${{ secrets.ECR_REPOSITORY_NAME }} | |
run: | | |
docker tag spring-boot-app ${{ secrets.USER_ID }}.dkr.ecr.us-east-1.amazonaws.com/${{ secrets.ECR_REPOSITORY_NAME }}:latest | |
- 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-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Log in to Amazon ECR | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
USER_ID: ${{ secrets.USER_ID }} | |
run: | | |
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $USER_ID.dkr.ecr.$AWS_REGION.amazonaws.com | |
- name: Push Docker image to ECR | |
env: | |
USER_ID: ${{ secrets.USER_ID }} | |
ECR_REPOSITORY_NAME: ${{ secrets.ECR_REPOSITORY_NAME }} | |
run: | | |
docker push $USER_ID.dkr.ecr.us-east-1.amazonaws.com/$ECR_REPOSITORY_NAME:latest | |
- name: Update ECS service | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }} | |
SERVICE_NAME: ${{ secrets.SERVICE_NAME }} | |
run: | | |
aws ecs update-service \ | |
--cluster $CLUSTER_NAME \ | |
--service $SERVICE_NAME \ | |
--force-new-deployment \ | |
--region $AWS_REGION |