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
2023-03-19 23:07:43 -06:00
ARG NODE_VERSION = 18
ARG ALPINE_VERSION = 3 .17
2022-02-26 21:59:05 -07:00
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} as builder
ARG NODE_VERSION
ARG ALPINE_VERSION
# install node dependences
WORKDIR /build
COPY [ "package.json" , "package-lock.json" , "./" ]
RUN npm ci --production
# final container
FROM alpine:${ALPINE_VERSION} as final
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
2022-02-26 21:59:05 -07:00
RUN addgroup -g ${ NODE_GID } -S node \
2021-07-23 17:19:58 -06:00
&& adduser -G node -S -u ${ NODE_UID } node \
2022-05-02 00:31:19 -06:00
&& mkdir /watch /watch2 /watch3 /watch4 /watch5 /certs \
2021-07-23 17:19:58 -06:00
&& chown root:node /certs \
&& chmod 770 /certs
2021-07-22 16:36:36 -06:00
2022-02-26 21:59:05 -07: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
2022-02-26 21:59:05 -07:00
# add tini, timezone support, nodejs 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 \
2022-02-26 21:59:05 -07:00
nodejs~${ NODE_VERSION } \
2021-07-28 03:50:03 -06:00
&& 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 17:18:39 -06:00
LABEL org.opencontainers.image.documentation= "https://git.asifbacchus.dev/ab-docker/ab-livereload/raw/branch/main/README.md"
2021-07-30 11:53:41 -06:00
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
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
2022-02-26 21:59:05 -07:00
# set-up application and copy dependencies from builder
2021-07-22 16:22:40 -06:00
WORKDIR /home/node
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" ]
2022-02-26 21:59:05 -07:00
COPY --chown= node:node [ "ab-livereload.js" , "/home/node/" ]
COPY --from= builder [ "/build/node_modules" , "/home/node/node_modules" ]
RUN chown -R node:node /home/node/* \
&& chmod 644 /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-30 17:10:37 -06:00
ENTRYPOINT [ "/sbin/tini" , "-e" , "143" , "--" , "/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