Merge pull request #50 from Pure-Plate/release #62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to EC2 | |
on: | |
push: | |
branches: | |
- main # 또는 배포 브랜치 이름 | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- 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 }}/pureplate:latest | |
docker stop pureplate || true | |
docker rm pureplate || true | |
docker run -d -p 8000:8000 --name pureplate ${{ secrets.DOCKER_HUB_USERNAME }}/pureplate:latest | |
EOF | |