-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile.api
43 lines (41 loc) · 1.65 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
# Install dependencies for all subprojects
FROM node:alpine AS base
WORKDIR /app
# Install 'libc6-compat'
RUN apk add --no-cache libc6-compat
WORKDIR /app/packages/api
# Install dependencies
COPY packages/api/package.json packages/api/yarn.lock ./
RUN yarn install --frozen-lockfile
WORKDIR /app/packages/common
# Install dependencies
COPY packages/common/package.json packages/common/yarn.lock ./
RUN yarn install --frozen-lockfile
# Build API
FROM node:alpine AS api-builder
WORKDIR /app/packages/api
COPY /packages/api /app/packages/api
COPY /packages/common /app/packages/common
COPY --from=base /app/packages/api/node_modules ./node_modules
COPY --from=base /app/packages/common/node_modules /app/packages/common/node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app/packages/api
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodeuser -u 1001
# Copy only necessary files
COPY --from=api-builder --chown=nodeuser /app/packages/api/dist ./dist
COPY --from=api-builder /app/packages/api/.env ./.env
COPY --from=api-builder /app/packages/api/src/config/config.js ./src/config/config.js
COPY --from=api-builder /app/packages/api/src/migrations ./src/migrations
COPY --from=api-builder /app/packages/api/package.json ./package.json
COPY --from=api-builder /app/packages/api/tsconfig.json ./tsconfig.json
COPY --from=api-builder /app/packages/api/.sequelizerc ./.sequelizerc
COPY --from=api-builder /app/packages/api/node_modules ./node_modules
USER nodeuser
ARG PORT=3000
ENV NODE_ENV production
ENV PORT $PORT
EXPOSE $PORT
CMD ["yarn", "migrate-and-start"]