-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
218 lines (167 loc) Β· 5.37 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
##
## ---- Base OS layer ----
## docker build -t styled-wotd --build-arg IMAGE_SOURCE=node --build-arg IMAGE_TAG=lts --build-arg VERCEL_TOKEN=<token> .
##
ARG IMAGE_SOURCE=node
ARG IMAGE_TAG=lts
FROM ${IMAGE_SOURCE}:${IMAGE_TAG} AS base
## setup base stage
RUN echo "**** Base stage ****"
## setup image arguments
ARG PYTHON_VERSION=3.8.2
ARG VERCEL_TOKEN
ARG USER
ARG UID
ARG GID
ARG NAME="styled-wotd"
ARG VERSION="$(git describe --abbrev=0 --tag)"
ARG PACKAGE="AlexRogalskiy/wotd"
ARG DESCRIPTION="Automatically generate styled SVG Word of the Day upon request"
ARG LC_ALL="en_US.UTF-8"
ARG BUILD_DATE="$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")"
ARG VCS_REF="$(git rev-parse --short HEAD)"
ARG APP_DIR="/usr/src/app"
ARG DATA_DIR="/usr/src/data"
ARG TEMP_DIR="/tmp"
ARG INSTALL_PACKAGES="git curl dumb-init gosu dos2unix locales letsencrypt"
## setup image labels
LABEL "name"="$NAME"
LABEL "version"="$VERSION"
LABEL "description"="$DESCRIPTION"
LABEL "com.github.repository"="https://github.com/${PACKAGE}"
LABEL "com.github.homepage"="https://github.com/${PACKAGE}"
LABEL "com.github.documentation"="https://github.com/${PACKAGE}/blob/master/README.md"
LABEL "com.github.maintainer"="Sensiblemetrics, Inc. <hello@sensiblemetrics.io> (https://sensiblemetrics.io)"
LABEL "com.github.version"="$VERSION"
LABEL "com.github.build-date"="$BUILD_DATE"
LABEL "com.github.vcs-ref"="$VCS_REF"
LABEL "com.github.name"="$NAME"
LABEL "com.github.description"="$DESCRIPTION"
## setup environment variables
ENV PYTHON_VERSION $PYTHON_VERSION
ENV APP_DIR=$APP_DIR \
DATA_DIR=$DATA_DIR \
TEMP_DIR=$TEMP_DIR
ENV TZ=UTC \
LANGUAGE=en_US:en \
LC_ALL=$LC_ALL \
LC_CTYPE=$LC_ALL \
LANG=$LC_ALL \
PYTHONIOENCODING=UTF-8 \
PYTHONLEGACYWINDOWSSTDIO=UTF-8 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
DEBIAN_FRONTEND=noninteractive \
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DEFAULT_TIMEOUT=100 \
NPM_CONFIG_LOGLEVEL=error \
IN_DOCKER=true
ENV VERCEL_TOKEN $VERCEL_TOKEN
ENV USER=${USER:-'devbot'} \
UID=${UID:-5000} \
GID=${GID:-10000}
## create user
RUN addgroup --gid "$GID" "$USER" || exit 0
RUN adduser \
--disabled-password \
--gecos "" \
--ingroup "$USER" \
--uid "$UID" \
--shell /bin/bash \
"$USER" \
|| exit 0
## mount volumes
VOLUME ["$APP_DIR", "$DATA_DIR", "$TEMP_DIR"]
## create working directory
WORKDIR $APP_DIR
## install dependencies
RUN echo "**** Installing build packages ****"
## RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends $INSTALL_PACKAGES \
&& apt-get autoclean \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*
## install python
RUN echo "**** Installing Python ****"
RUN cd /tmp && curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz && \
tar -xvf Python-${PYTHON_VERSION}.tar.xz && \
cd Python-${PYTHON_VERSION} && \
./configure --enable-optimizations && \
make -j 4 && \
make altinstall && \
ln -s /usr/local/bin/python3.8 /usr/bin/python3.8
## install node
RUN echo "**** Installing Node ****"
RUN npm install -g npm && \
npm install -g vercel
## show versions
RUN echo "npm version: $(npm --version)"
RUN echo "node version: $(node --version | awk -F. '{print $1}')"
RUN echo "python version: $(python3 --version)"
## setup entrypoint
## ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64 /usr/local/bin/dumb-init
## RUN chmod +x /usr/local/bin/dumb-init
## ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
ENTRYPOINT ["dumb-init", "--"]
## ENTRYPOINT [ "/usr/bin/tini", "--" ]
## remove cache
RUN echo "**** Cleaning cache ****"
RUN apt-get remove -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev g++
RUN rm -rf /var/cache/apt/* /tmp/* /var/tmp/*
## copy project files
COPY package.json .
COPY scripts ./scripts
COPY data ./data
##
## ---- Node Dependencies ----
##
FROM base AS node-dependencies
## setup node modules stage
RUN echo "**** Installing node modules stage ****"
## update npm settings
RUN npm set progress=false && npm config set depth 0
## install only <production> node_modules
## RUN npm install --no-audit --only=prod
## copy production node_modules aside
## RUN cp -R node_modules prod_node_modules
## install node_modules, including 'devDependencies'
RUN npm install --no-audit
## run vercel
RUN yes | vercel --confirm --token $VERCEL_TOKEN
## remove cache
RUN echo "**** Cleaning node cache ****"
RUN npm cache clean --force
##
## ---- Testing ----
##
FROM node-dependencies AS test
## setup testing stage
RUN echo "**** Testing stage ****"
## copy source files
COPY . ./
## run format checking & linting
RUN npm run test:license
##
## ---- Release ----
##
FROM base AS release
## setup release stage
RUN echo "**** Release stage ****"
## copy dependencies
#COPY --from=node-dependencies ${APP_DIR}/prod_node_modules ./node_modules
COPY --from=node-dependencies ${APP_DIR}/node_modules ./node_modules
## copy app sources
COPY . ./
## run scripts
#RUN dos2unix ./scripts/env.sh && \
# . ./scripts/env.sh
## setup user
USER $USER
## expose port
EXPOSE 3000
## define cmd
CMD [ "npm", "run", "develop:docker" ]