summaryrefslogtreecommitdiff
path: root/docker/demo/build_base.sh
blob: 8633bc98a62484716ea958bff1ac7a1cf7f04001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash

# args: $1 base Dockerfile, $2 optional tags file

set -e

usage () {
  echo Usage: ./build_base.sh [-h,  --help] docker-file [tags-file]
  echo
  echo Builds the taler_local/taler_base base image, optionally
  echo using the 'tags-file', a text file containing environment
  echo variables definitions to specify to which Git tag each Taler
  echo component should be pulled.
}

for helpOpt in "-h" "--help"; do
  if test "$helpOpt" = "${1:-}"; then
    usage
    exit 0
  fi
done

if ! which realpath > /dev/null; then
  echo "Please, install 'realpath' (coreutils)"
fi

# Help message not returned, assume the first
# argument is the Dockerfile.
if test -z "$1"; then
  echo docker-file argument not found.
  exit 1
fi

DOCKER_FILE=$(realpath $1)

# Check base file.
if ! test -a $DOCKER_FILE; then
  echo Base Dockerfile: $DOCKER_FILE not found.
  exit 1
fi

# Allows extra features to conditionally copy files
# from the host during the build.  That solves the
# case where the tag file is not given.
export DOCKER_BUILDKIT=1

if test -n "$2"; then
  ! test -a "$2" && (echo "Tag file: $2 not found." && exit 1) 
  TAGS_FILE_DIR=$(dirname $2)
  TAGS_FILE_NAME=$(basename $2)
  cd $TAGS_FILE_DIR
  docker build --no-cache \
    -t taler_local/taler_base \
    -f $DOCKER_FILE \
    --build-arg tags_file=$TAGS_FILE_NAME .
  cd - > /dev/null
  exit 0
fi

docker build --no-cache \
  -t taler_local/taler_base \
  -f $DOCKER_FILE .