test 1 #55
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 | |
# uses: webfactory/ssh-agent@v0.5.3 | |
# with: | |
# ssh-private-key: ${{ secrets.INSAIT_EC2_SSH_KEY }} | |
- name: Set up SSH passphrase | |
env: | |
SSH_HOST: ${{ secrets.EC2_SSH_HOST }} | |
SSH_USER: ${{ secrets.EC2_SSH_USER }} | |
SSH_KEY: ${{ secrets.INSAIT_EC2_SSH_KEY }} | |
SSH_PASSPHRASE: ${{ secrets.INSAIT_SSH_PASSPHRASE }} | |
run: | | |
ssh-agent -a $SSH_AUTH_SOCK | |
echo 'echo $SSH_PASSPHRASE' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass | |
echo "$SSH_KEY" | tr -d '\r' | DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add - | |
# mkdir -p ~/.ssh/ | |
# echo "$SSH_KEY" > ~/.ssh/id_rsa_staging | |
# chmod 600 ~/.ssh/id_rsa_staging | |
# echo "$SSH_PASSPHRASE" > ~/.ssh/passphrase.txt | |
# chmod 400 ~/.ssh/passphrase.txt | |
# cat >>~/.ssh/config <<EOF | |
# Host staging | |
# HostName $SSH_HOST | |
# User $SSH_USER | |
# IdentityFile ~/.ssh/id_rsa_staging | |
# StrictHostKeyChecking accept-new | |
# EOF | |
# echo Running test script | |
# ssh-keygen -p -P "$(cat ~/.ssh/passphrase.txt)" -N "" -f ~/.ssh/id_rsa_staging | |
# ssh-agent -a $SSH_AUTH_SOCK | |
# echo 'echo $SSH_PASSPHRASE' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass | |
# echo "$SSH_PRIVATE_KEY" | tr -d '\r' | DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add - | |
# - name: Set up Docker Compose | |
# uses: KengoTODA/actions-setup-docker-compose@main | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- 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 }} | |
run: | | |
cd $GITHUB_WORKSPACE | |
docker-compose -f ./docker-compose.yml up -d | |
# docker-compose -f path/to/docker-compose.yml pull | |
# export DOCKER_HOST="ssh://${{ secrets.EC2_SSH_HOST }}" | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# run: | | |
# ssh -o StrictHostKeyChecking=no ubuntu@ec2-16-16-171-100.eu-north-1.compute.amazonaws.com << 'EOF' | |
# export GITHUB_TOKEN=${GITHUB_TOKEN} | |
# if [ ! -d "/home/ubuntu/prefect-server" ]; then | |
# git clone https://github.com/OlegPodlipalin/prefect-server.git /home/ubuntu/prefect-server | |
# else | |
# cd /home/ubuntu/prefect-server | |
# git pull | |
# fi | |
# cd /home/ubuntu/prefect-server | |
# docker-compose up -d | |
# EOF | |
- name: Clean up SSH key | |
run: | | |
ssh-add -D | |
rm -rf ~/.ssh/ |