Testing Production Build Locally #
This guide explains how to test the webapp production build locally with proper configuration for Clerk authentication.
⚠️ Warning: The changes described in this document are for testing purposes only and should never be committed to the repository as they contain sensitive credentials.
Overview #
Testing the production build locally requires one main change:
- Adding Clerk credentials to the webapp Dockerfile
bonsapi applies permissive CORS (Cors::permissive()) at the app level, so the production webapp can talk to it directly — no proxy or CORS configuration needed.
Prerequisites #
- Docker and Docker Compose running locally
- Access to Clerk test credentials
- Local development environment set up
web-app in dev environment would be allocated port 3000, so the production version should run on port 3001.
Step 1: Configure Clerk Credentials in Dockerfile #
Edit the apps/webapp/Dockerfile and add the following environment variables before the CMD instruction (around line 55):
ENV CLERK_JWT_PUBLIC_KEY="<CLERK_JWT_PUBLIC_KEY>"
ENV CLERK_SECRET_KEY="<CLERK_SECRET_KEY>"
ENV CLERK_WEBHOOK_SIGNING_SECRET="<CLERK_WEBHOOK_SIGNING_SECRET>"
Step 2: Build and Run Production Webapp #
Build and run the webapp production container:
# Build the production image
docker buildx build -t webapp-prod -f apps/webapp/Dockerfile --build-arg DOPPLER_TOKEN="<doppler_token>" --build-arg DOPPLER_CONFIG=dev_local .
# Run the production container
docker run --name=webapp-prod --network=host webapp-prod:latest
# Run the production container on Mac (network=host does not work)
docker run --name=webapp-prod -p 3001:3001 -d webapp-prod:latest
Step 3: Verify the Setup #
- Check webapp is running: Navigate to
http://localhost:3000(as example of the port on 3000) - Verify Clerk authentication: Try to sign in
- Test API connectivity: Ensure the webapp can communicate directly with bonsapi
Troubleshooting #
Common Issues #
Clerk Authentication Errors
- Verify all three Clerk environment variables are correctly set
- Ensure the JWT public key is properly formatted with
\nfor line breaks
Container Connection Issues #
- Verify all containers are on the same Docker network
- Check Docker container logs for specific error messages
Logs #
Check container logs for debugging:
# Webapp logs
docker logs <webapp-container-name>
# API logs
docker logs <bonsapi-container-name>
Cleanup #
After testing, remember to:
- Revert Dockerfile changes: Remove the Clerk environment variables
- Don’t commit these changes: These are for local testing only