-
Notifications
You must be signed in to change notification settings - Fork 30
/
build-ruby
executable file
·174 lines (161 loc) · 5.02 KB
/
build-ruby
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/library.sh
source "$SELFDIR/lib/library.sh"
ENVIRONMENT_NAME=
SOURCE_PATH=
PACKAGE_VERSION=
OUTPUT_PATH=
VARIANT=normal
JEMALLOC_BIN_PATH=
BUILD_CONCURRENCY=1
CACHE_CONNECTION_STRING_FILE=
CACHE_CONTAINER=
CACHE_KEY_PREFIX=
function usage()
{
echo "Usage: ./build-ruby <OPTIONS>"
echo "Build a Ruby binary tarball from its source tarball."
echo
echo "Required options:"
echo " -n NAME Name of environment to build in (one of: $(list_environment_names "$SELFDIR/environments"))"
echo " -s PATH Path to Ruby source tarball"
echo " -v VERSION Package version number"
echo " -o PATH Path to output tarball"
echo
echo "Build variant (pick at most one):"
echo " -m PATH Build with Jemalloc support, using this Jemalloc binary tarball (as built by ./build-jemalloc)"
echo " -t Build with malloc_trim support"
echo
echo "Optional options:"
echo " -j NUM Build concurrency (default: $BUILD_CONCURRENCY)"
echo " -c PATH Cache to Azure Blob Storage, use connection string in given file"
echo " -r CONTAINER Use given Azure Blob Storage container"
echo " -d NAME Use given Azure Blob Storage key prefix"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "n:s:v:o:m:tj:c:r:d:h" opt; do
case "$opt" in
n)
ENVIRONMENT_NAME="$OPTARG"
;;
s)
SOURCE_PATH=$(absolute_path "$OPTARG")
;;
v)
PACKAGE_VERSION="$OPTARG"
;;
o)
OUTPUT_PATH=$(absolute_path "$OPTARG")
;;
m)
VARIANT=jemalloc
JEMALLOC_BIN_PATH=$(absolute_path "$OPTARG")
;;
t)
VARIANT=malloctrim
;;
j)
BUILD_CONCURRENCY="$OPTARG"
;;
c)
CACHE_CONNECTION_STRING_FILE=$(absolute_path "$OPTARG")
;;
r)
CACHE_CONTAINER="$OPTARG"
;;
d)
CACHE_KEY_PREFIX="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
if [[ "$ENVIRONMENT_NAME" = "" ]]; then
echo 'ERROR: please specify an environment name with -n.' >&2
exit 1
fi
if [[ "$SOURCE_PATH" = "" ]]; then
echo 'ERROR: please specify a Ruby source tarball path with -s.' >&2
exit 1
fi
if [[ ! -e "$SOURCE_PATH" ]]; then
echo "ERROR: $SOURCE_PATH does not exist." >&2
exit 1
fi
if [[ "$PACKAGE_VERSION" = "" ]]; then
echo 'ERROR: please specify a package version number with -v.' >&2
exit 1
fi
if [[ "$VARIANT" = jemalloc ]]; then
if [[ "$JEMALLOC_BIN_PATH" = "" ]]; then
echo 'ERROR: please specify a Jemalloc binary tarball path with -m.' >&2
exit 1
fi
if [[ "$JEMALLOC_BIN_PATH" != "" && ! -e "$JEMALLOC_BIN_PATH" ]]; then
echo "ERROR: $JEMALLOC_BIN_PATH does not exist." >&2
exit 1
fi
fi
if [[ "$OUTPUT_PATH" = "" ]]; then
echo 'ERROR: please specify an output tarball path with -o.' >&2
exit 1
fi
if [[ -n "$CACHE_CONNECTION_STRING_FILE" && -z "$CACHE_CONTAINER" ]]; then
echo "ERROR: if a cache connection string file is given, then an Azure Blob Storage container name must also be given." >&2
exit 1
fi
}
parse_options "$@"
if tty -s; then
TTY_ARGS=(-t -i)
else
TTY_ARGS=()
fi
MOUNT_ARGS=()
if [[ "$VARIANT" = jemalloc ]]; then
MOUNT_ARGS+=(-v "$JEMALLOC_BIN_PATH:/input/jemalloc-bin.tar.gz:ro")
fi
if [[ -n "$CACHE_CONNECTION_STRING_FILE" ]]; then
MOUNT_ARGS+=(-v "$CACHE_CONNECTION_STRING_FILE:/azure-connection-string.txt:ro")
fi
IMAGE_VERSION=$(read_single_value_file "$SELFDIR/environments/$ENVIRONMENT_NAME/image_tag")
OUTPUT_TEMP_PATH=$(mktemp "$OUTPUT_PATH.XXXXXX")
create_file_if_missing "$OUTPUT_TEMP_PATH"
echo '--- Entering Docker container ---'
function _cleanup() {
echo
echo '--- Exited Docker container ---'
run rm -f "$OUTPUT_TEMP_PATH"
}
verbose_run docker run --rm --init "${TTY_ARGS[@]}" \
-v "$SELFDIR:/system:ro" \
-v "$SOURCE_PATH:/input/ruby-src.tar.gz:ro" \
-v "$OUTPUT_TEMP_PATH:/output/ruby-bin.tar.gz" \
"${MOUNT_ARGS[@]}" \
-e "VARIANT=$VARIANT" \
-e "BUILD_CONCURRENCY=$BUILD_CONCURRENCY" \
-e "PACKAGE_VERSION=$PACKAGE_VERSION" \
-e "ENVIRONMENT_NAME=$ENVIRONMENT_NAME" \
-e "CACHE_CONTAINER=$CACHE_CONTAINER" \
-e "CACHE_KEY_PREFIX=$CACHE_KEY_PREFIX" \
--user "$(id -u):$(id -g)" \
"ghcr.io/fullstaq-ruby/server-edition-ci-images:$ENVIRONMENT_NAME-v$IMAGE_VERSION" \
/system/container-entrypoints/build-ruby
function _cleanup() {
echo '--- Exited Docker container ---'
run mv "$OUTPUT_TEMP_PATH" "$OUTPUT_PATH"
}