forked from openstad/openstad-headless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
executable file
·83 lines (60 loc) · 1.97 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
79
80
81
82
83
# Image used for building dependencies
FROM node:18-slim as builder
ARG APP
ENV WORKSPACE apps/${APP}
LABEL org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}
# Create app directory
WORKDIR /opt/openstad-headless
# Install all base dependencies.# add perl for shell scripts
RUN apt-get update && \
apt-get install -y python3 make cmake git bash g++
# Install app dependencies
COPY --chown=node:node package*.json .
# Bundle all packages during build, only the installed once will persist
COPY --chown=node:node packages/ ./packages
COPY --chown=node:node apps/$APP ./apps/$APP
RUN npm install -w $WORKSPACE
RUN npm run build-packages --if-present --prefix=$WORKSPACE
# Disabled for now since the admin/web server won't build due to errors
# && \
# npm run build --prefix=@openstad-headless/${APP} --if-present
# Development image
FROM builder as development
ARG APP
ENV WORKSPACE apps/${APP}
# Create app directory
WORKDIR /opt/openstad-headless
CMD ["npm", "run", "dev", "--prefix=${WORKSPACE}"]
# Prepare production
FROM builder as prepare-production
ARG APP
ENV WORKSPACE apps/${APP}
RUN npm --prefix=apps/${APP} run build --if-present && \
npm --prefix=apps/${APP} prune --production
# Release image
FROM node:18-slim as release
ARG APP
ARG PORT
ENV WORKSPACE apps/${APP}
WORKDIR /opt/openstad-headless
RUN apt-get update && \
apt-get install -y netcat-traditional && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# copy files
COPY --from=prepare-production --chown=node:node /opt/openstad-headless/apps/${APP} ./apps/${APP}
USER node
EXPOSE ${PORT}
# Run the application
CMD ["npm", "run", "start", "--prefix=${WORKSPACE}"]
FROM release as release-with-packages
ARG APP
ARG PORT
ENV WORKSPACE apps/${APP}
WORKDIR /opt/openstad-headless
# copy files
COPY --from=prepare-production --chown=node:node /opt/openstad-headless/packages ./packages
USER node
EXPOSE ${PORT}
# Run the application
CMD ["npm", "run", "start", "--prefix=${WORKSPACE}"]