My Dockerfile for hosting Wappler NodeJS on Caprover

Dockerfile:

FROM node:16-bullseye-slim

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG PORT=3000
ENV PORT $PORT
EXPOSE $PORT

RUN apt update && apt install jq -y

ENV PATH /opt/node_app/node_modules/.bin:$PATH

WORKDIR /opt/node_app

COPY package.json .
RUN npm install --no-optional
COPY . .

RUN jq '.options.connection.host = "{{$_ENV.DB_HOST}}" | .options.connection.port = "{{$_ENV.DB_PORT}}" | .options.connection.user = "{{$_ENV.DB_USER}}" | .options.connection.password = "{{$_ENV.DB_PASS}}" | .options.connection.database = "{{$_ENV.DB_NAME}}"' app/modules/connections/db.json > jq_out.json \
    && cp jq_out.json app/modules/connections/db.json

RUN jq '.debug = false' app/config/config.json > jq_out.json \
    && cp jq_out.json app/config/config.json

RUN jq '.env = {}' app/config/config.json > jq_out.json \
    && cp jq_out.json app/config/config.json

CMD [ "nodemon", "./index.js" ]

captain-definition.yml:

{
 "schemaVersion" :2 ,
 "dockerfilePath": "./Dockerfile"
}

The Dockerfile will patch Wappler files to read the following environment variables for the database named “db” (on Wappler):

DB_HOST
DB_PORT
DB_NAME
DB_USER
DB_PASS

Not handling Redis yet. Tagging @sid as he might find this useful

Todo:

  • Redis support
  • Read debug mode from ENV
2 Likes

Thanks for the mention. :slightly_smiling_face:

Why don’t you set the DB env variables directly in Wappler?
All my Caprover deployments use that.

Oh, I think you’ve asked that question before :thinking:

Long story short, I didn’t trust Wappler wouldn’t override my config. I think the port number issue is still unfixed (only accepts integers), so if you happen to go near those settings you might break it again at save

it is fixed and we have now data pickers, so you can pick from the defined $_ENV variables

1 Like

Oh. Yes.
I recollect about the port thing.

Before the latest update with ENV support, I never even once had a pproblem with modifying the db.json files.

But now that its supported officially, you can probably do away with dockerfile for this.