diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 29ab64f..ab9f5ac 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -121,11 +121,14 @@ jobs: - name: Check remote build credentials id: check-build-host + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" if [ -z "${{ secrets.VPS_SSH_KEY }}" ] || \ - [ -z "${{ secrets.VPS_IP }}" ] || \ + [ -z "$VPS_HOST" ] || \ [ -z "${{ secrets.VPS_USER }}" ]; then - echo "::error::VPS_SSH_KEY, VPS_IP, and VPS_USER are required to build on the remote Docker host" + echo "::error::VPS_SSH_KEY, VPS_USER, and either VPS_IP or DEPLOY_REGISTRY_HOST are required to build on the remote Docker host" exit 1 fi @@ -137,18 +140,23 @@ jobs: fi - name: Set up SSH key + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" mkdir -p ~/.ssh && chmod 700 ~/.ssh echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H "${{ secrets.VPS_IP }}" >> ~/.ssh/known_hosts 2>/dev/null + ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null chmod 644 ~/.ssh/known_hosts - name: Sync build context to VPS env: REMOTE_BUILD_DIR: ${{ env.DEPLOY_ROOT }}/build-context + VPS_HOST: ${{ secrets.VPS_IP }} run: | - ssh "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}" \ + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" + ssh "${{ secrets.VPS_USER }}@$VPS_HOST" \ "rm -rf '$REMOTE_BUILD_DIR' && mkdir -p '$REMOTE_BUILD_DIR'" tar \ --exclude='.git' \ @@ -156,7 +164,7 @@ jobs: --exclude='.next' \ --exclude='dist' \ --exclude='coverage' \ - -czf - . | ssh "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}" \ + -czf - . | ssh "${{ secrets.VPS_USER }}@$VPS_HOST" \ "tar -xzf - -C '$REMOTE_BUILD_DIR'" - name: Build and push on VPS @@ -173,9 +181,11 @@ jobs: NEXT_PUBLIC_ADMIN_URL: ${{ secrets.NEXT_PUBLIC_ADMIN_URL }} SITE_ORIGIN: ${{ secrets.SITE_ORIGIN }} REMOTE_BUILD_DIR: ${{ env.DEPLOY_ROOT }}/build-context + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" REGISTRY_PASSWORD_B64="$(printf '%s' "$REGISTRY_PASSWORD" | base64 | tr -d '\n')" - ssh "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}" " + ssh "${{ secrets.VPS_USER }}@$VPS_HOST" " set -e cd '$REMOTE_BUILD_DIR' if ! command -v docker >/dev/null 2>&1; then @@ -258,9 +268,12 @@ jobs: - name: Check deploy credentials id: check-creds + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" if [ -z "${{ secrets.VPS_SSH_KEY }}" ] || \ - [ -z "${{ secrets.VPS_IP }}" ] || \ + [ -z "$VPS_HOST" ] || \ [ -z "${{ secrets.VPS_USER }}" ]; then echo "VPS secrets not fully configured — skipping deploy" echo "skip=true" >> "$GITHUB_OUTPUT" @@ -278,37 +291,46 @@ jobs: - name: Set up SSH key if: steps.check-creds.outputs.skip == 'false' + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" mkdir -p ~/.ssh && chmod 700 ~/.ssh echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H "${{ secrets.VPS_IP }}" >> ~/.ssh/known_hosts 2>/dev/null + ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null chmod 644 ~/.ssh/known_hosts - name: Sync deployment assets if: steps.check-creds.outputs.skip == 'false' + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | - ssh "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}" \ + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" + ssh "${{ secrets.VPS_USER }}@$VPS_HOST" \ "mkdir -p '$DEPLOY_ROOT/scripts' '$DEPLOY_ROOT/docker/pgmanage' '$DEPLOY_ROOT/docker/registry/auth' '$DEPLOY_ROOT/dynamic'" scp docker-compose.production.yml \ docker-compose.portainer.production.yml \ docker-compose.registry.production.yml \ docker-compose.registry.local.yml \ traefik.yaml \ - "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}:$DEPLOY_ROOT/" + "${{ secrets.VPS_USER }}@$VPS_HOST:$DEPLOY_ROOT/" scp scripts/docker-prod-common.sh \ scripts/docker-prod-deploy.sh \ scripts/docker-prod-up-registry.sh \ scripts/docker-registry-local-up.sh \ - "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}:$DEPLOY_ROOT/scripts/" + "${{ secrets.VPS_USER }}@$VPS_HOST:$DEPLOY_ROOT/scripts/" scp docker/pgmanage/override.py \ - "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}:$DEPLOY_ROOT/docker/pgmanage/" + "${{ secrets.VPS_USER }}@$VPS_HOST:$DEPLOY_ROOT/docker/pgmanage/" - name: Run deploy script on VPS if: steps.check-creds.outputs.skip == 'false' + env: + VPS_HOST: ${{ secrets.VPS_IP }} run: | + VPS_HOST="${VPS_HOST:-$DEPLOY_REGISTRY_HOST}" REGISTRY_PASSWORD_B64="$(printf '%s' "${{ secrets.REGISTRY_PASSWORD }}" | base64 | tr -d '\n')" - ssh "${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }}" " + ssh "${{ secrets.VPS_USER }}@$VPS_HOST" " set -e cd '$DEPLOY_ROOT' APP_IMAGE='$DEPLOY_REGISTRY_HOST/$IMAGE_REPOSITORY' \