-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (89 loc) · 3.54 KB
/
deploy-fluentbit.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Deploy to AWS
on:
push:
branches:
- main
paths:
- 'fluentbit/**'
- '.github/workflows/**'
env:
ENDPOINT: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com
DEV_REPO: ${{ secrets.DEV_FLUENTBIT_ECR_REPOSITORY }}
PROD_REPO: ${{ secrets.PROD_FLUENTBIT_ECR_REPOSITORY }}
TASK_DEFINITION: ${{ secrets.TASK_DEFINITION_NAME }}-prod
ECS_CONTAINER: ${{ secrets.ECS_FLUENTBIT_CONTAINER_NAME }}-prod
ECS_SERVICE: ${{ secrets.ECS_SERVICE_NAME }}-prod
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER_NAME }}-prod
TAG: latest
jobs:
deploy-dev:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Build and push image to Amazon ECR
run: |
docker build -t ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }} .
docker push ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
working-directory: ./fluentbit
- name: Pull image from Amazon ECR and restart container in EC2
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.DEV_SERVER_SSH_KEY }}
host: ${{ secrets.DEV_SERVER_HOST }}
username: ${{ secrets.DEV_SERVER_USER }}
script: |
docker login -u AWS -p $(aws ecr get-login-password --region ap-northeast-2) ${{ env.ENDPOINT }}
docker pull ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
docker stop fluentbit-dev && docker rm fluentbit-dev
docker run -d --name fluentbit-dev -p 8888:8888 --network dev-network -e env=dev ${{ env.ENDPOINT }}/${{ env.DEV_REPO }}:${{ env.TAG }}
deploy-prod:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Build and push image to Amazon ECR
run: |
docker build -t ${{ env.ENDPOINT }}/${{ env.PROD_REPO }}:${{ env.TAG }} .
docker push ${{ env.ENDPOINT }}/${{ env.PROD_REPO }}:${{ env.TAG }}
working-directory: ./fluentbit
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.TASK_DEFINITION }} --query taskDefinition > task-definition.json
- 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: task-definition.json
container-name: ${{ env.ECS_CONTAINER }}
image: ${{ env.ENDPOINT }}/${{ env.PROD_REPO }}:${{ env.TAG }}
- name: Deploy Amazon ECS task definition
id: deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true