forked from fullstaq-ruby/server-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-ruby-rpm
executable file
·103 lines (90 loc) · 2.47 KB
/
build-ruby-rpm
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
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/library.sh
source "$SELFDIR/lib/library.sh"
BINARY_TARBALL_PATH=
OUTPUT_PATH=
REVISION=0
function usage()
{
echo "Usage: ./build-ruby-rpm <OPTIONS>"
echo "Build a Ruby RPM package from its binary tarball (which is produced by ./build-ruby)."
echo
echo "Required options:"
echo " -b PATH Path to Ruby binary tarball (as built by ./build-ruby)"
echo " -o PATH Path to output package file"
echo
echo "Optional options:"
echo " -r REVISION Package revision number (default: $REVISION)"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local ORIG_ARGV
local opt
while getopts "b:o:r:h" opt; do
case "$opt" in
b)
BINARY_TARBALL_PATH=$(absolute_path "$OPTARG")
;;
o)
OUTPUT_PATH=$(absolute_path "$OPTARG")
;;
r)
REVISION="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
ORIG_ARGV=("$@")
if [[ "$BINARY_TARBALL_PATH" = "" ]]; then
echo 'ERROR: please specify a Ruby binary tarball path with -b.' >&2
exit 1
fi
if [[ ! -e "$BINARY_TARBALL_PATH" ]]; then
echo "ERROR: $BINARY_TARBALL_PATH does not exist." >&2
exit 1
fi
if [[ "$OUTPUT_PATH" = "" ]]; then
echo 'ERROR: please specify an output package path with -o.' >&2
exit 1
fi
}
parse_options "$@"
if tty -s; then
TTY_ARGS=(-t -i)
else
TTY_ARGS=()
fi
IMAGE_VERSION=$(read_single_value_file "$SELFDIR/environments/utility/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 "$BINARY_TARBALL_PATH:/input/ruby-bin.tar.gz:ro" \
-v "$OUTPUT_TEMP_PATH:/output/ruby.rpm" \
-e "REVISION=$REVISION" \
--user "$(id -u):$(id -g)" \
"fullstaq/ruby-build-env-utility:$IMAGE_VERSION" \
/system/container-entrypoints/build-ruby-rpm
function _cleanup() {
echo '--- Exited Docker container ---'
run mv "$OUTPUT_TEMP_PATH" "$OUTPUT_PATH"
}