Skip to content

Build & Deploy

Build & Deploy #16

Workflow file for this run

name: Build & Deploy
on:
workflow_run:
workflows: ["CI"]
branches: [main]
types: [completed]
jobs:
build-push:
if: >-
github.repository == 'readium/speech-server' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.event.workflow_run.head_sha }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:latest
cache-to: type=inline
deploy:
needs: build-push
runs-on: ubuntu-latest
steps:
- name: Deploy to GCP VM
uses: appleboy/ssh-action@v1
env:
# base64-encoded contents of .env / pocket-tts.env / elevenlabs.env, stored as
# GitHub secrets (see docs/deployment.md). base64 avoids newline/quoting issues
# over SSH. This is the single source of truth for prod config — never edit the
# files on the VM by hand. ELEVENLABS_ENV_B64 is optional (only when ElevenLabs
# is enabled); an empty secret leaves elevenlabs.env absent, which is fine.
DOTENV_B64: ${{ secrets.DOTENV_B64 }}
POCKET_ENV_B64: ${{ secrets.POCKET_TTS_ENV_B64 }}
ELEVENLABS_ENV_B64: ${{ secrets.ELEVENLABS_ENV_B64 }}
with:
host: ${{ secrets.GCP_VM_HOST }}
username: ${{ secrets.GCP_VM_USER }}
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
envs: DOTENV_B64,POCKET_ENV_B64,ELEVENLABS_ENV_B64
script: |
set -euo pipefail
cd ~/speech-server
git pull --ff-only
# Render env files from the secrets (overwrites whatever's on the VM).
printf '%s' "$DOTENV_B64" | base64 -d > .env
printf '%s' "$POCKET_ENV_B64" | base64 -d > pocket-tts.env
chmod 600 .env pocket-tts.env
# elevenlabs.env only when the secret is set (provider optional).
if [ -n "$ELEVENLABS_ENV_B64" ]; then
printf '%s' "$ELEVENLABS_ENV_B64" | base64 -d > elevenlabs.env
chmod 600 elevenlabs.env
fi
docker compose pull app
docker compose up -d --no-build app
docker compose restart nginx
docker image prune -f