diff options
author | Varac <varac@leap.se> | 2017-09-25 16:52:04 +0200 |
---|---|---|
committer | Varac <varac@leap.se> | 2017-09-25 19:13:33 +0200 |
commit | d944721a35786a48b996ef088f0311b1835180a7 (patch) | |
tree | 6c9194a5b85dd761e80c5658c1c8d69f5453dd3d /.gitlab/build.sh | |
parent | 64e961fe8ebc1eeb331cef2604cf4c8714e8d8ad (diff) |
Build docker images from CI
Diffstat (limited to '.gitlab/build.sh')
-rwxr-xr-x | .gitlab/build.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/.gitlab/build.sh b/.gitlab/build.sh new file mode 100755 index 00000000..cc63075d --- /dev/null +++ b/.gitlab/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Build script for the gitlab ci. +# +# usage: build.sh DIR [TAG] +# +# Will run docker build in DIR with DIR/Dockerfile or +# DIR/TAG.dockerfile if TAG is given. +# +# Assumes CI specific environment variables to be set: +# CI_REGISTRY_IMAGE +# LAST_COMMIT (fetched from the gitlab api in before_script hook) +# + +DIR=$1 +TAG=${2:-latest} +DOCKERFILE=docker/${DIR}/${2:-Dockerfile}${2:+.dockerfile} +TARGET=${CI_REGISTRY_IMAGE}/${DIR}:${TAG} + +if git diff "$LAST_COMMIT" HEAD --name-only | egrep "($DOCKERFILE|^.gitlab)"; then + docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY" + docker build -t "$TARGET" -f "$DOCKERFILE" docker/ + docker push "$TARGET" +fi |