forked from pkosiec/mongo-seeding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.Dockerfile
80 lines (58 loc) · 1.75 KB
/
dev.Dockerfile
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Run with context of the upper level directory
#
# Stage 1: Core
#
FROM node:18-alpine AS coreBuilder
ENV CORE_DIR=./core
WORKDIR /app
# Copy sources
COPY $CORE_DIR/package.json $CORE_DIR/package-lock.json $CORE_DIR/tsconfig.json /app/
COPY $CORE_DIR/src /app/src/
# Install dependencies
RUN npm install --no-optional
# Build app
RUN npm run build
# Remove sources
RUN rm -rf /app/src/ && \
rm -rf /app/node_modules/
RUN npm i --production --no-optional
#
# Stage 2: CLI
#
FROM node:18-alpine as cliBuilder
ENV CLI_DIR=./cli
WORKDIR /app
# Install dependencies
COPY $CLI_DIR/package.json $CLI_DIR/package-lock.json $CLI_DIR/tsconfig.json /app/
RUN npm i --no-optional
# Copy built core
COPY --from=coreBuilder /app/ node_modules/mongo-seeding/
# Copy app sources
COPY $CLI_DIR/src/ /app/src/
COPY $CLI_DIR/bin/ /app/bin/
# Build app
RUN npm run build
# Remove unnecessary sources
RUN rm -rf /app/src/ && \
rm -rf /app/node_modules/
#
# Stage 3: Final Docker image
#
FROM node:18-alpine
LABEL org.opencontainers.image.title="Mongo Seeding" \
org.opencontainers.image.description=" The ultimate solution for populating your MongoDB database. " \
org.opencontainers.image.url="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.documentation="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.source="https://github.com/pkosiec/mongo-seeding.git" \
org.opencontainers.image.version="dev" \
org.opencontainers.image.licenses="MIT"
WORKDIR /app
COPY --from=cliBuilder /app/ /app/
# Create a symlink
RUN npm i --production --no-optional && \
npm link && \
rm -rf /app/node_modules/mongo-seeding/
# Copy built core
COPY --from=coreBuilder /app/ /app/node_modules/mongo-seeding/
WORKDIR /data
CMD seed