Skip to content

Commit bcfb764

Browse files
authored
Update deploy.yml
1 parent 6d0d385 commit bcfb764

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.github/workflows/deploy.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
name: Deploy to EC2
1+
name: Build & Deploy Spike (Flask-only → GHCR → EC2)
22

33
on:
44
push:
5-
branches:
6-
- main # main 브랜치 push 시 자동 배포
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: read
9+
packages: write
710

811
jobs:
9-
deploy:
10-
name: Deploy to EC2 Server
12+
build-push-deploy:
1113
runs-on: ubuntu-latest
12-
1314
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
15+
- uses: actions/checkout@v4
16+
- uses: docker/setup-buildx-action@v3
17+
- uses: docker/login-action@v3
18+
with:
19+
registry: ghcr.io
20+
username: ${{ github.actor }}
21+
password: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- uses: docker/build-push-action@v6
24+
with:
25+
context: .
26+
file: server/Dockerfile
27+
push: true
28+
tags: |
29+
ghcr.io/dmu-debugvisual/debugvisual-spike:latest
30+
ghcr.io/dmu-debugvisual/debugvisual-spike:${{ github.sha }}
1631
17-
- name: Set up SSH key
32+
- name: Deploy on EC2 (compose pull/up)
33+
env:
34+
HOST: ${{ secrets.EC2_HOST }}
35+
USER: ${{ secrets.EC2_USER }}
1836
run: |
1937
mkdir -p ~/.ssh
2038
echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa
39+
sed -i 's/\r$//' ~/.ssh/id_rsa
2140
chmod 600 ~/.ssh/id_rsa
22-
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
23-
24-
- name: SSH and deploy
25-
run: |
26-
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "cd ~ && ./deploy.sh"
41+
ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts
42+
ssh "$USER@$HOST" "\
43+
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} && \
44+
cd ~/apps/debugvisual && \
45+
docker compose pull && docker compose up -d && \
46+
docker image prune -af || true"

0 commit comments

Comments
 (0)