Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deploy): add docker recipes to deploy #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:20-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:20-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;