-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (62 loc) · 1.93 KB
/
Copy pathci.yml
File metadata and controls
74 lines (62 loc) · 1.93 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
name: FastAPI Push CI/CD (v 1.5)
env:
IMAGE_TAG: 1.0.0
on:
push:
branches:
- main
pull_request:
types:
- closed
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker Hub Login
uses: docker/login-action@v3
with:
username: wonseoop
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: FastAPI Image Build and Push
run: |
docker buildx build \
--platform linux/amd64 \
-t wonseoop/hackton-fastapi:1.0.0 \
--push .
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Install AWS CLI
uses: unfor19/install-aws-cli-action@v1
with:
version: 2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Get BE Public IPs by Name tag
run: |
BE_IPS=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=FastAPI" "Name=instance-state-name,Values=running" \
--query "Reservations[].Instances[].PublicIpAddress" \
--output text)
echo "BE_IPS=$BE_IPS" >> $GITHUB_ENV
- name: Deploy to all BE instances
run: |
for IP in $BE_IPS; do
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ubuntu@$IP \
"cd /home/ubuntu/AWS_DOCKER/FastAPI && docker compose down && docker compose pull && docker compose up -d"
done