-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Dockerfile
71 lines (66 loc) · 2.14 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
#
# KOA REST API BOILERPLATE
#
# build:
# docker build --force-rm -t posquit0/koa-rest-api-boilerplate --build-arg NPM_TOKEN=${NPM_TOKEN} .
# run:
# docker run --rm -it --env-file=path/to/.env --name koa-rest-api-boilerplate -p 80:7071 posquit0/koa-rest-api-boilerplate
#
#
### BASE
FROM node:14.16.1-alpine AS base
LABEL maintainer "Byungjin Park <[email protected]>"
RUN \
# Add our own user and group to avoid permission problems
addgroup -g 131337 app \
&& adduser -u 131337 -G app -s /bin/sh -h /app -D app \
# Create directories for application
&& mkdir -p /app/src
# Set the working directory
WORKDIR /app/src
# Copy project specification and dependencies lock files
COPY package.json yarn.lock ./
### DEPENDENCIES
FROM base AS dependencies
ARG NPM_TOKEN
RUN \
# Install dependencies for `node-gyp`
apk add --no-cache --virtual .gyp python make g++ \
# Configure NPM for private repositories
&& echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc \
# Install Node.js dependencies (only production)
&& yarn --production \
# Backup production dependencies aside
&& cp -R ./node_modules /tmp \
# Install ALL Node.js dependencies
&& yarn \
# Delete the NPM token
&& rm -f .npmrc \
# Backup development dependencies aside
&& mv ./node_modules /tmp/node_modules_dev
### RELEASE
FROM base AS release
# Install for healthcheck
RUN apk add --update --no-cache curl
# Copy development dependencies if --build-arg DEBUG=1, or production dependencies
ARG DEBUG
COPY --from=dependencies /tmp/node_modules${DEBUG:+_dev} ./node_modules
# Copy app sources
COPY . .
# Change permissions for files and directories
RUN chown -R app:app /app && chmod g+s /app
# Expose application port
ENV APP_PORT 7071
EXPOSE ${APP_PORT}
# Check container health by running a command inside the container
HEALTHCHECK --interval=5s \
--timeout=5s \
--retries=6 \
CMD curl -fs http://localhost:${APP_PORT}/ || exit 1
# Set NODE_ENV to 'development' if --build-arg DEBUG=1, or 'production'
ENV NODE_ENV=${DEBUG:+development}
ENV NODE_ENV=${NODE_ENV:-production}
# Use non-root user
USER app:app
# Run
CMD [ "node", "app" ]