diff --git a/Dockerfile b/Dockerfile index 63957f9..199400a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM alpine:3.5 MAINTAINER Julien Del-Piccolo ARG BRANCH="master" ARG COMMIT="" +ENV SSPKS_BRANCH=${BRANCH} +ENV SSPKS_COMMIT=${COMMIT} LABEL branch=${BRANCH} LABEL commit=${COMMIT} @@ -25,6 +27,7 @@ RUN echo "BRANCH: ${BRANCH}" \ && rm -rf /var/cache/apk/* \ && mkdir /run/apache2 \ && sed -i 's/Listen 80/Listen 8080/' /etc/apache2/httpd.conf \ + && sed -i 's/^variables_order = "GPCS"/variables_order = "EGPCS"/' /etc/php5/php.ini \ && ln -sf /dev/stdout /var/log/apache2/access.log \ && ln -sf /dev/stderr /var/log/apache2/error.log diff --git a/hooks/build b/hooks/build index 58f9708..d8db73f 100755 --- a/hooks/build +++ b/hooks/build @@ -8,8 +8,4 @@ echo "DOCKER_REPO: ${DOCKER_REPO}" echo "DOCKER_TAG: ${DOCKER_TAG}" echo "IMAGE_NAME: ${IMAGE_NAME}" -if [ -z "${DOCKER_TAG}" ]; then - docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) --build-arg=BRANCH=${SOURCE_BRANCH} -t $IMAGE_NAME . -else - docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) --build-arg=BRANCH=${DOCKER_TAG} -t $IMAGE_NAME . -fi +docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) --build-arg=BRANCH=${SOURCE_BRANCH} -t $IMAGE_NAME . \ No newline at end of file diff --git a/lib/SSpkS/Config.php b/lib/SSpkS/Config.php index 2cf9850..69fb2e5 100644 --- a/lib/SSpkS/Config.php +++ b/lib/SSpkS/Config.php @@ -15,6 +15,8 @@ * @property string basePath Path to site root (where index.php is located) * @property string baseUrl URL to site root (where index.php is located) * @property string baseUrlRelative Relative URL to site root (without scheme or hostname) + * @property string SSPKS_COMMIT current commit hash taken from ENV variables + * @property string SSPKS_BRANCH current branch taken from ENV variables */ class Config implements \Iterator { @@ -39,10 +41,46 @@ public function __construct($basePath, $cfgFile = 'conf/sspks.yaml') } catch (ParseException $e) { throw new \Exception($e->getMessage()); } + + /** Init variables that are not actual config variables */ + $config['SSPKS_COMMIT'] = ''; + $config['SSPKS_BRANCH'] = ''; + + /** Override config values with environment variables if present */ + if ($this->envVarIsNotEmpty('SSPKS_COMMIT')) { + $config['SSPKS_COMMIT'] = $_ENV['SSPKS_COMMIT']; + } + + if ($this->envVarIsNotEmpty('SSPKS_BRANCH')) { + $config['SSPKS_BRANCH'] = $_ENV['SSPKS_BRANCH']; + } + + if ($this->envVarIsNotEmpty('SSPKS_SITE_NAME')) { + $config['site']['name'] = $_ENV['SSPKS_SITE_NAME']; + } + + if ($this->envVarIsNotEmpty('SSPKS_SITE_THEME')) { + $config['site']['theme'] = $_ENV['SSPKS_SITE_THEME']; + } + + if ($this->envVarIsNotEmpty('SSPKS_SITE_REDIRECTINDEX')) { + $config['site']['redirectindex'] = $_ENV['SSPKS_SITE_REDIRECTINDEX']; + } $this->config = $config; $this->config['basePath'] = $this->basePath; } + + /** + * Checks wether an env variable exists and is not an empty string. + * + * @param string $name Name of requested environment variable. + * @return boolean value. + */ + public function envVarIsNotEmpty($name) + { + return (array_key_exists($name, $_ENV) && $_ENV[$name]); + } /** * Getter magic method. diff --git a/lib/SSpkS/Output/HtmlOutput.php b/lib/SSpkS/Output/HtmlOutput.php index a38d576..89ad832 100644 --- a/lib/SSpkS/Output/HtmlOutput.php +++ b/lib/SSpkS/Output/HtmlOutput.php @@ -31,13 +31,22 @@ public function __construct(\SSpkS\Config $config) $this->setVariable('baseUrlRelative', $this->config->baseUrlRelative); $this->setVariable('themeUrl', $this->config->baseUrlRelative . $this->config->paths['themes'] . $this->config->site['theme'] . '/'); $this->setVariable('requestUri', $_SERVER['REQUEST_URI']); + $this->setVariable('commitHash', $this->config->SSPKS_COMMIT); + $this->setVariable('branch', $this->config->SSPKS_BRANCH); } + /** + * @param string $name + * @param mixed $value + */ public function setVariable($name, $value) { $this->tplVars[$name] = $value; } + /** + * @param string $tplName + */ public function setTemplate($tplName) { $this->template = $tplName; diff --git a/themes/material/templates/partials/html_tail.mustache b/themes/material/templates/partials/html_tail.mustache index f2ec59b..af06abe 100644 --- a/themes/material/templates/partials/html_tail.mustache +++ b/themes/material/templates/partials/html_tail.mustache @@ -6,6 +6,18 @@
  • Source on GitHub
  • +{{# branch }} + + +{{/ branch }}