Skip to content

Commit

Permalink
Merge pull request #457 from joakimfors/master
Browse files Browse the repository at this point in the history
Streamline Dockerfile for caching and size
  • Loading branch information
petrsloup authored Dec 11, 2020
2 parents 6ff4cae + 6b3f557 commit 51baa9b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
13 changes: 6 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.git
docs/_build
node_modules
test_data
light
config.json
*.mbtiles
*
!src
!public
!package.json
!package-lock.json
!docker-entrypoint.sh
73 changes: 49 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
FROM node:10-stretch
FROM node:10-buster AS builder

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qq update \
&& apt-get -y --no-install-recommends install \
apt-transport-https \
curl \
unzip \
build-essential \
python \
libcairo2-dev \
libgles2-mesa-dev \
libgbm-dev \
libllvm7 \
libprotobuf-dev \
&& apt-get -y --purge autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY . /usr/src/app

ENV NODE_ENV="production"

RUN cd /usr/src/app && npm install --production


FROM node:10-buster-slim AS final

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qq update \
&& apt-get -y --no-install-recommends install \
libgles2-mesa \
libegl1 \
xvfb \
xauth \
&& apt-get -y --purge autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/src/app /app

ENV NODE_ENV="production"
ENV CHOKIDAR_USEPOLLING=1
ENV CHOKIDAR_INTERVAL=500

VOLUME /data
WORKDIR /data
EXPOSE 80
ENTRYPOINT ["/bin/bash", "/usr/src/app/run.sh"]

RUN apt-get -qq update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install \
apt-transport-https \
curl \
unzip \
build-essential \
python \
libcairo2-dev \
libgles2-mesa-dev \
libgbm-dev \
libllvm3.9 \
libprotobuf-dev \
libxxf86vm-dev \
xvfb \
x11-utils \
&& apt-get clean

RUN mkdir -p /usr/src/app
COPY / /usr/src/app
RUN cd /usr/src/app && npm install --production

EXPOSE 8000

USER node:node

ENTRYPOINT ["/app/docker-entrypoint.sh"]

CMD ["-p", "8000"]
23 changes: 23 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -e

handle() {
SIGNAL=$(( $? - 128 ))
echo "Caught signal ${SIGNAL}, stopping gracefully"
kill -s ${SIGNAL} $(pidof node) 2>/dev/null
}

trap handle INT TERM

if ! which -- "${1}"; then
# first arg is not an executable
xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /app/ "$@" &
# Wait exits immediately on signals which have traps set. Store return value and wait
# again for all jobs to actually complete before continuing.
wait $! || RETVAL=$?
wait
exit ${RETVAL}
fi

exec "$@"

0 comments on commit 51baa9b

Please sign in to comment.