-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuild-rbenv-rpm
executable file
·115 lines (102 loc) · 2.76 KB
/
build-rbenv-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
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/library.sh
source "$SELFDIR/lib/library.sh"
SOURCE_PATH=
OUTPUT_PATH=
REVISION=0
function usage()
{
echo "Usage: ./build-rbenv-rpm <OPTIONS>"
echo "Build an Rbenv RPM package."
echo
echo "To find out the right value for -n:"
echo " bin/rbenv --version | awk '{ print \$2 }' | sed -E 's/(.+)-.*/\1/'"
echo
echo "Required options:"
echo " -s PATH Path to Rbenv source tree"
echo " -o PATH Path to output package file"
echo " -n VERSION Rbenv version number without commit hash suffix"
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 "s:o:n:r:h" opt; do
case "$opt" in
s)
SOURCE_PATH=$(absolute_path "$OPTARG")
;;
o)
OUTPUT_PATH=$(absolute_path "$OPTARG")
;;
n)
VERSION="$OPTARG"
;;
r)
REVISION="$OPTARG"
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
ORIG_ARGV=("$@")
if [[ "$SOURCE_PATH" = "" ]]; then
echo 'ERROR: please specify an Rbenv source 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 package path with -o.' >&2
exit 1
fi
if [[ "$VERSION" = "" ]]; then
echo 'ERROR: please specify an Rbenv version with -n.' >&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 "$SOURCE_PATH:/input/rbenv:ro" \
-v "$OUTPUT_TEMP_PATH:/output/rbenv.rpm" \
-e "VERSION=$VERSION" \
-e "REVISION=$REVISION" \
--user "$(id -u):$(id -g)" \
"ghcr.io/fullstaq-ruby/server-edition-ci-images:utility-v$IMAGE_VERSION" \
/system/container-entrypoints/build-rbenv-rpm
function _cleanup() {
echo '--- Exited Docker container ---'
run mv "$OUTPUT_TEMP_PATH" "$OUTPUT_PATH"
}