Skip to content

Instantly share code, notes, and snippets.

@chrisjensen
Last active January 21, 2021 02:39
Show Gist options
  • Save chrisjensen/7fab79cf0533d42324ca21775e1c4164 to your computer and use it in GitHub Desktop.
Save chrisjensen/7fab79cf0533d42324ca21775e1c4164 to your computer and use it in GitHub Desktop.
NGINX + Node Docker on Fly
FROM nginx:1.15.7-alpine
WORKDIR /home/app
ENV TINI_VERSION v0.18.0
ENV TINI_SHA "50a5bb62e3c4fdfb442da6d1530abb2b6afacc24"
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
RUN echo "$TINI_SHA /tini" | sha1sum -c -
RUN chmod +x /tini
RUN apk update && apk upgrade && \
apk add --no-cache bash openssh
RUN apk add --no-cache --repository http://nl.alpinelinux.org/alpine/edge/main libuv \
&& apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.8/main/ nodejs=8.14.0-r0 npm \
&& echo "NodeJS Version:" "$(node -v)" \
&& echo "NPM Version:" "$(npm -v)"
RUN npm config set unsafe-perm true
RUN npm install nodemon -g
# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
ADD ./package.json ./package-lock.json /tmp/
WORKDIR /tmp
RUN npm install --production
RUN mkdir -p /home/app && cp -a /tmp/node_modules /home/app/
# From here we load our application's code in, therefore the previous docker
# "layer" thats been cached will be used if possible
WORKDIR /home/app
COPY . /home/app
RUN mkdir -p /data/nginx/cache
# This is just a test, not the final variables used in the config
# This just here to fail a build and deploy fast if there's a config problem
# so we put the file in a different location to be sure we don't mix up
# **NOTE**: If you update the environment variables, don't forget to update them
# in ./launch.sh too which is what's used in production
RUN RESOLVER=127.0.0.11 envsubst '${RESOLVER}' < /home/app/nginx.conf > /home/app/nginx-test.conf
RUN cat /home/app/nginx-test.conf
RUN nginx -t -c /home/app/nginx-test.conf
CMD ["/tini", "--", "./launch.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment