Skip to content

fix

fix #13

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push the image
run: |
sudo docker build -t my-python-app .
sudo docker tag my-python-app ${{ secrets.DOCKER_USERNAME }}/my-python-app
sudo docker push ${{ secrets.DOCKER_USERNAME }}/my-python-app
- name: SSH Remote Commands
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: 22
script: |
# Your deployment commands here
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/my-python-app
sudo docker stop my-python-app || true
sudo docker rm my-python-app || true
sudo docker run -d -p 8000:8000 ${{ secrets.DOCKER_USERNAME }}/my-python-app