forked from fullstaq-ruby/server-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-environment-image
executable file
·68 lines (58 loc) · 1.47 KB
/
build-environment-image
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
63
64
65
66
67
68
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/library.sh
source "$SELFDIR/lib/library.sh"
FORMAT="fullstaq/ruby-build-env-%s"
function usage()
{
echo "Usage: ./build-environment [OPTIONS] <NAME>"
echo "Build a build environment Docker image. A build environment is an image based on"
echo "a certain Linux distro, and is used to compile Ruby for that distro."
echo
echo "<NAME> is the name of a subdirectory in environments/, such as 'ubuntu-18.04'."
echo
echo "This script will produce a Docker image called"
echo "'fullstaq/ruby-build-env-<NAME>'. You can change the name format with -f."
echo
echo "Optional options:"
echo " -f FORMAT A format string that defines the output image name. Default: $FORMAT"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local ORIG_ARGV
local opt
while getopts "f:h" opt; do
case "$opt" in
f)
FORMAT="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
ORIG_ARGV=("$@")
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
}
parse_options "$@"
NAME="$1"
IMAGE_NAME=$(printf "$FORMAT" "$NAME")
IMAGE_VERSION=$(read_single_value_file "$SELFDIR/environments/$NAME/image_tag")
if [[ ! -e "$SELFDIR/environments/$NAME" ]]; then
echo "ERROR: $SELFDIR/environments/$NAME does not exist." >&2
exit 1
fi
run docker build --pull -t "$IMAGE_NAME:$IMAGE_VERSION" "$SELFDIR/environments/$NAME"