-
Notifications
You must be signed in to change notification settings - Fork 6
88 lines (71 loc) · 2.42 KB
/
main.yml
File metadata and controls
88 lines (71 loc) · 2.42 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
name: Main Workflow
on:
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.0
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
unzip \
jq
- name: Install .NET SDK
run: |
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
- name: Install PostgreSQL
run: |
sudo apt-get install -y postgresql
- name: Install Node.js and Yarn
uses: actions/setup-node@v3
with:
node-version: '14'
- run: |
sudo apt-get install -y nodejs
npm install -g yarn
- name: Install Docker
uses: docker/setup-docker@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: 'us-east-1'
- name: Run Terraform apply
run: |
terraform init
terraform apply -auto-approve
- name: Build and push Docker images
run: |
docker-compose build
docker tag your_image:latest ${{ secrets.AWS_ECR_REPO_URL }}/your_image:latest
docker push ${{ secrets.AWS_ECR_REPO_URL }}/your_image:latest
- name: Update ECS service
run: |
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
AWS_REGION="us-east-1"
ECR_REPO_NAME="your_image"
ECS_CLUSTER_NAME="your_ecs_cluster"
ECS_SERVICE_NAME="your_ecs_service"
IMAGE_TAG="latest"
ECR_IMAGE_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO_NAME}:${IMAGE_TAG}"
# Update ECS service with the new image
aws ecs update-service --cluster $ECS_CLUSTER_NAME --service $ECS_SERVICE_NAME --force-new-deployment --task-definition "${ECR_REPO_NAME}:${IMAGE_TAG}"
- name: Run Terraform destroy
run: |
terraform destroy -auto-approve
- name: Print resources destroyed
run: |
echo "Resources destroyed successfully"