Permalink
Browse files

Add version info from env variables (#41)

Override from ENV variables:

  - site.name (SSPKS_SITE_NAME)
  - site.theme (SSPKS_SITE_THEME)
  - site.redirectindex (SSPKS_SITE_REDIRECTINDEX)
  
And please Scrutinizer.
  • Loading branch information...
jdel committed Aug 15, 2017
1 parent 842060e commit a5ad86e952e0a750d18c42292af618eeb2cf7a1f
Showing with 63 additions and 5 deletions.
  1. +3 −0 Dockerfile
  2. +1 −5 hooks/build
  3. +38 −0 lib/SSpkS/Config.php
  4. +9 −0 lib/SSpkS/Output/HtmlOutput.php
  5. +12 −0 themes/material/templates/partials/html_tail.mustache
View
@@ -2,6 +2,8 @@ FROM alpine:3.5
MAINTAINER Julien Del-Piccolo <julien@del-piccolo.com>
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
View
@@ -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 .
View
@@ -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.
@@ -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;
@@ -6,6 +6,18 @@
<li><a href="https://github.com/jdel/sspks">Source on GitHub</a></li>
</ul>
</div>
{{# branch }}
<div class="mdl-mini-footer--right-section">
<div class="mdl-logo">Version</div>
<ul class="mdl-mini-footer--link-list">
<li><a href="https://github.com/jdel/sspks/tree/{{ branch }}">{{ branch }}</a></li>
{{# commitHash }}
<li><a href="https://github.com/jdel/sspks/commit/{{ commitHash }}">{{ commitHash }}</a></li>
{{/ commitHash }}
</ul>
</div>
</div>
{{/ branch }}
</footer>
</main>
</div>

0 comments on commit a5ad86e

Please sign in to comment.