Wemo.Learn

Step 11 of 11· AI Customer Support Chatbot

Deployment

Package the desk with Docker, run it on a hosting platform with Supabase, add the widget to the website, and update the index automatically with GitHub Actions.

Purpose#

Run the desk on a public HTTPS address and add the widget to the company website. The index is updated automatically when articles change.

In this step:

  • Create a production database
  • Build a Docker image that runs as a non-root user
  • Deploy to a hosting platform
  • Add the widget to the website
  • Update the index automatically with GitHub Actions

Setup#

Loading diagram…

1. Production database#

Create a second Supabase project, support-desk-prod, as in step 2. Development then never touches customer conversations.

Terminal
DATABASE_URL="<production pooler URI>" uv run python -m support_desk.db
DATABASE_URL="<production pooler URI>" uv run python -m support_desk.index

2. Docker image#

dockerfile
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:0.11.32 /uv /bin/uv

WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen
COPY support_desk ./support_desk
COPY knowledge_base ./knowledge_base

# Run as an unprivileged user instead of root.
RUN useradd --create-home app && chown app /app
USER app

# Logs appear right away in the hosting platform's log view; no .pyc files in the image.
ENV PORT=8000 PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
CMD ["sh", "-c", "exec .venv/bin/uvicorn support_desk.app:app --host 0.0.0.0 --port ${PORT}"]
.dockerignore
.env
.venv
.git
evals
__pycache__

A small Python image installs the locked dependencies, copies the code and runs the server as a non-root user on the port the platform sets, with logs written immediately.

Build and run locally (requires Docker):

Terminal
docker build -t support-desk .
docker run --rm -p 8000:8000 --env-file .env support-desk

Open http://localhost:8000.

3. Hosting#

Any platform that runs a Docker container and provides HTTPS works: Render, Railway, Fly.io, Google Cloud Run. The steps for Render:

  1. Push the project to a GitHub repository. Check that .env is not in it: git ls-files | grep .env must print only .env.example, if anything.
  2. Give Render access to the repository. Open github.com/settings/applications, go to the Installed GitHub Apps tab and click Configure next to Render. Under Repository access, select the repository and click Save. If Render is not listed, connect GitHub in Render first: New → Web Service → GitHub.
  3. In render.com, click New → Web Service and choose the repository. Check that Language is Docker. Under Advanced, set Dockerfile Path to ./dockerfile.
  4. Docker Command (called Start Command on some platforms): the command that starts the server.
Terminal
sh -c 'exec .venv/bin/uvicorn support_desk.app:app --host 0.0.0.0 --port ${PORT:-8000}'

It is the same command as CMD in the dockerfile, so the field can also stay empty where the platform allows it. --host 0.0.0.0 makes the server reachable from outside the container. ${PORT:-8000} uses the port the platform sets in PORT, or 8000.

  1. Region: the one closest to your Supabase project. Every question makes several database queries; a distant region adds latency to each.
  2. Health Check Path: /healthz.
  3. Environment: add the variables from .env with production values:
