duneci-build-docker-image 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#! /bin/bash

set -e
set -u

usage() {
  echo "usage: $0 [docker-options]... <image-name> <directories>..." >&2
  exit 0
}

docker-build() {
  docker build ${docker_opts[@]:+"${docker_opts[@]}"} "${@}"
}

docker_opts=()
16
for var in ftp_proxy http_proxy https_proxy no_proxy; do
17
18
19
20
21
  if [[ -n "${!var:-}" ]]; then
    docker_opts+=(--build-arg="${var}=${!var}")
  fi
done

22
23
24
25
if [[ "${DUNECI_DOCKER_CACHE:-1}" = 0 ]]; then
  docker_opts+=(--no-cache)
fi

26
27
28
29
if [[ $# -lt 2 ]]; then
  usage
fi

30
31
parallel=

32
33
while :; do
  case "${1}" in
34
35
36
37
    --parallel)
      parallel=1
      shift
      ;;
38
39
40
41
42
43
44
45
46
47
48
49
    -*)
      docker_opts+=("${1}")
      shift
      ;;
    *)
      break
      ;;
  esac
done

image="${1}"; shift

50
51
52
53
if [[ -n "${parallel}" -a -v DUNECI_PARALLEL ]]; then
  docker_opts+=(--build-arg=DUNECI_PARALLEL="${DUNECI_PARALLEL}")
fi

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
builddir="build/${image##*/}"
if [[ -e ${builddir} ]]; then
  echo "E: ${builddir} already exists" >&2
  exit 1
fi

mkdir -p -- "${builddir}"

for d in "$@"; do
  cp -t "${builddir}" -- "${d}"/*
done

docker-build -t "${image}" "${builddir}"

rm -rf -- "${builddir}"