Compare commits

...

3 Commits

Author SHA1 Message Date
2c3bcf27d7 refactor(dockerfile): change order for faster build
- move file copy to near end since scripts change often
2021-07-22 18:45:29 -06:00
ba7d33943e fix(entrypoint): fix shell action 2021-07-22 18:44:29 -06:00
f30e22b333 build(dockerfile): temp comment labels for faster build 2021-07-22 18:44:00 -06:00
2 changed files with 35 additions and 24 deletions

View File

@ -12,17 +12,14 @@ RUN deluser --remove-home node \
&& adduser -G node -S -u ${NODE_UID} node
# create default volumes in-case user forgets, expose default port
VOLUME [ "/var/watch", "/var/certs" ]
VOLUME [ "/watch", "/certs" ]
EXPOSE 35729
# add tini, timezone support and create certificate directories
RUN apk --update --no-cache add \
tini \
tzdata \
openssl \
&& chown node:node /var/certs \
&& chmod 700 /var/certs \
&& chmod +r /var/watch
openssl
# labels
LABEL org.opencontainers.image.authors="Asif Bacchus <asif@asifbacchus.dev>"
@ -42,12 +39,7 @@ ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py"
ENV LR_EXCLUDE=".git/,.svn/,.vscode/,.idea/"
ENV LR_DELAY=500
# copy scripts, cleanup permissions and install livereload npm
COPY [ "livereload.js", "/home/node/livereload.js" ]
COPY [ "entrypoint.sh", "/usr/local/bin/entrypoint.sh" ]
RUN chown node:node /home/node/livereload.js \
&& chmod 644 /home/node/livereload.js \
&& chmod 755 /usr/local/bin/entrypoint.sh
# install livereload npm as node user then switch back to root user
USER node
WORKDIR /home/node
RUN mkdir -p .npm-global/bin .npm-global/lib \
@ -55,16 +47,27 @@ RUN mkdir -p .npm-global/bin .npm-global/lib \
&& npm config set update-notifier false \
&& npm install livereload --save
# run entrypoint script by default
# copy scripts and fix-up all permissions
USER root
COPY [ "livereload.js", "/home/node/livereload.js" ]
COPY [ "entrypoint.sh", "/usr/local/bin/entrypoint.sh" ]
RUN chown node:node /home/node/livereload.js \
&& chmod 644 /home/node/livereload.js \
&& chmod 755 /usr/local/bin/entrypoint.sh
# switch to node user, run entrypoint script by default
USER node
WORKDIR /home/node
ENTRYPOINT [ "/sbin/tini", "--", "/usr/local/bin/entrypoint.sh" ]
# set build timestamp and version labels
ARG INTERNAL_VERSION
ARG BUILD_DATE
LABEL org.opencontainers.image.version="16.5.0, 0.9.3"
LABEL org.opencontainers.image.vendor="NODE.js, node-livereload"
LABEL dev.asifbacchus.image.name="livereload-tls-npm"
LABEL dev.asifbacchus.image.version=${INTERNAL_VERSION}
LABEL org.opencontainers.image.created=${BUILD_DATE}
# TODO: uncomment when done testing
#ARG INTERNAL_VERSION
#ARG BUILD_DATE
#LABEL org.opencontainers.image.version="16.5.0, 0.9.3"
#LABEL org.opencontainers.image.vendor="NODE.js, node-livereload"
#LABEL dev.asifbacchus.image.name="livereload-tls-npm"
#LABEL dev.asifbacchus.image.version=${INTERNAL_VERSION}
#LABEL org.opencontainers.image.created=${BUILD_DATE}
#EOF

View File

@ -33,8 +33,9 @@ case "$1" in
listen | server | run | start)
doServer=1
;;
shell) ;;
shell)
doShell=1
;;
new-cert)
doCertNew=1
;;
@ -47,20 +48,27 @@ export-cert)
*)
# invalid or unknown option
printf "\nUnknown action requested: %s\n" "$1"
printf "Valid actions: [listen | server | run | start] | shell | new-cert | show-cert | export-cert"
printf "Valid actions: [listen | server | run | start] | shell | new-cert | show-cert | export-cert\n\n"
exit 1
;;
esac
# action: run server
if [ "$doServer" -eq 1 ]; then
exec "node livereload.js"
exec node livereload.js
exit "$?"
fi
# action: drop to shell
if [ "$doShell" -eq 1 ]; then
exec /bin/sh "$@"
if [ -z "$2" ]; then
printf "\nExecuting interactive shell:\n"
exec /bin/sh
else
shift
printf "\nExecuting shell: '%s'\n" "$*"
exec /bin/sh -c "$*"
fi
exit "$?"
fi