diff --git a/packages/whook-example/Dockerfile b/packages/whook-example/Dockerfile new file mode 100644 index 00000000..ff3cc1f5 --- /dev/null +++ b/packages/whook-example/Dockerfile @@ -0,0 +1,56 @@ +FROM node:18-alpine AS build-image + +WORKDIR /app + +# For PG Native build +RUN apk --no-cache add make python3 gcc postgresql-dev g++ + +COPY package.json package-lock.json* ./ + +# **IMPORTANT**: Replace this line per +# `npm ci` in your own deployments +# For it to work in the `whook` monorepos, +# had to remove the c +RUN npm i + +ARG NODE_ENV=production +ENV NODE_ENV=$NODE_ENV + +ARG APP_ENV=production +ENV APP_ENV=$APP_ENV + +ARG DEV_MODE=0 +ENV DEV_MODE=$DEV_MODE + +COPY ./bin /app/bin +COPY ./src /app/src +COPY ./tsconfig.json /app/tsconfig.json +RUN npm run build +RUN npm ci --production && npm cache clean --force + +FROM node:18-alpine +WORKDIR /app + +COPY package.json package-lock.json* ./ + +COPY --from=build-image /app/node_modules /app/node_modules +COPY --from=build-image /app/dist /app/dist +COPY --from=build-image /app/builds /app/builds +COPY --from=build-image /app/bin /app/bin + +ARG NODE_ENV=production +ENV NODE_ENV=$NODE_ENV + +ARG APP_ENV=production +ENV APP_ENV=$APP_ENV + +ARG HOST=0.0.0.0 +ENV HOST=$HOST +ARG PORT=8000 +ENV PORT=$PORT + +ENV MAIN_FILE builds/${APP_ENV}/server/start.js + +EXPOSE ${PORT} + +CMD node ${MAIN_FILE} diff --git a/packages/whook-example/README.md b/packages/whook-example/README.md index f2460b28..62ed5258 100644 --- a/packages/whook-example/README.md +++ b/packages/whook-example/README.md @@ -72,6 +72,13 @@ Generate API types: npm run apitypes ``` +## Deploy with Docker + +```sh +docker build --build-arg 'APP_ENV=production' -t whook-api . +docker run --env 'JWT_SECRET=lol' --env 'HOST=0.0.0.0' -p 127.0.0.1:8000:8000/tcp whook-api +``` + ## Debug Execute a handler in isolation: diff --git a/packages/whook-example/src/config/production/config.ts b/packages/whook-example/src/config/production/config.ts index a82d2798..a7d31579 100644 --- a/packages/whook-example/src/config/production/config.ts +++ b/packages/whook-example/src/config/production/config.ts @@ -3,7 +3,7 @@ import type { AppConfig } from 'application-services'; const CONFIG: AppConfig = { ...COMMON_CONFIG, - HOST: 'api.example.com', + HOST: '0.0.0.0', }; export default CONFIG;