12 Commits

Author SHA1 Message Date
asif 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
asif ba7d33943e fix(entrypoint): fix shell action 2021-07-22 18:44:29 -06:00
asif f30e22b333 build(dockerfile): temp comment labels for faster build 2021-07-22 18:44:00 -06:00
asif 9ee212fcef fix(dockerfile): fix minor bugs stopping build 2021-07-22 17:38:43 -06:00
asif 1ca3b48d0d refactor(dockerfile): remove old dockerfile
- delete non-tls version of dockerfile
- set internal version as build-arg
2021-07-22 17:28:21 -06:00
asif d864231db1 refactor(dockerfile): cleanup permissions
- set proper permissions for server script and entrypoint
2021-07-22 17:21:55 -06:00
asif 7828ff2125 struct(dockerfile): add openssl 2021-07-22 17:16:15 -06:00
asif 0fbd3303e4 struct(entrypoint): skeleton entrypoint script
- basic operation flow with placeholder functions
- implement server and shell launch
- allow commands to pass to shell
- update Dockerfile to load entrypoint only
- update Dockerfile to set permissions for certs directory
2021-07-22 17:15:31 -06:00
asif e82fad68ac feature(server invocation script): 2021-07-22 16:43:17 -06:00
asif cc10ee2241 struct(Dockerfile): align with previous customizations 2021-07-22 16:36:36 -06:00
asif 9e9abe945f struct(dockerfile): initial build skeleton 2021-07-22 16:22:40 -06:00
asif f21510cdf7 chore(git): update gitignore, gitattributes 2021-07-22 16:22:05 -06:00
6 changed files with 289 additions and 80 deletions
+19 -9
View File
@@ -4,9 +4,6 @@
# https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/ # https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
* text=auto * text=auto
# JetBrains: Do not touch line endings, but show diff
.idea/** -text
# #
# The above will handle all files NOT found below # The above will handle all files NOT found below
# #
@@ -23,7 +20,7 @@
*.PDF diff=astextplain *.PDF diff=astextplain
*.rtf diff=astextplain *.rtf diff=astextplain
*.RTF diff=astextplain *.RTF diff=astextplain
*.md text *.md text diff=markdown
*.tex text diff=tex *.tex text diff=tex
*.adoc text *.adoc text
*.textile text *.textile text
@@ -33,6 +30,7 @@
*.tsv text *.tsv text
*.txt text *.txt text
*.sql text *.sql text
*.ps1 text eol=crlf
# Graphics # Graphics
*.png binary *.png binary
@@ -56,7 +54,22 @@
# These are explicitly windows files and should use crlf # These are explicitly windows files and should use crlf
*.bat text eol=crlf *.bat text eol=crlf
*.cmd text eol=crlf *.cmd text eol=crlf
*.ps1 text eol=crlf
# web frontend stack -- force LF so SRI hashes are always correct
*.html text eol=lf
*.htm text eol=lf
*.css text eol=lf
*.min.css text eol=lf
*.js text eol=lf
*.min.js text eol=lf
# Visual Studio projects (Rider also)
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Serialisation # Serialisation
*.json text *.json text
@@ -72,9 +85,6 @@
*.tgz binary *.tgz binary
*.zip binary *.zip binary
# Docker build files
Dockerfile text eol=lf
# Text files where line endings should be preserved # Text files where line endings should be preserved
*.patch -text *.patch -text
@@ -85,5 +95,5 @@ Dockerfile text eol=lf
.gitattributes export-ignore .gitattributes export-ignore
.gitignore export-ignore .gitignore export-ignore
.gitkeep export-ignore .gitkeep export-ignore
.vscode export-ignore
.idea export-ignore .idea export-ignore
.vscode export-ignore
+71 -9
View File
@@ -1,10 +1,72 @@
.vscode/* ### JetBrains template
!.vscode/settings.json # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
!.vscode/tasks.json # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/numbered-bookmarks.json
*.code-workspace
# Local History for Visual Studio Code # User-specific stuff
.history/ .idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
-58
View File
@@ -1,58 +0,0 @@
#
# nodejs with livereload
#
# allow dynamic build by specifying base image as build arg
ARG NODE_TAG="16.4.2-alpine3.14"
FROM node:${NODE_TAG}
# change user id of node user
ARG NODE_UID=9999
RUN deluser --remove-home node \
&& addgroup -g ${NODE_UID} -S node \
&& adduser -G node -S -u ${NODE_UID} node
# add tini, timezone support
RUN apk --update --no-cache add tzdata tini
# labels
LABEL org.opencontainers.image.authors="Asif Bacchus <asif@asifbacchus.dev>"
LABEL org.opencontainers.image.title="livereload npm"
LABEL org.opencontainers.image.description="Dockerized npm livereload running under limited user account. Environment variables allow specifying files to watch/exclude and notification delay."
LABEL org.opencontainers.image.url="https://git.asifbacchus.dev/ab-docker/livereload"
LABEL org.opencontainers.image.documentation="https://git.asifbacchus.dev/ab-docker/livereload/raw/branch/master/README.md"
LABEL org.opencontainers.image.source="https://git.asifbacchus.dev/ab-docker/livereload.git"
# create default volume in case user forgets to map one
VOLUME [ "/var/watch" ]
# expose port
EXPOSE 35729
# default environment variables
ENV TZ=Etc/UTC
ENV NODE_ENV=production
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
ENV EXT="html,xml,css,js,jsx,ts,tsx,php,py"
ENV EXCLUDE=".git/,.svn/"
ENV DELAY=500
# install livereload for node user
USER node
WORKDIR /home/node
RUN mkdir -p .npm-global/bin .npm-global/lib \
&& npm install -g livereload
# run node via tini by default
ENTRYPOINT [ "/sbin/tini", "--" ]
CMD livereload /var/watch --debug --exts $EXT --exclusions $EXCLUDE -u true --wait $DELAY
# set build timestamp and version labels
ARG BUILD_DATE
LABEL org.opencontainers.image.version="16.4.2"
LABEL org.opencontainers.image.vendor="nodeJS"
LABEL dev.asifbacchus.image.name="livereload npm"
LABEL dev.asifbacchus.image.version="1.2"
LABEL org.opencontainers.image.created=${BUILD_DATE}
#EOF
+73
View File
@@ -0,0 +1,73 @@
# LiveReload-npm server supporting SSL/TLS
# allow dynamic building by specifying base image elements as build-args
ARG NODE_VERSION=16
ARG ALPINE_VERSION=3.14
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION}
# create new node user with set id from build-arg
ARG NODE_UID=9999
RUN deluser --remove-home node \
&& addgroup -g ${NODE_UID} -S node \
&& adduser -G node -S -u ${NODE_UID} node
# create default volumes in-case user forgets, expose default port
VOLUME [ "/watch", "/certs" ]
EXPOSE 35729
# add tini, timezone support and create certificate directories
RUN apk --update --no-cache add \
tini \
tzdata \
openssl
# labels
LABEL org.opencontainers.image.authors="Asif Bacchus <asif@asifbacchus.dev>"
LABEL org.opencontainers.image.title="livereload npm"
LABEL org.opencontainers.image.description="Dockerized npm livereload supporting TLS and running under limited user account. Environment variables allow specifying files to watch/exclude and notification delay."
LABEL org.opencontainers.image.url="https://git.asifbacchus.dev/ab-docker/livereload"
LABEL org.opencontainers.image.documentation="https://git.asifbacchus.dev/ab-docker/livereload/raw/branch/master/README.md"
LABEL org.opencontainers.image.source="https://git.asifbacchus.dev/ab-docker/livereload.git"
# default environment variables
ENV NODE_ENV=production
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV TZ="Etc/UTC"
ENV LR_PORT=35729
ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py"
ENV LR_EXCLUDE=".git/,.svn/,.vscode/,.idea/"
ENV LR_DELAY=500
# 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 \
&& npm config set fund false \
&& npm config set update-notifier false \
&& npm install livereload --save
# 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
# 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
+97
View File
@@ -0,0 +1,97 @@
#!/bin/sh
#
# entrypoint script for livereload-tls-npm container
#
# functions
certificateGenerateNew() {
printf "\nGenerating new self-signed certificate:\n"
printf "Exporting new certificate:\n"
exit 0
}
certificateShow() {
printf "\nCurrently loaded certificate:\n"
exit 0
}
certificateExport() {
printf "\nExporting currently loaded certificate:\n"
exit 0
}
# default variable values
doCertExport=0
doCertNew=0
doCertShow=0
doServer=0
doShell=0
# process action parameter
case "$1" in
listen | server | run | start)
doServer=1
;;
shell)
doShell=1
;;
new-cert)
doCertNew=1
;;
show-cert)
doCertShow=1
;;
export-cert)
doCertExport=1
;;
*)
# 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\n\n"
exit 1
;;
esac
# action: run server
if [ "$doServer" -eq 1 ]; then
exec node livereload.js
exit "$?"
fi
# action: drop to shell
if [ "$doShell" -eq 1 ]; then
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
# action: generate new self-signed certificate
if [ "$doCertNew" -eq 1 ]; then certificateGenerateNew; fi
# action: show loaded certificate
if [ "$doCertShow" -eq 1 ]; then certificateShow; fi
# action: export loaded certificate
if [ "$doCertExport" -eq 1 ]; then certificateExport; fi
# failsafe exit - terminate with code 99: this code should never be executed!
exit 99
# exit codes:
# 0: normal exit, no errors
# 1: invalid or invalid parameter passed to script
# 50: certificate errors
# 51: unable to read certificate/chain
# 52: unable to read private key
# 55: unable to generate new certificate
# 56: unable to export certificate, likely write error
# 99: code error
#EOF
+25
View File
@@ -0,0 +1,25 @@
// implement node-livereload over an HTTPS connection
// load livereload module
let livereload = require('livereload');
// set createServer options
const https = require('https');
const fs = require('fs');
const options = {
https: {
cert: fs.readFileSync('/certs/fullchain.pem'),
key: fs.readFileSync('/certs/privkey.pem')
},
port: process.env.LR_PORT,
exts: process.env.LR_EXTS,
exclusions: process.env.LR_EXCLUDE,
usePolling: true,
delay: process.env.LR_DELAY
};
// start server
let server = livereload.createServer(options);
server.watch('/var/watch')
//#EOF