-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuild-jemalloc
executable file
·138 lines (125 loc) · 3.84 KB
/
build-jemalloc
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
#!/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=
OUTPUT_PATH=
BUILD_CONCURRENCY=1
CACHE_CONNECTION_STRING_FILE=
CACHE_CONTAINER=
CACHE_KEY_PREFIX=
function usage()
{
echo "Usage: ./build-jemalloc <OPTIONS>"
echo "Build a Jemalloc 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 Jemalloc source tarball"
echo " -o PATH Path to output tarball"
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:o:j:c:r:d:h" opt; do
case "$opt" in
n)
ENVIRONMENT_NAME="$OPTARG"
;;
s)
SOURCE_PATH=$(absolute_path "$OPTARG")
;;
o)
OUTPUT_PATH=$(absolute_path "$OPTARG")
;;
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 Jemalloc 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 [[ "$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
if [[ -n "$CACHE_CONNECTION_STRING_FILE" ]]; then
CACHE_PATH_MOUNT_ARGS=(-v "$CACHE_CONNECTION_STRING_FILE:/azure-connection-string.txt:ro")
else
CACHE_PATH_MOUNT_ARGS=()
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/jemalloc-src.tar.bz2:ro" \
-v "$OUTPUT_TEMP_PATH:/output/jemalloc-bin.tar.gz" \
"${CACHE_PATH_MOUNT_ARGS[@]}" \
-e "ENVIRONMENT_NAME=$ENVIRONMENT_NAME" \
-e "BUILD_CONCURRENCY=$BUILD_CONCURRENCY" \
-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-jemalloc
function _cleanup() {
echo '--- Exited Docker container ---'
run mv "$OUTPUT_TEMP_PATH" "$OUTPUT_PATH"
}