-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (32 loc) · 1.16 KB
/
deploy.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
name: Deploy to EC2
on:
push:
branches:
- main # 또는 배포 브랜치 이름
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.EC2_KEY }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/pureplate:latest .
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/pureplate:latest
- name: Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/my-django-app:latest
docker stop my-django-app || true
docker rm my-django-app || true
docker run -d -p 8000:8000 --name my-django-app ${{ secrets.DOCKER_HUB_USERNAME }}/my-django-app:latest
EOF