1+ name : Deploy Event Service to Amazon ECS
2+
3+ on :
4+ push :
5+ branches : [ "main" ] # Pipeline runs every time you push to main
6+
7+ env :
8+ AWS_REGION : us-east-1
9+ ECR_REPOSITORY : event-service
10+ ECS_SERVICE : event-service
11+ ECS_CLUSTER : stream-seat-cluster
12+ CONTAINER_NAME : event-service-container # Make sure this matches your Task Definition
13+
14+ jobs :
15+ deploy :
16+ runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout Code
19+ uses : actions/checkout@v4
20+
21+ - name : Set up JDK 17
22+ uses : actions/setup-java@v3
23+ with :
24+ java-version : ' 17'
25+ distribution : ' temurin'
26+ cache : maven
27+
28+ - name : Build JAR with Maven
29+ run : mvn clean package -DskipTests
30+
31+ - name : Configure AWS credentials
32+ uses : aws-actions/configure-aws-credentials@v1
33+ with :
34+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
35+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+ aws-region : ${{ env.AWS_REGION }}
37+
38+ - name : Login to Amazon ECR
39+ id : login-ecr
40+ uses : aws-actions/amazon-ecr-login@v1
41+
42+ - name : Build, Tag, and Push Image to ECR
43+ env :
44+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
45+ run : |
46+ # Use buildx for the AMD64 architecture we need for Fargate
47+ docker buildx create --use
48+ docker buildx build --platform linux/amd64 \
49+ -t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
50+ --push .
51+
52+ - name : Force ECS Deployment
53+ run : |
54+ aws ecs update-service --cluster ${{ env.ECS_CLUSTER }} \
55+ --service ${{ env.ECS_SERVICE }} \
56+ --force-new-deployment
0 commit comments