Skip to content

Release: fix deploy.yml #46

Release: fix deploy.yml

Release: fix deploy.yml #46

Workflow file for this run

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