Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Add Docker support #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 add-docker-support
RUN npm install && npm install [email protected] --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"]
6 changes: 5 additions & 1 deletion bin/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions bin/lib/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions bin/lib/ensure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down