[beast] TRAVIS: applyenv: allow importing arbitrary environment variables into Dockerfile
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast] TRAVIS: applyenv: allow importing arbitrary environment variables into Dockerfile
- Date: Mon, 21 Mar 2016 20:38:22 +0000 (UTC)
commit 09ff5d25d316343d1af5616dfcc611eb09b67794
Author: Tim Janik <timj gnu org>
Date: Mon Mar 21 20:58:03 2016 +0100
TRAVIS: applyenv: allow importing arbitrary environment variables into Dockerfile
We use applyenv to pass build context into Dockerfile. In particular, this makes
the FROM distribution configurable and transports build settings like http_proxy
or the travis job number into the docker command context.
Signed-off-by: Tim Janik <timj gnu org>
.travis.docker | 7 +++++--
.travis.yml | 9 ++++-----
buildtool.sh | 30 +++++++++++++++++++++++++++---
3 files changed, 36 insertions(+), 10 deletions(-)
---
diff --git a/.travis.docker b/.travis.docker
index fe7b708..b31903d 100644
--- a/.travis.docker
+++ b/.travis.docker
@@ -2,10 +2,13 @@
# Pick distribution to start from
FROM @XFROM@
-
-# Maintainer information and contact information
MAINTAINER Tim Janik <timj gnu org>
+
+# Carry over enviroment variables
ENV EMAIL beast gnome org
+ENV TRAVIS_JOB_NUMBER "@TRAVIS_JOB_NUMBER@"
+ENV http_proxy "@http_proxy@"
+ENV RAPICORNREPO "@RAPICORNREPO@"
# Automation tools and convenience commands
ENV DEBIAN_FRONTEND noninteractive
diff --git a/.travis.yml b/.travis.yml
index 3b3266d..103aa59 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,7 +13,7 @@ matrix:
env:
global:
- - http_proxy=""
+ #- http_proxy="http://example.com"
- bintray_url="https://dl.bintray.com/beast-team"
matrix:
- XFROM="ubuntu:wily" XUP="wily"
@@ -30,10 +30,9 @@ before_install:
install:
# Complete history is required for VCSREVISION
- travis_retry git fetch --unshallow
- # Configure Dockerfile
- - RAPICORNREPO="$bintray_url/$XUP snapshot main" && \
- sed -e "s&@XFROM@&$XFROM&""g" -e "s&@RAPICORNREPO@&$RAPICORNREPO&""g" \
- -e "${http_proxy:+/^FROM\b/aENV http_proxy $http_proxy}" < .travis.docker > Dockerfile
+ # Configure Dockerfile by substituting @VAR@ with $VAR
+ - export RAPICORNREPO="$bintray_url/$XUP snapshot main" && \
+ ./buildtool.sh applyenv .travis.docker > Dockerfile
# Build and run tests, create packages
- docker build -t beast .
diff --git a/buildtool.sh b/buildtool.sh
index 843605a..30bcf07 100755
--- a/buildtool.sh
+++ b/buildtool.sh
@@ -6,7 +6,7 @@ SCRIPTNAME=`basename $0`;
function die { e="$1" ; shift ; [ -n "$*" ] && echo "$SCRIPTNAME: $*" >&2 ; exit "${e:-127}" ; } # die
<exitcode> [message]
# == config ==
-mkconfig() # print shell variables describing package, version, commit id, monotonic revision
+mkconfig() # print shell variables describing package, version, commit id, monotonic revision
{
set -e # abort on errors
# ensure we're in the project directory and have full git history
@@ -43,9 +43,9 @@ mkconfig() # print shell variables describing package, version, commit id, monot
popd >/dev/null # cd OLDPWD
}
-
# == bintrayup ==
-bintrayup() {
+bintrayup() # Usage: bintrayup <bintrayaccount> <packagepath> <packagedistribution> [packages...]
+{
set +x # avoid printing authentication secrets
mkconfig >/dev/null # PACKAGE, VERSION, ...
ACCNAME="$1"; PKGPATH="$2"; PKGDIST="$3" # BINTRAY_APITOKEN must be set by caller
@@ -76,6 +76,30 @@ bintrayup() {
test $ALLOK = 0 || die 2 "Some files failed to upload"
}
+# == applyenv ==
+applyenv() # Usage: applyenv <inputfile> [inputargs...]
+{
+ # NOTE: avoid using unprefixed environment variables, they could become output substitutions
+ applyenv__input___="$1"; shift
+ test -r "$applyenv__input___" || { echo "$0: failed to read: $applyenv__input___"; exit 1; }
+ applyenv__sedprogram___=""
+ for applyenv__word___ in \
+ $(grep -oE '@[0123456789abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ]+@' "$applyenv__input___"
| sort | uniq)
+ do
+ applyenv__varname___=${applyenv__word___//@/} # word= EXAMPLE@ varname=EXAMPLE
+ if [[ ${!applyenv__varname___} == *\|* ]]; then
+ echo "$0: detected '|', skipping variable: \$$applyenv__varname___" >&2
+ elif test "$applyenv__word___" == "@0@"; then
+ applyenv__sedprogram___="$applyenv__sedprogram___; s|$applyenv__word___|${applyenv__input___}|g"
+ else
+ applyenv__sedprogram___="$applyenv__sedprogram___; s|$applyenv__word___|${!applyenv__varname___}|g"
+ fi
+ done
+ sed "$applyenv__sedprogram___" "$applyenv__input___"
+}
+
+
# == commands ==
[[ "$1" != config ]] || { shift; mkconfig "$@" ; exit $? ; }
[[ "$1" != bintrayup ]] || { shift; bintrayup "$@" ; exit $? ; }
+[[ "$1" != applyenv ]] || { shift; applyenv "$@" ; exit $? ; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]