use different variable name for secrets #12
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: Build and Deploy staging/preproduction | |
env: | |
NODE_VERSION: '18' | |
GCP_PROJECT_ID: 'rbl-common' | |
SERVER_USER: 'w3reg' | |
SERVER_IP: '135.181.202.179' | |
DEPLOY_PATH: '/home/w3reg/app.w3reg.org' | |
BUILD_TARGET: 'production' | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build the Vite app | |
env: | |
BUILD_TARGET: 'production' | |
run: | | |
curl -fsSL https://bun.sh/install | bash -s "canary" | |
export BUN_INSTALL="$HOME/.bun" | |
export PATH=$BUN_INSTALL/bin:$PATH | |
cat .env.example | grep -v "#" > .env | |
cat .env | wc -l | |
bash scripts/build.sh | |
- name: Set up SSH agent | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} | |
- name: Add SSH Key to Known Hosts | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan -t ed25519 ${{ env.SERVER_IP }} >> ~/.ssh/known_hosts | |
chmod 644 ~/.ssh/known_hosts | |
- name: Enable Debug Logging | |
run: echo "DEBUG=true" >> $GITHUB_ENV | |
- name: Print Known Hosts | |
run: cat ~/.ssh/known_hosts || echo "No known hosts file found" | |
- name: List SSH Keys | |
run: ssh-add -l || echo "No keys loaded into ssh-agent" | |
- name: Debug SSH Connection | |
run: ssh -vvv ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} || echo "SSH failed" | |
- name: Deploy to server | |
run: | | |
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << EOF | |
set -euo pipefail | |
rm -fr ${{ env.DEPLOY_PATH }}/w3registrar-www/nginx || true | |
mkdir -p ${{ env.DEPLOY_PATH }}/w3registrar-www | |
EOF | |
scp -r ./nginx ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/w3registrar-www | |
scp -r ./dist ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/w3registrar-www/nginx | |
scp docker-compose.yaml ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/w3registrar-www | |
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << EOF | |
set -euo pipefail | |
cd ${{ env.DEPLOY_PATH }}/w3registrar-www | |
docker compose up --build -d web-nginx | |
EOF |