diff --git a/.dockerignore b/.dockerignore index a125f80..6d3272b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,5 @@ .npmignore cloud-config.yaml Dockerfile -run-dev-container \ No newline at end of file +run-dev-container +build-docker-image diff --git a/Dockerfile b/Dockerfile index 6ec95c7..d8aac2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,11 +83,16 @@ COPY . /src RUN npm install -g /src +# link certbot renewal hook to reload nginx +RUN mkdir -p /etc/letsencrypt/renewal-hooks/deploy \ + && ln -s /src/bin/reload-nginx /etc/letsencrypt/renewal-hooks/deploy/01-reload-nginx + + # setup and expose emergence RUN mkdir -p /emergence EXPOSE 22 80 3306 9083 ENV MYSQL_HOME=/emergence/services/etc -VOLUME ["/emergence"] +VOLUME ["/emergence", "/etc/letsencrypt"] # setup entrypoint diff --git a/bin/reload-nginx b/bin/reload-nginx new file mode 100755 index 0000000..df912e2 --- /dev/null +++ b/bin/reload-nginx @@ -0,0 +1,3 @@ +#!/bin/bash -e + +/usr/sbin/nginx -c /emergence/services/etc/nginx.conf -s reload diff --git a/bin/resolve-site b/bin/resolve-site index 1c8be6e..ee98cca 100755 --- a/bin/resolve-site +++ b/bin/resolve-site @@ -28,6 +28,8 @@ UNDERSCORE="$DIR/../node_modules/.bin/underscore" # search sites pushd /emergence/sites > /dev/null for SITE_DIR in `find . -maxdepth 1 ! -path . -type d`; do + [ -f "${SITE_DIR}/site.json" ] || continue + SITE_HANDLE="$(basename ${SITE_DIR})" SITE_HOSTNAMES="$(sudo cat ${SITE_DIR}/site.json | $UNDERSCORE process '(data.hostnames||[]).concat([data.primary_hostname]).filter(x=>x)' --outfmt text)" diff --git a/package-lock.json b/package-lock.json index e597869..6fea852 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,12 @@ { "name": "emergence", - "version": "1.1.0", + "version": "1.1.5", "lockfileVersion": 1, "requires": true, "dependencies": { "JSONSelect": { "version": "0.4.0", + "resolved": false, "integrity": "sha1-oI7cxn6z/L6Z7WMIVTRKDPKCu40=", "optional": true }, @@ -79,6 +80,7 @@ }, "coffee-script": { "version": "1.12.7", + "resolved": false, "integrity": "sha1-wF2uDLeVkdBbMHCoQzqYyaiczFM=", "optional": true }, @@ -420,6 +422,7 @@ }, "msgpack": { "version": "1.0.2", + "resolved": false, "integrity": "sha1-kj4sXP+mXIQY6bIo0RJHk5acQpw=", "optional": true, "requires": { @@ -451,6 +454,7 @@ }, "nan": { "version": "2.4.0", + "resolved": false, "integrity": "sha1-+zxZ1F/k7/4hXwuJD4rfbrMtIjI=", "optional": true }, diff --git a/package.json b/package.json index 989f716..552f86e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "emergence", "preferGlobal": true, - "version": "1.1.3", + "version": "1.1.5", "license": "MIT", "dependencies": { "hostile": "^1.3.x", diff --git a/php-bootstrap/lib/DB.class.php b/php-bootstrap/lib/DB.class.php index aa023f9..9804550 100644 --- a/php-bootstrap/lib/DB.class.php +++ b/php-bootstrap/lib/DB.class.php @@ -494,9 +494,19 @@ public static function syncTimezone() return; } + $timezoneTestResult = DB::oneValue('SELECT CONVERT_TZ("2007-03-11 3:00:00", "US/Eastern", "US/Central")'); + + if ($timezoneTestResult == '2007-03-11 01:00:00') { + // MySQL server support named timezones + $mysqlTimezone = date_default_timezone_get(); + } else { + // use static timezone offset because MySQL doesn't have timezone tables loaded + $mysqlTimezone = date('P'); + } + self::nonQuery( 'SET time_zone = "%s"', - self::escape(date('P')) + self::escape($mysqlTimezone) ); } diff --git a/php-bootstrap/lib/Emergence_FS.class.php b/php-bootstrap/lib/Emergence_FS.class.php index b90f1dc..c9b5f7d 100644 --- a/php-bootstrap/lib/Emergence_FS.class.php +++ b/php-bootstrap/lib/Emergence_FS.class.php @@ -688,7 +688,7 @@ public static function findFiles($filename, $useRegexp = false, $scope = null, $ } $fileResults = DB::query( - 'SELECT f2.* FROM (SELECT MAX(f1.ID) AS ID FROM `%1$s` f1 WHERE CollectionID IN (%2$s) AND Status != "Phantom" GROUP BY f1.Handle) AS lastestFiles LEFT JOIN `%1$s` f2 ON (f2.ID = lastestFiles.ID) WHERE f2.Status != "Deleted" AND f2.Handle %3$s "%4$s"' + 'SELECT f2.* FROM (SELECT MAX(f1.ID) AS ID FROM `%1$s` f1 WHERE CollectionID IN (%2$s) AND Status != "Phantom" GROUP BY f1.CollectionID, f1.Handle) AS lastestFiles LEFT JOIN `%1$s` f2 ON (f2.ID = lastestFiles.ID) WHERE f2.Status != "Deleted" AND f2.Handle %3$s "%4$s"' ,array( SiteFile::$tableName ,$collectionsQuery diff --git a/php-bootstrap/lib/Site.class.php b/php-bootstrap/lib/Site.class.php index 3775d25..7a402b6 100644 --- a/php-bootstrap/lib/Site.class.php +++ b/php-bootstrap/lib/Site.class.php @@ -325,12 +325,20 @@ public static function getRequestPathResult($path) public static function executeScript(SiteFile $_SCRIPT_NODE, $_SCRIPT_EXIT = true) { // create session - if ( - empty($GLOBALS['Session']) && - static::$autoCreateSession && - !in_array(implode('/', static::$resolvedPath), static::$skipSessionPaths) - ) { - $GLOBALS['Session'] = UserSession::getFromRequest(); + if (empty($GLOBALS['Session']) && static::$autoCreateSession) { + $resolvedPath = implode('/', static::$resolvedPath) . '/'; + + $createSession = true; + foreach (static::$skipSessionPaths as $skipSessionPath) { + if (strpos($resolvedPath, $skipSessionPath) === 0) { + $createSession = false; + break; + } + } + + if ($createSession) { + $GLOBALS['Session'] = UserSession::getFromRequest(); + } } if (extension_loaded('newrelic')) {