-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (67 loc) · 2.23 KB
/
Copy pathworkflow.yml
File metadata and controls
81 lines (67 loc) · 2.23 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
name: workflow.yml
on:
push:
branches: [ main ]
jobs:
build:
name: Build Image
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
run: |
docker build --no-cache -t dearbelly-cv .
docker tag dearbelly-cv:latest ${{ secrets.ECR_URI }}/dearbelly-cv
docker push ${{ secrets.ECR_URI }}/dearbelly-cv:latest
transfer:
runs-on: ubuntu-24.04
needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Transfer deploy file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ./deployment/
target: /home/ubuntu/dearbelly
deploy:
name: Deploy
runs-on: ubuntu-24.04
needs: transfer
steps:
- name: SSH into EC2 server and Deploy
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
# 1. cd
mkdir -p ~/dearbelly/deployment
cd ~/dearbelly/deployment
# 2. .env file
echo "${{ secrets.ENV }}" > .env
sudo chmod 600 .env
# 3. aws login
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_URI }}
# 4. export env
export ECR_URI=${{ secrets.ECR_URI }}
# 5. pull Image
docker pull ${{ secrets.ECR_URI }}/dearbelly-cv:latest
# 6. docker start
sudo chmod +x deploy.sh
source deploy.sh