Deploy to server #16
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 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: | | |
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 |