Deploy to EC2 #5
This file contains hidden or 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: | |
| workflow_run: | |
| workflows: ["Build and Push to Docker Hub"] | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: Pinhouse_env | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Deploy to EC2 via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| set -e | |
| docker pull ${{ secrets.DOCKER_USERNAME }}/pinhouse:latest | |
| docker rm -f pinhouse || true | |
| docker run -d \ | |
| --name pinhouse \ | |
| --restart unless-stopped \ | |
| -p 3000:3000 \ | |
| ${{ secrets.DOCKER_USERNAME }}/pinhouse:latest | |