-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDockerfile-be
59 lines (49 loc) · 2.07 KB
/
Dockerfile-be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# A container with pnpm and python3 is required
FROM node:21.7.3-alpine as pnpm_base
WORKDIR /app
RUN npm i --global --no-update-notifier --no-fund pnpm@8
RUN apk update
RUN apk add --no-cache g++ make py3-pip libc6-compat git openssh
# run fetch in a separate step to avoid re-fetching deps on every change
FROM pnpm_base as fetched_deps
WORKDIR /app
ENV NODE_ENV production
COPY pnpm-lock.yaml ./
RUN pnpm config set store-dir /workdir/.pnpm-store
RUN pnpm fetch
# install all deps from cache
FROM fetched_deps as with_all_deps
COPY . ./
RUN pnpm install --offline
# Build the BE
# the main issue with building everything is the FE depends on a running BE
FROM with_all_deps as builder
RUN pnpm --filter='*backend-api' build
RUN pnpm --filter='*backend-api' deploy pruned --prod
# get the latest code files
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan -H github.com ghNestBackend ghMacSetup ghMiller >>~/.ssh/known_hosts
# COPY ./libs/project-deploy/sshConfig.txt ~/.ssh/config
RUN mkdir -p /app/code-repos
WORKDIR /app/code-repos
RUN --mount=type=ssh,id=nestbackend git clone [email protected]:darraghoriordan/nest-backend-libs.git
RUN rm -rf /app/code-repos/nest-backend-libs/.git
RUN --mount=type=ssh,id=macsetup git clone [email protected]:darraghoriordan/mac-setup-script.git
RUN rm -rf /app/code-repos/mac-setup-script/.git
RUN --mount=type=ssh,id=usemiller git clone [email protected]:darraghoriordan/use-miller.git
RUN rm -rf /app/code-repos/use-miller/.git
# Lean production image - only take pruned assets
FROM node:21.7.3-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 app
RUN adduser --system --uid 1001 app
USER app
COPY --chown=app:app --from=builder /app/code-repos /app/code-repos
COPY --chown=app:app --from=builder /app/apps/backend/dist/src src
COPY --chown=app:app --from=builder /app/apps/backend/package.json package.json
COPY --chown=app:app --from=builder /app/apps/backend/dist/migrations src/migrations
COPY --chown=app:app --from=builder /app/pruned/node_modules node_modules
EXPOSE 5000
ENV PORT 5000
CMD ["node", "src/main.js"]
#CMD ["ls", "-la"]