kios-webapp/.github/workflows/push.yml
2023-06-07 10:42:55 +02:00

73 lines
2.4 KiB
YAML

name: Code Deployment and Environment Setup
on:
push:
branches:
- main
jobs:
build:
name: Run remote SSH commands
runs-on: ubuntu-latest
steps:
- name: Clone or pull repository
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script_stop: false
script: |
if [ -d ${{ secrets.PATH }} ]; then
cd ${{ secrets.PATH }}
git pull
else
mkdir -p ${{ secrets.PATH }}
cd ${{ secrets.PATH }}
git clone https://github.com/${{ github.repository }} .
fi
- name: Update environment variables
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script_stop: false
script: |
# Bash function to replace env variables
replace_env() {
local env_var=$1
local new_value=$2
local file=$3
sed -i "s/${env_var}=.*/${env_var}=${new_value}/" $file
}
cd ${{ secrets.PATH }}
# Replace .env with vars
replace_env 'NAME' '${{ vars.NAME }}' .env
replace_env 'ASTRO_HOST' '${{ vars.ASTRO_HOST }}' .env
replace_env 'PAYLOAD_HOST' '${{ vars.PAYLOAD_HOST }}' .env
replace_env 'PAYLOAD_SERVER_URL' '${{ vars.PAYLOAD_SERVER_URL }}' .env
replace_env 'PAYLOAD_PORT' '${{ vars.PAYLOAD_PORT }}' .env
# Replace .env with secrets
replace_env 'PAYLOAD_SECRET' '${{ secrets.PAYLOAD_SECRET }}' .env
replace_env 'MONGODB_URI' '${{ secrets.MONGODB_URI }}' .env
replace_env 'MONGODB_USER' '${{ secrets.MONGODB_USER }}' .env
replace_env 'MONGODB_PW' '${{ secrets.MONGODB_PW }}' .env
replace_env 'TOKEN' '${{ secrets.TOKEN }}' .env
mkdir -p ./astro
cp .env ./astro/.env
- name: Start Production Services
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script: |
cd ${{ secrets.PATH }}
yarn prod payload
yarn prod astro