Deploy Prefect Server from Image to EC2 #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 Docker Compose to EC2 | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
repository_dispatch: | |
types: [custom-event] | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# - name: Set up SSH key (no passphrase) | |
# uses: webfactory/ssh-agent@v0.5.3 | |
# with: | |
# ssh-private-key: ${{ secrets.INSAIT_EC2_SSH_KEY }} | |
- name: Set up SSH with passphrase | |
run: | | |
ssh-agent -a $SSH_AUTH_SOCK | |
echo 'echo ${{ secrets.INSAIT_SSH_PASSPHRASE }}' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass | |
echo "${{ secrets.INSAIT_EC2_SSH_KEY }}" | tr -d '\r' | DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add - | |
- name: Debug SSH connection | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_SSH_USER }}@${{ secrets.EC2_SSH_HOST }} hostname | |
- name: Deploy to EC2 | |
env: | |
DOCKER_HOST: "ssh://${{ secrets.EC2_SSH_USER }}@${{ secrets.EC2_SSH_HOST }}" | |
PREFECT_DOCKER_WORKPOOL: ${{ secrets.PREFECT_DOCKER_WORKPOOL }} | |
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }} | |
run: | | |
cd $GITHUB_WORKSPACE | |
docker-compose -f ./docker-compose.yml up -d | |
- name: Clean up SSH key | |
run: | | |
ssh-add -D | |
rm -rf ~/.ssh_askpass ~/.ssh/ |