VariableProduction value
OPENAI_API_KEYA separate key for production, so it can be revoked without affecting development
DATABASE_URLThe production pooler URI
ALLOWED_ORIGINSThe website, for example https://www.brightside.example,https://brightside.example
TRUST_PROXY_HEADERStrue (Render's proxy sets X-Forwarded-For)
CLIENT_SALTA new random value, see below
MAX_MESSAGE_CHARS, CACHE_TTL_HOURSAs needed

Create the salt:

Terminal
python3 -c "import secrets; print(secrets.token_hex(32))"
  1. Click Deploy. When the log shows Uvicorn running on http://0.0.0.0:10000, open https://<your-service>.onrender.com/healthz. It returns {"ok":true}.

4. Widget on the website#

Add one line before </body> on every page of the website, or in the site's footer template:

html
<script src="https://<your-service>.onrender.com/widget.js" data-api="https://<your-service>.onrender.com" defer></script>
  • Website builders (WordPress, Webflow, Squarespace, Wix) have a setting for custom code in the footer.
  • The website's address must be listed in ALLOWED_ORIGINS exactly: scheme, www or not, no trailing slash.

5. GitHub Actions#

A workflow that updates the production index when articles change. Merging a pull request into main counts as a push to main.

The file must be at the root of the repository: .github/workflows/knowledge-base.yml. If the project is in a subfolder of the repository, add the folder to the path (support-desk/knowledge_base/**) and set working-directory: support-desk on the steps.

.github/workflows/knowledge-base.yml
# Updates the search index when articles change on main.
# Needs two repository secrets: OPENAI_API_KEY and DATABASE_URL (Settings -> Secrets and variables -> Actions).
name: knowledge-base

on:
  push:
    branches: [main]
    paths: ["knowledge_base/**"]
  workflow_dispatch:     # a "Run workflow" button in the Actions tab

# Never run two index updates at the same time.
concurrency: knowledge-base

jobs:
  index:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
      - run: uv sync --frozen
      - run: uv run python -m support_desk.index
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          DATABASE_URL: ${{ secrets.DATABASE_URL }}

A push to main that changes knowledge_base/ re-indexes production; two runs never overlap. Run workflow in the Actions tab starts it by hand.

Secrets: the workflow reads OPENAI_API_KEY and DATABASE_URL from repository secrets. Add both before the first run:

  1. In the GitHub repository, open Settings → Secrets and variables → Actions.
  2. On the Secrets tab, under Repository secrets, click New repository secret.
  3. Name: DATABASE_URL. Secret: the production pooler URI. Click Add secret.
  4. Repeat for OPENAI_API_KEY.

Use the Secrets tab, not Variables, and not environment secrets under Settings → Environments: the workflow does not see those.

Checkpoint#

  1. https://<your-service>.onrender.com/healthz returns {"ok":true}.
  2. On the website, the chat button appears. Ask "What is your phone number?". The answer contains 555-0142.
  3. In the browser's developer tools, Console shows no CORS errors.
  4. Ask a question that needs a person and leave an email address. The ticket appears in DATABASE_URL="<production URI>" uv run python -m support_desk.handoff.
  5. On GitHub, open Actions → knowledge-base → Run workflow. The run is green and its log ends with a line such as Index updated: 0 added, 0 removed, 21 unchanged.
  6. Change a sentence in an article, push to main, wait for the index job, and ask about the change.

Troubleshooting#

  • The repository is not in Render's list: Render has no access to it. Add it under Configure → Repository access for Render at github.com/settings/applications.
  • The build fails with failed to read dockerfile or open Dockerfile: no such file: Dockerfile Path is still ./Dockerfile. Set it to ./dockerfile under Settings → Build & Deploy.
  • The deploy fails with Missing settings: …: the named environment variables are not set on the hosting platform. Add them and redeploy.
  • The log shows CLIENT_SALT is the default value: set CLIENT_SALT to a random value (see above) before customers use the chat.
  • The service starts but is not reachable: the start command is missing --host 0.0.0.0 or uses a fixed port instead of PORT.
  • Deploy fails with uv.lock errors: commit uv.lock. --frozen requires it.
  • /healthz returns 500: check DATABASE_URL in the hosting settings. The log shows the database error.
  • The widget loads but every request fails with a CORS error: the website's exact origin is missing from ALLOWED_ORIGINS. Redeploy after changing it.
  • The workflow fails with DATABASE_URL is not set: the repository secret is missing, misspelled, or was added as a variable or environment secret. Add it as described in section 5 and run the workflow again.
  • The workflow fails with missing front matter: an article does not start with ---, title: and url: (step 3). Common causes: a blank line or invisible character before the first ---, or Windows line endings (switch CRLF to LF in the editor's status bar). Check locally with uv run python -m support_desk.kb before pushing. The database is not changed when the workflow fails.
  • The workflow does not start after a push: the push did not change files under knowledge_base/, went to a branch other than main, or the workflow file is not at the root of the repository.
  • The first request after a pause takes 30 seconds or more: free hosting plans stop idle services. Use a paid instance for a customer-facing website.

AI Automations Guild

Join the community

Ask questions, get help with this tutorial and share what you build. Free on Skool.