Skip to content

Commit 642c892

Browse files
committed
Docker
1 parent 4a1a79c commit 642c892

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM node:22-alpine AS base
2+
3+
# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
4+
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.
5+
6+
FROM base AS builder
7+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8+
RUN apk update
9+
RUN apk add --no-cache libc6-compat
10+
# Set working directory
11+
WORKDIR /contwatch-client
12+
RUN npm install turbo
13+
COPY . .
14+
RUN npx turbo prune contwatch-client --docker
15+
16+
# Add lockfile and package.json's of isolated subworkspace
17+
FROM base AS installer
18+
RUN apk update
19+
RUN apk add --no-cache libc6-compat
20+
WORKDIR /contwatch-client
21+
22+
# First install dependencies (as they change less often)
23+
COPY --from=builder /contwatch-client/out/json/ .
24+
RUN npm install
25+
26+
# Build the project and its dependencies
27+
COPY --from=builder /contwatch-client/out/full/ .
28+
29+
# Uncomment and use build args to enable remote caching
30+
# ARG TURBO_TEAM
31+
# ENV TURBO_TEAM=$TURBO_TEAM
32+
33+
# ARG TURBO_TOKEN
34+
# ENV TURBO_TOKEN=$TURBO_TOKEN
35+
36+
RUN npx turbo build --filter=contwatch-client...
37+
38+
FROM base AS runner
39+
WORKDIR /contwatch-client
40+
41+
# Don't run production as root
42+
RUN addgroup --system --gid 1001 nodejs
43+
RUN adduser --system --uid 1001 nextjs
44+
USER nextjs
45+
46+
COPY --from=installer --chown=nextjs:nodejs /contwatch-client/apps/contwatch-client/.next/standalone ./
47+
COPY --from=installer --chown=nextjs:nodejs /contwatch-client/apps/contwatch-client/.next/static ./apps/contwatch-client/.next/static
48+
COPY --from=installer --chown=nextjs:nodejs /contwatch-client/apps/contwatch-client/public ./apps/contwatch-client/public
49+
50+
CMD node apps/contwatch-client/server.js

src/client/apps/contwatch-client/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { HOST, PORT, PROTOCOL } from "./src/settings.mjs";
33

44
const nextConfig = {
5-
// output: "standalone",
5+
output: "standalone",
66
experimental: {
77
turbo: {
88
useSwcCss: true,

src/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
client:
3+
build:
4+
context: client
5+
dockerfile: ./apps/contwatch-client/Dockerfile
6+
restart: always
7+
network_mode: host
8+
api:
9+
build:
10+
context: server
11+
restart: always
12+
working_dir: /api
13+
network_mode: host

src/server/Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM python:3.12-alpine AS base
2+
3+
FROM base AS builder
4+
5+
WORKDIR /api
6+
7+
RUN apk update \
8+
&& apk add --no-cache --virtual build-deps g++ \
9+
&& apk add --no-cache libpq-dev \
10+
# && ln -s "/usr/lib/libcrypto.so.3" "/usr/lib/libcrypto.so" \
11+
&& pip3 install pipenv --no-cache-dir --disable-pip-version-check --root-user-action=ignore
12+
13+
# Allows docker to cache installed dependencies between builds
14+
COPY "Pipfile" "Pipfile.lock" ./
15+
RUN pipenv install --system --deploy --ignore-pipfile \
16+
&& pipenv --clear
17+
18+
# Mounts the application code to the image
19+
COPY . ./
20+
21+
RUN apk del build-deps \
22+
&& for dir in pip pipenv setuptools virtualenv docs distlib pkg_resources packaging certify; \
23+
do rm -rf "/usr/local/lib/python3.12/site-packages/$dir"*; done
24+
25+
FROM base AS runner
26+
27+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
28+
COPY --from=builder /usr/local/bin /usr/local/bin
29+
30+
WORKDIR /api
31+
COPY --from=builder /api ./
32+
33+
RUN apk update \
34+
# && apk add --no-cache binutils libmagic \
35+
# && ln -s "/usr/lib/libcrypto.so.3" "/usr/lib/libcrypto.so" \
36+
&& pip3 install pipenv --no-cache-dir --disable-pip-version-check --root-user-action=ignore
37+
# && crontab /api/cron
38+
39+
#ARG DEBUG
40+
#ENV DJANGO_DEBUG=${DEBUG}
41+
ARG PORT
42+
ENV PORT=${PORT}
43+
#ARG UWSGI_PROTOCOL
44+
#ENV PROTOCOL=${UWSGI_PROTOCOL}
45+
46+
# runs the production server
47+
CMD ["sh", "-c", "./main.py"]

0 commit comments

Comments
 (0)