-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile
78 lines (54 loc) · 1.63 KB
/
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
FROM node:18-alpine AS ts-build
RUN mkdir -p /app
COPY package.json yarn.lock /app/
WORKDIR /app
# Install Node dependencies
RUN yarn install --ignore-scripts
# Copy source files
COPY ./src /app/src
COPY ./prisma /app/prisma
COPY ./bin /app/bin
COPY ./config /app/config
COPY tsconfig.json /app
# Generate local prisma client
RUN yarn prisma generate
# Build/transpile from ts to js
RUN yarn build
# Generate build container
FROM node:18-alpine
LABEL Maintainer="Gonzalo Plaza <[email protected]>" \
Description="Lightweight container with Node 16 based on Alpine Linux"
# Environment vars
ARG NODE_ENV=development
ENV NODE_CONFIG_STRICT_MODE=1
ENV NODE_ENV=$NODE_ENV
ENV APP_NAME=express-ts-ddd
ENV APP_LOG_LEVEL=debug
ENV COGNITO_USER_POOL=""
ENV COGNITO_CLIENT_ID=""
ENV COGNITO_REGION=""
ENV PORT=3000
# Configure user
RUN addgroup -S webuser \
&& adduser -S webuser -G webuser
# Install Alpine dependencies
RUN apk --no-cache add supervisor && \
rm -rf /var/cache/apk/*
# Configure supervisord
COPY ./etc/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN mkdir -p /app /app/logs
WORKDIR /app
COPY package.json yarn.lock /app/
# Install production Node dependencies
RUN yarn install --ignore-scripts --production
# Copy nodels build from previous stage
COPY --from=ts-build /app/dist /app/
# Generate prisma client
COPY ./prisma /app/prisma
RUN yarn prisma generate && rm -rf /app/prisma
# Expose the port nginx is reachable on
EXPOSE ${PORT}
# Set the user
USER webuser
# Let supervisord start nginx && node js built app
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]