Skip to content

Commit

Permalink
feat(deploy): add docker recipes to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 27, 2024
1 parent 4600433 commit 406181e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
56 changes: 56 additions & 0 deletions packages/whook-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 7 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-example/src/config/production/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 406181e

Please sign in to comment.