Setup Remote Server #3
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: Setup Remote Server | |
# Trigger workflow manually | |
on: | |
workflow_dispatch: | |
jobs: | |
replace_and_copy: | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Start ssh-agent and add the SSH key with passphrase | |
- name: Set up SSH | |
uses: webfactory/ssh-agent@v0.7.0 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add Known Hosts | |
run: ssh-keyscan -H ${{ secrets.REMOTE_IP }} >> ~/.ssh/known_hosts | |
# Replace environment variables in docker-compose.yml and nginx.conf | |
- name: Replace environment variables in docker-compose.yml | |
run: | | |
sed -i 's|${DB_URI}|'"${{ secrets.DB_URI }}"'|g' ./scripts/docker-compose.yml | |
sed -i 's|${DB_NAME}|'"${{ secrets.DB_NAME }}"'|g' ./scripts/docker-compose.yml | |
shell: bash | |
- name: Replace environment variables in nginx.conf | |
run: | | |
sed -i 's|${UPSTREAM_SERVER}|'"${{ secrets.UPSTREAM_SERVER }}"'|g' ./scripts/nginx.conf | |
sed -i 's|${PROXY_PASS}|'"${{ secrets.PROXY_PASS }}"'|g' ./scripts/nginx.conf | |
shell: bash | |
# Copy files to remote server using scp | |
- name: Copy files to remote server | |
run: | | |
scp -o StrictHostKeyChecking=no ./scripts/docker-compose.yml ./scripts/nginx.conf ${{ secrets.REMOTE_SERVER }}:/home/app | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |