2021-07-23 18:36:14 -06:00
# node-livereload server supporting SSL/TLS
2021-07-22 16:36:36 -06:00
# allow dynamic building by specifying base image elements as build-args
2021-07-22 16:22:40 -06:00
ARG NODE_VERSION = 16
ARG ALPINE_VERSION = 3 .14
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION}
2021-07-28 04:41:28 -06:00
ARG NODE_VERSION
ARG ALPINE_VERSION
2021-07-22 16:22:40 -06:00
2021-07-24 16:21:07 -06:00
# create new node user with set UID and GID from build-args and create volume directories
2021-07-22 16:36:36 -06:00
ARG NODE_UID = 9999
2021-07-24 16:21:07 -06:00
ARG NODE_GID = 9999
2021-07-22 16:36:36 -06:00
RUN deluser --remove-home node \
2021-07-24 16:21:07 -06:00
&& addgroup -g ${ NODE_GID } -S node \
2021-07-23 17:19:58 -06:00
&& adduser -G node -S -u ${ NODE_UID } node \
&& mkdir /watch /certs \
&& chown root:node /certs \
&& chmod 770 /certs
2021-07-22 16:36:36 -06:00
2021-07-22 17:15:31 -06:00
# create default volumes in-case user forgets, expose default port
2021-07-22 18:45:29 -06:00
VOLUME [ "/watch" , "/certs" ]
2021-07-22 17:15:31 -06:00
EXPOSE 35729
2021-07-22 16:36:36 -06:00
# add tini, timezone support and create certificate directories
2021-07-22 16:22:40 -06:00
RUN apk --update --no-cache add \
2021-07-28 03:50:03 -06:00
tini \
tzdata \
openssl \
&& apk --update --no-cache upgrade
2021-07-22 16:22:40 -06:00
2021-07-22 16:36:36 -06:00
# labels
2021-07-28 04:41:28 -06:00
MAINTAINER Asif Bacchus <asif@asifbacchus.dev>
LABEL maintainer = "Asif Bacchus <asif@asifbacchus.dev>"
2021-07-30 11:53:41 -06:00
LABEL dev.asifbacchus.docker.internalName= "ab-livereload"
2021-07-22 16:36:36 -06:00
LABEL org.opencontainers.image.authors= "Asif Bacchus <asif@asifbacchus.dev>"
2021-07-23 18:36:14 -06:00
LABEL org.opencontainers.image.description= "Dockerized node-livereload supporting TLS and running under limited user account. Environment variables allow specifying files to watch/exclude and notification delay."
2021-07-30 11:53:41 -06:00
LABEL org.opencontainers.image.documentation= "https://git.asifbacchus.dev/ab-docker/ab-livereload/raw/branch/master/README.md"
LABEL org.opencontainers.image.source= "https://git.asifbacchus.dev/ab-docker/ab-livereload.git"
LABEL org.opencontainers.image.title= "ab-livereload"
LABEL org.opencontainers.image.url= "https://git.asifbacchus.dev/ab-docker/ab-livereload"
LABEL org.opencontainers.image.vendor= "Asif Bacchus <asif@asifbacchus.dev>"
2021-07-22 16:36:36 -06:00
# default environment variables
2021-07-22 16:22:40 -06:00
ENV NODE_ENV = production
ENV NPM_CONFIG_PREFIX = /home/node/.npm-global
ENV PATH = /home/node/.npm-global/bin:$PATH
2021-07-22 16:36:36 -06:00
ENV TZ = "Etc/UTC"
ENV LR_PORT = 35729
ENV LR_EXTS = "html,xml,css,js,jsx,ts,tsx,php,py"
2021-07-28 03:51:56 -06:00
ENV LR_EXCLUDE = " .vscode/,.idea/,.tmp $,.swp $"
2021-07-22 16:36:36 -06:00
ENV LR_DELAY = 500
2021-07-22 21:21:59 -06:00
ENV LR_DEBUG = true
2021-07-23 13:31:01 -06:00
ENV LR_HTTPS = true
2021-07-23 17:19:58 -06:00
ENV CERT_HOSTNAME = ""
2021-07-22 16:22:40 -06:00
2021-07-24 03:01:01 -06:00
# install node-livereload and express as node user then switch back to root user
2021-07-22 16:22:40 -06:00
USER node
WORKDIR /home/node
2021-07-30 17:07:46 -06:00
COPY --chown= node:node [ "package.json" , "package-lock.json" , "/home/node/" ]
2021-07-22 16:22:40 -06:00
RUN mkdir -p .npm-global/bin .npm-global/lib \
2021-07-22 16:36:36 -06:00
&& npm config set fund false \
2021-07-22 16:22:40 -06:00
&& npm config set update-notifier false \
2021-07-30 11:53:41 -06:00
&& npm install --save
2021-07-30 17:07:46 -06:00
COPY --chown= node:node [ "ab-livereload.js" , "/home/node/" ]
2021-07-22 16:22:40 -06:00
2021-07-22 18:45:29 -06:00
# copy scripts and fix-up all permissions
USER root
2021-07-23 17:19:58 -06:00
COPY [ "selfsigned.cnf" , "/etc/selfsigned.cnf" ]
2021-07-22 18:45:29 -06:00
COPY [ "entrypoint.sh" , "/usr/local/bin/entrypoint.sh" ]
2021-07-30 11:53:41 -06:00
RUN chown node:node /home/node/* \
&& chmod 644 /home/node/package* /home/node/ab-livereload.js \
2021-07-23 17:19:58 -06:00
&& chmod 755 /usr/local/bin/entrypoint.sh \
&& chmod 644 /etc/selfsigned.cnf
2021-07-22 18:45:29 -06:00
2021-07-24 03:01:01 -06:00
HEALTHCHECK \
--interval= 10s \
--timeout= 5s \
--start-period= 60s \
--retries= 3 \
CMD wget --spider -T 3 -q localhost:3000/api/v1/health || exit 1
2021-07-22 18:45:29 -06:00
# switch to node user, run entrypoint script by default
USER node
WORKDIR /home/node
2021-07-22 17:15:31 -06:00
ENTRYPOINT [ "/sbin/tini" , "--" , "/usr/local/bin/entrypoint.sh" ]
2021-07-22 16:22:40 -06:00
2021-07-22 16:36:36 -06:00
# set build timestamp and version labels
2021-07-23 18:22:40 -06:00
ARG INTERNAL_VERSION
2021-07-28 04:41:28 -06:00
ARG GIT_COMMIT
2021-07-23 18:22:40 -06:00
ARG BUILD_DATE
2021-07-28 04:41:28 -06:00
LABEL org.opencontainers.image.version= " NODE= ${ NODE_VERSION } , node-livereload=0.9.3 "
LABEL dev.asifbacchus.docker.internalVersion= ${ INTERNAL_VERSION }
LABEL org.opencontainers.image.revision= ${ GIT_COMMIT }
2021-07-23 18:22:40 -06:00
LABEL org.opencontainers.image.created= ${ BUILD_DATE }
2021-07-22 16:36:36 -06:00
2021-07-22 16:22:40 -06:00
#EOF