-
Notifications
You must be signed in to change notification settings - Fork 12
73 lines (64 loc) · 2.19 KB
/
production.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
name: Production
on:
push:
branches: [main, ci-aws]
env:
AWS_REGION: ap-southeast-2
jobs:
lint-format:
name: Linting Checks
uses: ./.github/workflows/lint.yml
build:
needs: lint-format
name: Build
runs-on: [self-hosted, ARM64] # Since deployment is on arm64
environment: Production
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
# - name: Install arm64 support for Docker
# run: docker run --privileged --rm tonistiigi/binfmt --install arm64
- name: Build Docker container
env:
GUILD_ID: ${{ secrets.GUILD_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
docker buildx build \
--secret id=GUILD_ID \
--secret id=BOT_TOKEN \
--platform=linux/arm64 --file=Dockerfile -t duckbot .
docker image save duckbot | gzip > duckbot.tar.gz
- name: Copy image and compose file to S3
run: |
aws s3 cp ./duckbot.tar.gz s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/
aws s3 cp ./docker-compose.yml s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/
deploy:
needs: build
name: Deploy
runs-on: ubuntu-latest
environment: Production
steps:
- name: Deploy on EC2
env:
KEY: ${{ secrets.SSH_EC2_KEY }}
HOSTNAME: ${{ secrets.SSH_EC2_HOSTNAME }}
USER: ${{ secrets.SSH_EC2_USER }}
run: |
echo "$KEY" > private_key && chmod 600 private_key
ssh -v -o StrictHostKeyChecking=no -i private_key ${USER}@${HOSTNAME} '
cd ~/duckbot
aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/duckbot.tar.gz .
aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/docker-compose.yml .
docker load -i duckbot.tar.gz
docker compose up -d
docker restart duckbot
'