-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (84 loc) · 3.54 KB
/
deploy.yml
File metadata and controls
99 lines (84 loc) · 3.54 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: CI/CD Pipeline for Notejam Flask Application
on:
push:
branches:
- main # Trigger on push to the main branch
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v2
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Print AWS Environment Variables
run: |
echo "AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}"
echo "AWS_REGION: ${{ secrets.AWS_REGION }}"
# Set up AWS credentials
- 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-region: eu-central-1
# Log in to Amazon ECR
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
region: eu-central-1
# Create ECR repository if it doesn't exist
- name: Create ECR Repository
run: |
aws ecr describe-repositories --repository-names ${{ secrets.ECR_REPOSITORY }} || \
aws ecr create-repository --repository-name ${{ secrets.ECR_REPOSITORY }}
# Build the Docker image
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_IMAGE_NAME }} .
docker tag ${{ secrets.DOCKER_IMAGE_NAME }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:latest
# Push the Docker image to Amazon ECR
- name: Push Docker image to ECR
run: |
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Configure AWS credentials
- 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-region: ${{ secrets.AWS_REGION }}
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition dev-task --query taskDefinition > task-definition.json
# Deploy the registered task definition to ECS
- name: Deploy to Amazon ECS
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
cluster: ${{ secrets.ECS_CLUSTER }} # Name of the ECS cluster
service: ${{ secrets.ECS_SERVICE }} # Name of the ECS service
task-definition: task-definition.json
container-name: "dev-container" # Container name in the ECS task definition
image: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:latest
- name: Debug Task Definition ARN
run: |
echo "Task Definition ARN: ${{ env.TASK_DEFINITION_ARN }}"
# Verify the ECS service deployment
- name: Verify ECS service health
run: |
aws ecs describe-services --cluster ${{ secrets.ECS_CLUSTER }} --services ${{ secrets.ECS_SERVICE }} --query 'services[0].deployments'