From 6e565e81edc2253d136cfd8dc5f88d7f6c54c1b4 Mon Sep 17 00:00:00 2001 From: alfonsomunozpomer Date: Tue, 29 Dec 2020 02:17:06 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Add=20serve=20command=20flag=20that=20doesn?= =?UTF-8?q?=E2=80=99t=20disable=20privileged=20ports=20for=20Docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add serve command flag that doesn’t disable privileged ports for Docker --- bin/commands/serve.js | 6 +++++- bin/lib/Help.js | 3 +++ bin/lib/ensure.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/commands/serve.js b/bin/commands/serve.js index fe06e0e..893f99b 100644 --- a/bin/commands/serve.js +++ b/bin/commands/serve.js @@ -20,6 +20,7 @@ const SYNC_TO = 'sync-to' const SYNC_FROM = 'sync-from' const LIVE_SYNC = 'live-sync' const SYNC_FOLDER_AND_CONTENTS = 'sync-folder-and-contents' +const DOCKER = 'docker' // This will only show errors in the access log (HTTP response codes 4xx and 5xx). const ACCESS_LOG_ERRORS_ONLY = 'access-log-errors-only' @@ -145,6 +146,9 @@ function serve (args) { const syncRequested = args.named[SYNC_TO] !== undefined const liveSync = args.named[LIVE_SYNC] + // Is Site.js running in a Docker container? + const docker = args.named[DOCKER] + // // Handle initial sync setup-related tasks. // @@ -186,7 +190,7 @@ function serve (args) { // Ensure privileged ports are disabled on Linux machines. // For details, see: https://source.small-tech.org/site.js/app/-/issues/169 - ensure.privilegedPortsAreDisabled() + ensure.privilegedPortsAreDisabled(docker) // Start a server and also sync if requested. tcpPortUsed.check(port) diff --git a/bin/lib/Help.js b/bin/lib/Help.js index dfd505c..2278e94 100644 --- a/bin/lib/Help.js +++ b/bin/lib/Help.js @@ -82,6 +82,8 @@ class Help { const optionAccessLogErrorsOnly = option('access-log-errors-only') const optionAccessLogDisable = option('access-log-disable') + const optionDocker = option('docker') + // Black right-pointing triangle (U+25B6) // (There are several similar unicode gylphs but this is the one that works well across // Linux, macOS, and Windows). @@ -150,6 +152,7 @@ class Help { ${optionSyncFrom}\t\t\t\tThe folder to sync from. ${optionLiveSync}\t\t\t\tWatch for changes and live sync them to a remote server. ${optionSyncFolderAndContents}\t\tSync local folder and contents (default is to sync the folder’s contents only). + ${optionDocker}\t\t\t\tSet when running in a Docker container (does not disable privileged ports). ${ this.systemdExists ? `For ${commandEnable} command: diff --git a/bin/lib/ensure.js b/bin/lib/ensure.js index 03d4455..1f30ef8 100644 --- a/bin/lib/ensure.js +++ b/bin/lib/ensure.js @@ -122,8 +122,8 @@ class Ensure { // execute, we carry it out every time. // // For more details, see: https://source.small-tech.org/site.js/app/-/issues/169 - privilegedPortsAreDisabled () { - if (os.platform() === 'linux') { + privilegedPortsAreDisabled (docker) { + if (os.platform() === 'linux' && !docker) { try { Site.logAppNameAndVersion() From 3965b9d57a896482f4f5870b643cc5607e74d900 Mon Sep 17 00:00:00 2001 From: alfonsomunozpomer Date: Tue, 29 Dec 2020 02:37:55 +0000 Subject: [PATCH 2/3] Add Dockerfile that builds Site.js and serves folder /var/www/html --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..430df2d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:12.16.2-buster-slim + +EXPOSE 80 +EXPOSE 443 + +RUN apt-get update && apt-get -y install git libnss3-tools + +RUN git clone https://github.com/alfonsomunozpomer/site.js.git +WORKDIR /site.js +RUN git checkout docker +RUN npm install && npm install nexe@3.3.7 --save-dev +RUN npm run build && cp dist/release/linux/`ls -1t dist/release/linux | head -1`/site /usr/local/bin + +VOLUME /site.js/dist +VOLUME /var/www/html + +ENTRYPOINT ["site"] +CMD ["serve", "/var/www/html", "--docker"] From 10893e3ed65ccd67e4e490ce739a6e52bbac5c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Mu=C3=B1oz-Pomer=20Fuentes?= Date: Thu, 31 Dec 2020 16:49:14 +0000 Subject: [PATCH 3/3] Fix branch name from forked repo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 430df2d..0419b56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && apt-get -y install git libnss3-tools RUN git clone https://github.com/alfonsomunozpomer/site.js.git WORKDIR /site.js -RUN git checkout docker +RUN git checkout add-docker-support RUN npm install && npm install nexe@3.3.7 --save-dev RUN npm run build && cp dist/release/linux/`ls -1t dist/release/linux | head -1`/site /usr/local/bin