forked from DevOps-2024-group-p/maxitwit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.api
57 lines (47 loc) · 1.5 KB
/
Dockerfile.api
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
# syntax=docker/dockerfile:1
ARG NODE_VERSION=21.6.2
FROM node:${NODE_VERSION}-alpine as base
# Expose the port that the application listens on.
EXPOSE 3001
WORKDIR /usr/src/app
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into
# into this layer.
FROM base as development
ENV NODE_ENV development
ENV API true
ENV HUSKY=0
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --include=dev
USER root
COPY . .
RUN npx prisma generate
CMD npm run devstart
FROM base as production
ENV NODE_ENV production
ENV API true
ENV HUSKY=0
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev
USER root
COPY . .
RUN npx prisma generate
CMD npm run start:migrate
FROM base as test
ENV NODE_ENV test
ENV API true
ENV HUSKY=0
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --include=dev
USER root
COPY . .
CMD npx prisma generate && \
npx prisma migrate reset --skip-seed --force && \
npm run devstart