-
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (67 loc) · 2.75 KB
/
aws.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Deploy to AWS ECS
on:
push:
branches: ['main'] # Triggers on push to main
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
env:
ECR_REPOSITORY: app # Set this to your Amazon ECR repository name
ECS_SERVICE: SkyDevOps # Set this to your Amazon ECS service name
ECS_CLUSTER: Sky # Set this to your Amazon ECS cluster name
permissions:
contents: read
jobs:
deploy:
name: Deploy to AWS ECS
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- 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_REGION }}
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push new Docker image to AWS ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
run: |
# Use Docker Buildx to build the image for x86_64
docker buildx build --platform linux/amd64 --push -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "Docker image $ECR_REPOSITORY:$IMAGE_TAG has been built and pushed to $ECR_REGISTRY"
- name: Deploy to AWS ECS
run: |
# Update the ECS service
aws ecs update-service --cluster ${{ env.ECS_CLUSTER }} --service ${{ env.ECS_SERVICE }} --force-new-deployment
# Define the website URL and the desired status code
WEBSITE_URL="https://skyscraper-api.com"
EXPECTED_STATUS_CODE=200
# Loop until the website returns the expected status code
# Wait 30 seconds before sending request
sleep 30
while true; do
# Send a HEAD request to the website and capture the HTTP status code
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" $WEBSITE_URL)
# Check if the status code matches the expected status code
if [ "$HTTP_STATUS" -eq "$EXPECTED_STATUS_CODE" ]; then
echo "Website is back up with status code $HTTP_STATUS"
break
else
echo "Website down. Current status code: $HTTP_STATUS"
fi
# Wait 20 seconds before the next check
sleep 20
done
echo "Website online"
echo "Deployment successful"