Skip to content

Commit

Permalink
chore: containerize nestjs express example app (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmastrom committed May 2, 2024
1 parent c7fd3ef commit 3f7868f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,47 @@ steps:
'--service-account=$_SERVICE_ACCOUNT',
]
# ---------------------------------------------------------------
# NestJS Express integration
- name: 'gcr.io/cloud-builders/docker'
id: 'build-nest-js-express'
waitFor: ['push-base']
args:
[
'buildx',
'build',
'--build-arg',
'BASE_IMAGE=gcr.io/${_PROJECT_ID}/${_BASE_BUILDER}',
'-t',
'gcr.io/${_PROJECT_ID}/${_SERVICE_NEST_JS_EXPRESS}',
'-f',
'./examples/nestjs-api-reference-express/Dockerfile',
'.',
]
- name: 'gcr.io/cloud-builders/docker'
id: 'push-nest-js-express'
waitFor: ['build-nest-js-express']
args: ['push', 'gcr.io/${_PROJECT_ID}/${_SERVICE_NEST_JS_EXPRESS}']
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
waitFor: ['push-nest-js-express']
args:
[
'run',
'deploy',
'$_SERVICE_NEST_JS_EXPRESS',
'--image=gcr.io/${_PROJECT_ID}/${_SERVICE_NEST_JS_EXPRESS}',
'--region=$_REGION',
'--platform=managed',
'--allow-unauthenticated',
'--execution-environment=gen2',
'--cpu=$_CPU',
'--memory=$_MEMORY',
'--service-account=$_SERVICE_ACCOUNT',
]
# ---------------------------------------------------------------
# Other Integration
# - name: OTHER INTEGRATION
# ---------------------------------------------------------------
options:
machineType: E2_HIGHCPU_8
logging: CLOUD_LOGGING_ONLY
Empty file.
52 changes: 52 additions & 0 deletions examples/nestjs-api-reference-express/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE} AS builder
WORKDIR /app

COPY pnpm-lock.yaml .
COPY pnpm-workspace.yaml .
COPY package.json .
COPY tsconfig.json .
COPY packages/api-reference ./packages/api-reference
COPY packages/components ./packages/components
COPY packages/themes ./packages/themes
COPY packages/oas-utils ./packages/oas-utils
COPY packages/build-tooling ./packages/build-tooling
COPY packages/nestjs-api-reference ./packages/nestjs-api-reference
COPY examples/nestjs-api-reference-express ./examples/nestjs-api-reference-express

RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store \
pnpm --filter @scalar-examples/nestjs-api-reference-express install --frozen-lockfile && \
pnpm --filter @scalar-examples/nestjs-api-reference-express build

FROM node:18-bullseye-slim AS runner
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init

RUN npm install -g pnpm
ENV NODE_ENV production

# Create a non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nestjs

# Set the correct permission for the build
RUN mkdir app

RUN chown nestjs:nodejs app

WORKDIR /app

# Copy root node modules and any utilized packages
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/packages/components /app/packages/components
COPY --from=builder /app/packages/themes /app/packages/themes
COPY --from=builder /app/packages/oas-utils /app/packages/oas-utils
COPY --from=builder /app/packages/build-tooling /app/packages/build-tooling
COPY --from=builder /app/packages/api-reference /app/packages/api-reference
COPY --from=builder /app/packages/nestjs-api-reference /app/packages/nestjs-api-reference
COPY --from=builder /app/examples/nestjs-api-reference-express /app/examples/nestjs-api-reference-express

WORKDIR /app/examples/nestjs-api-reference-express

USER nestjs

CMD ["dumb-init", "node", "dist/main.js"]

0 comments on commit 3f7868f

Please sign in to comment.