-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (74 loc) · 2.76 KB
/
deploy-feed.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
84
85
86
87
88
89
name: Feed deployment
on:
push:
branches:
- dev
- prod
permissions:
id-token: write
contents: read
env:
PRODUCT: nuklaivm
COMPONENT: backend
APPLICATION: feed
API_PORT: 10592
AWS_REGION: eu-west-1
BUILD_FOLDER: build
jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/prod' && 'prod' || github.ref == 'refs/heads/dev' && 'dev' || 'dev' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: Set dev ENV
if: github.ref == 'refs/heads/dev'
run: |
echo "ENV=dev" >> $GITHUB_ENV
echo "AWS_ACCOUNT_ID=722484512985" >> $GITHUB_ENV
- name: Set prod ENV
if: github.ref == 'refs/heads/prod'
run: |
echo "ENV=prod" >> $GITHUB_ENV
echo "AWS_ACCOUNT_ID=146563424647" >> $GITHUB_ENV
- name: Upgrade deployment files with environment information
uses: cschleiden/replace-tokens@v1
with:
tokenPrefix: '${'
tokenSuffix: '}'
files: '["infra/aws/*.json"]'
env:
AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ env.AWS_REGION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.PRODUCT }}-${{ env.COMPONENT }}-deployer-${{ env.AWS_REGION }}-${{ env.ENV }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
ECR_REPOSITORY: ${{ env.PRODUCT }}-${{ env.COMPONENT }}-${{ env.APPLICATION }}-${{ env.ENV }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -f Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: infra/aws/task-definition-${{ env.COMPONENT }}-${{ env.APPLICATION }}.json
container-name: ${{ env.APPLICATION }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.APPLICATION }}
cluster: ${{ env.PRODUCT }}-${{ env.COMPONENT }}-${{ env.ENV }}
wait-for-service-stability: true