Skip to content

Deploy to server

Deploy to server #18

Workflow file for this run

---
name: Deploy to server
on: workflow_dispatch
jobs:
deploy_to_server:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/private_key.pem
chmod 600 ~/.ssh/private_key.pem
ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Checkout code
uses: actions/checkout@v2
- name: Copy docker compose files
run: |
ssh -i ~/.ssh/private_key.pem ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} <<EOF
rm -r ./docker
EOF
scp -i ~/.ssh/private_key.pem -r ./docker/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:/home/${{ secrets.SERVER_USER }}/docker
- name: Prepare and Deploy
run: |
ssh -i ~/.ssh/private_key.pem ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} <<"ENDSSH"
export APP_ENV=${{ vars.APP_ENV }}
export HOST_PORT=${{ vars.HOST_PORT }}
export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
echo "APP_ENV: $APP_ENV : ${{ vars.APP_ENV }}"
echo "HOST_PORT: $HOST_PORT : ${{ vars.HOST_PORT }}"
echo "POSTGRES_PASSWORD: $POSTGRES_PASSWORD : ${{ secrets.POSTGRES_PASSWORD }}"
docker-compose -f docker/base.yml -f docker/prod.yml pull
docker-compose -f docker/base.yml -f docker/prod.yml down
docker-compose -f docker/base.yml -f docker/prod.yml up
ENDSSH