Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 10 additions & 5 deletions apps/api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# local-test/api-gateway.Dockerfile
# Using a consistent base for all stages
ARG BASE_IMAGE=node:22-alpine
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS builder

ARG DIR=/usr/src/app
Expand All @@ -12,30 +12,35 @@ RUN yarn global add turbo@^2.0.3
RUN turbo prune api-gateway --docker && rm -f .npmrc

# Installing the isolated workspace
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS installer
ARG DIR=/usr/src/app
WORKDIR $DIR
COPY --from=builder $DIR/out/json/ .
COPY --from=builder $DIR/out/yarn.lock ./yarn.lock
COPY --from=builder $DIR/turbo.json ./turbo.json
COPY --from=builder $DIR/packages ./packages
RUN yarn install --ignore-scripts --frozen-lockfile --network-timeout 600000
RUN yarn install --ignore-scripts --frozen-lockfile

# Running build using turbo
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS sourcer
ARG DIR=/usr/src/app
WORKDIR $DIR
COPY --from=installer $DIR/ .
COPY --from=builder $DIR/out/full/ .
COPY --from=builder /usr/local/share/.config/yarn/global /usr/local/share/.config/yarn/global
RUN yarn build --filter=api-gateway && yarn install --production --ignore-scripts --frozen-lockfile --network-timeout 600000
RUN yarn build --filter=api-gateway && yarn install --production --ignore-scripts --frozen-lockfile

# Production stage
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS production
ARG DIR=/usr/src/app
ENV NODE_ENV production
WORKDIR $DIR
RUN apk add --no-cache dumb-init
RUN apk add --no-cache dumb-init~=1
COPY --chown=node:node --from=sourcer $DIR/apps/api-gateway/package.json ./package.json

COPY --chown=node:node --from=sourcer $DIR/apps/api-gateway/dist ./dist
COPY --chown=node:node --from=sourcer $DIR/node_modules $DIR/node_modules
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
Expand All @@ -46,4 +51,4 @@ EXPOSE 3000
FROM production AS patched
USER root
RUN apk -U upgrade
USER node
USER node
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Request } from "express";
export enum UserRole {
LEARNER = "learner",
AUTHOR = "author",
ADMIN = "admin",
}

export interface UserSession {
Expand Down
6 changes: 4 additions & 2 deletions apps/api-gateway/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import instana from "@instana/collector";
import { VersioningType } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import * as cookieParser from "cookie-parser";
import { json, urlencoded } from "express";
import helmet from "helmet";
import { WinstonModule } from "nest-winston";
import { AppModule } from "./app.module";
import { winstonOptions } from "./logger/config";
import instana from "@instana/collector";

instana();

Expand All @@ -15,7 +16,8 @@ async function bootstrap() {
cors: false,
logger: WinstonModule.createLogger(winstonOptions),
});

app.use(json({ limit: "1000mb" }));
app.use(urlencoded({ limit: "1000mb", extended: true }));
app.setGlobalPrefix("api", {
exclude: ["health", "health/liveness", "health/readiness"],
});
Expand Down
5 changes: 4 additions & 1 deletion apps/api/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = {
],
rules: {
"unicorn/prefer-top-level-await": "off",
'unicorn/no-nested-ternary': 'off',
"unicorn/no-nested-ternary": "off",
"unicorn/no-null": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/require-await": "off",
"unicorn/no-abusive-eslint-disable": "off",
"unicorn/prevent-abbreviations": [
"error",
Expand Down
31 changes: 17 additions & 14 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
# local-test/api.Dockerfile
# Using a consistent base for all stages
ARG BASE_IMAGE=node:22-alpine
FROM node:22-alpine AS builder
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS builder

ARG DIR=/usr/src/app

# Pruning using turbo
# Copy package files for dependency resolution
WORKDIR $DIR
COPY . .
RUN yarn global add turbo@^2.0.3
RUN turbo prune api --docker && rm -f .npmrc

# Installing the isolated workspace
FROM node:22-alpine AS installer
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS installer
ARG DIR=/usr/src/app
WORKDIR $DIR
COPY --from=builder $DIR/out/json/ .
COPY --from=builder $DIR/out/yarn.lock ./yarn.lock
COPY --from=builder $DIR/turbo.json ./turbo.json
COPY --from=builder $DIR/packages ./packages
COPY --from=builder $DIR/apps/api/prisma ./prisma
RUN yarn install --ignore-scripts --frozen-lockfile --network-timeout 600000
# Install build dependencies (including pkgconf) and rebuild native modules
RUN apk add --no-cache python3~=3 make~=4 g++~=14 pkgconf~=2 \
&& yarn install --frozen-lockfile \
&& yarn prisma generate \
&& npm rebuild cld --build-from-source

# Running build using turbo
FROM node:22-alpine AS sourcer
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS sourcer
ARG DIR=/usr/src/app
WORKDIR $DIR
COPY --from=installer $DIR/ .
COPY --from=builder $DIR/out/full/ .
COPY --from=builder /usr/local/share/.config/yarn/global /usr/local/share/.config/yarn/global
WORKDIR $DIR/apps/api
RUN npx prisma generate
WORKDIR $DIR
RUN yarn build --filter=api && yarn install --production --ignore-scripts --frozen-lockfile --network-timeout 600000
RUN yarn build --filter=api && yarn install --production --ignore-scripts --frozen-lockfile

# Production stage
FROM node:22-alpine AS production
ARG DIR=/usr/src/app
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} AS production
ENV NODE_ENV production
ARG DIR=/usr/src/app
WORKDIR $DIR
RUN apk add --no-cache dumb-init=1.2.5-r3
RUN apk add --no-cache dumb-init~=1 postgresql15-client~=15
COPY --chown=node:node --from=sourcer $DIR/apps/api/package.json ./package.json
COPY --chown=node:node --from=sourcer $DIR/apps/api/dist ./dist
COPY --chown=node:node --from=sourcer $DIR/node_modules $DIR/node_modules
COPY --chown=node:node --from=sourcer $DIR/prisma ./prisma
COPY --chown=node:node --from=sourcer $DIR/apps/api/migrate.sh ./migrate.sh
COPY --chown=node:node --from=sourcer $DIR/apps/api/ensureDb.js ./ensureDb.js
COPY --chown=node:node --from=sourcer $DIR/apps/api/src/scripts ./scripts
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "dist/main.js"]
CMD ["node", "dist/src/main.js"]
EXPOSE 3000

# Patched stage with updates
Expand Down
Loading