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

Commit

Permalink
Add support for env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Feb 22, 2014
1 parent c9b86ce commit 9b1c684
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions resources/templates/Dockerfile-travis.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{% extends "Dockerfile.twig" %}

{% block env %}
{% for key,value in env %}
ENV {{ key }} {{ value }}
{% endfor %}
{% endblock %}

{% block before_install %}
RUN /bin/bash -c -l "cd $WORKDIR{% for line in before_install %} && {{ line|replace({"$": "\$", '"': '\"'}) }}{% endfor %}"
{% endblock %}
Expand Down
3 changes: 3 additions & 0 deletions resources/templates/Dockerfile.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ FROM jolicode/base

ENV WORKDIR $HOME/project
ADD . $WORKDIR
WORKDIR $WORKDIR

{% block env %}{% endblock %}

{% block before_install %}{% endblock %}

Expand Down
15 changes: 14 additions & 1 deletion src/Joli/JoliCi/BuildStrategy/TravisCiBuildStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ class TravisCiBuildStrategy implements BuildStrategyInterface
'install' => array('composer install'),
'before_script' => array(),
'script' => array('phpunit'),
'env' => array()
),
'ruby' => array(
'before_install' => array(),
'install' => array('bundle install'),
'before_script' => array(),
'script' => array('bundle exec rake'),
'env' => array()
),
'node_js' => array(
'before_install' => array(),
'install' => array('npm install'),
'before_script' => array(),
'script' => array('npm test'),
'env' => array()
),
);

Expand Down Expand Up @@ -86,13 +89,23 @@ public function createBuilds($directory)
$versionKey = isset($this->languageVersionKeyMapping[$language]) ? $this->languageVersionKeyMapping[$language] : $language;
$buildRoot = $this->buildPath.DIRECTORY_SEPARATOR.uniqid();

$envFromConfig = $this->getConfigValue($config, $language, "env");
$envs = array();

foreach ($envFromConfig as $env) {
list($key, $value) = explode("=", $env);
$envs[$key] = $value;
}

foreach ($config[$versionKey] as $version) {

$this->builder->setTemplateName(sprintf("%s/Dockerfile-%s.twig", $language, $version));
$this->builder->setVariables(array(
'before_install' => $this->getConfigValue($config, $language, 'before_install'),
'install' => $this->getConfigValue($config, $language, 'install'),
'before_script' => $this->getConfigValue($config, $language, 'before_script'),
'script' => $this->getConfigValue($config, $language, 'script')
'script' => $this->getConfigValue($config, $language, 'script'),
'env' => $envs
));

$buildName = sprintf("%s-%s", $language, $version);
Expand Down

0 comments on commit 9b1c684

Please sign in to comment.