Skip to content

Instantly share code, notes, and snippets.

@infomiho
Last active November 11, 2023 23:06
Show Gist options
  • Save infomiho/6505d5970f5c334f704d658e9aa0bf56 to your computer and use it in GitHub Desktop.
Save infomiho/6505d5970f5c334f704d658e9aa0bf56 to your computer and use it in GitHub Desktop.
Deploying Wasp apps to Caprover

Caprover

You'll need a Caprover server setup.

Then create three apps for your Wasp app:

  1. server
  2. client
  3. Postgres DB
    • go to one click apps/dbs and create a vanilla PostgreSQL

Set the container ports:

  • server app -> 3001
  • client app -> 8043

Enable HTTPS and force redirects to HTTPS.

Adjust the captain-definition location in the Deployment tab:

  • server app -> captain-definition-server
  • client app -> captain-definition-client

Env variables

The env variables you will need to set:

  • server app
    • DATABASE_URL (the DB you created on Caprover)
      • postgres://postgres:<pw>@srv-captain--<db-app-name>:5432/postgres
    • WASP_WEB_CLIENT_URL the client url (custom domain or the Caprover assigned subdomain)
    • JWT_SECRET
  • client app
    • SERVER_APP_URL the server url

Captain files

Adding the following files to your Wasp app project:

  • captain-definition-client
  • captain-definition-server
  • caprover/Dockerfile.client
  • caprover/Dockerfile.server
  • .dockerignore

Github webhook

You'll need a new private-public SSH key pair to add to the client and server apps (private key) and to the Github repo as the deploy key (public key) ... or just add the public key to your account.

You should add the Github webhook URls as push only to your Github repo (one for each client and server)

Cloudflare Notes

Set the SSL/TLS to Full (strict).

Change the A recrod to DNS only when you try to verify the domain (Clicking Enable HTTPS tries to verify the domain and it fails if the A record is proxied).

When you get a certificate for the domain, switch the A recrod back to proxied.

{
"schemaVersion": 2,
"dockerfilePath": "./caprover/Dockerfile.client"
}
{
"schemaVersion": 2,
"dockerfilePath": "./caprover/Dockerfile.server"
}
# Building the Wasp app
FROM --platform=linux/amd64 node:18 AS wasp-build
ARG SERVER_APP_URL
ENV SERVER_APP_URL=$SERVER_APP_URL
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.11.7
ENV PATH="/root/.local/bin:${PATH}"
WORKDIR /app
COPY . /app
RUN wasp build
# Building the client
WORKDIR /app/.wasp/build/web-app
RUN REACT_APP_API_URL=$SERVER_APP_URL npm run build
# Serving the client
FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html", "-enable-logging"]
COPY --from=wasp-build /app/.wasp/build/web-app/build /srv/http
# Building the Wasp app
FROM --platform=linux/amd64 node:18 AS wasp-build
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.11.7
ENV PATH="/root/.local/bin:${PATH}"
WORKDIR /app
COPY . /app
RUN wasp build
# Building the server
FROM node:18-alpine3.17 AS node
FROM node AS base
RUN apk --no-cache -U upgrade # To ensure any potential security patches are applied.
FROM base AS server-builder
RUN apk add --no-cache build-base libtool autoconf automake
WORKDIR /app
COPY --from=wasp-build /app/.wasp/build/server/ ./server/
# Install npm packages, resulting in node_modules/.
RUN cd server && npm install
COPY --from=wasp-build /app/.wasp/build/db/schema.prisma ./db/
RUN cd server && PRISMA_CLIENT_OUTPUT_DIR=../server/node_modules/.prisma/client/ npx prisma generate --schema='../db/schema.prisma'
# Building the server should come after Prisma generation.
RUN cd server && npm run build
# Serving the server
FROM base AS server-production
RUN apk add --no-cache python3
ENV NODE_ENV production
WORKDIR /app
COPY --from=server-builder /app/server/node_modules ./server/node_modules
COPY --from=server-builder /app/server/dist ./server/dist
COPY --from=server-builder /app/server/package*.json ./server/
COPY --from=server-builder /app/server/scripts ./server/scripts
COPY --from=wasp-build /app/.wasp/build/db/ ./db/
EXPOSE ${PORT}
WORKDIR /app/server
ENTRYPOINT ["npm", "run", "start-production"]
.wasp/
.github/
.vscode/
caprover/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment