Skip to content

Commit a7ff28d

Browse files
authored
Create aws.yml
Updated
1 parent 6e5eab6 commit a7ff28d

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

aws.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy to Amazon ECS
2+
3+
on:
4+
push:
5+
branches: [ "gh-pages" ]
6+
7+
env:
8+
AWS_REGION: us-east-2 # AWS region from your EC2 and ECS details
9+
ECR_REPOSITORY: eoagritool # Amazon ECR repository name
10+
ECS_SERVICE: deploy # Amazon ECS service name
11+
ECS_CLUSTER: deploy # Amazon ECS cluster name
12+
ECS_TASK_DEFINITION: .aws/task-definition.json # Path to ECS task definition
13+
CONTAINER_NAME: eoagritool # Name of container in ECS task definition
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
name: Deploy to Amazon ECS
21+
runs-on: ubuntu-latest
22+
environment: production
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v1
30+
with:
31+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
aws-region: ${{ env.AWS_REGION }}
34+
35+
- name: Attach Administrator Policy to IAM User
36+
run: |
37+
aws iam attach-user-policy --user-name aimty --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
38+
39+
- name: Login to Amazon ECR
40+
id: login-ecr
41+
uses: aws-actions/amazon-ecr-login@v1
42+
43+
- name: Build, tag, and push image to Amazon ECR
44+
id: build-image
45+
env:
46+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
47+
IMAGE_TAG: ${{ github.sha }}
48+
run: |
49+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
50+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
51+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
52+
53+
- name: Update Amazon ECS task definition with new image
54+
id: task-def
55+
uses: aws-actions/amazon-ecs-render-task-definition@v1
56+
with:
57+
task-definition: ${{ env.ECS_TASK_DEFINITION }}
58+
container-name: ${{ env.CONTAINER_NAME }}
59+
image: ${{ steps.build-image.outputs.image }}
60+
61+
- name: Deploy Amazon ECS task definition
62+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
63+
with:
64+
task-definition: ${{ steps.task-def.outputs.task-definition }}
65+
service: ${{ env.ECS_SERVICE }}
66+
cluster: ${{ env.ECS_CLUSTER }}
67+
wait-for-service-stability: true

0 commit comments

Comments
 (0)