-
Notifications
You must be signed in to change notification settings - Fork 20
/
publish
executable file
·188 lines (176 loc) · 4.33 KB
/
publish
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=internal/lib/library.sh
source "$SELFDIR/internal/lib/library.sh"
# shellcheck source=internal/lib/distro_info.sh
source "$SELFDIR/internal/lib/distro_info.sh"
OUTPUT_DIR=
REPO_SERVER_API_USERNAME=
REPO_SERVER_API_TOKEN_FILE=
REPOSITORY=
LOG_DIR=
YANK=false
YANK_ALL=false
CONCURRENCY=1
SHOW_BACKTRACES=false
SHOW_TASKS=false
ARGV=
function usage()
{
echo "Usage: ./publish [OPTIONS] <TASK NAMES...>"
echo "Publish built Debian packages to the Passenger RPM repos server."
echo
echo "Required options:"
echo " -d DIR Path in which build products are stored"
echo " -u NAME Repo server API username"
echo " -c PATH Path to repo server API token file"
echo " -r NAME Repository name: apt-repo-oss(.staging) or"
echo " apt-repo-enterprise(.staging)"
echo
echo "Optional options:"
echo " -l DIR Write logs to the given directory"
echo " -j NUM Set concurrency. Default: 1"
echo " -y Yank old packages"
echo " -Y Yank all packages from repository before publishing"
echo " -O Periodically show progress overview"
echo " -t Show backtraces on error"
echo
echo " -T Show all tasks"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local ORIG_ARGV
local opt
while getopts "d:u:c:r:D:C:l:j:yYOtTh" opt; do
case "$opt" in
d)
OUTPUT_DIR="$OPTARG"
;;
u)
REPO_SERVER_API_USERNAME="$OPTARG"
;;
c)
REPO_SERVER_API_TOKEN_FILE="$OPTARG"
;;
r)
REPOSITORY="$OPTARG"
;;
l)
LOG_DIR="$OPTARG"
;;
j)
CONCURRENCY=$OPTARG
;;
y)
YANK=true
;;
Y)
YANK_ALL=true
;;
O)
SHOW_OVERVIEW_PERIODICALLY=true
;;
t)
SHOW_BACKTRACES=true
;;
T)
SHOW_TASKS=true
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
ORIG_ARGV=("$@")
BUILDBOX_IMAGE=$(get_buildbox_image)
if [[ ${#ORIG_ARGV[@]} = 0 ]]; then
SHOW_TASKS=true
else
ARGV=("${ORIG_ARGV[@]}" finish)
if $SHOW_BACKTRACES; then
ARGV+=(--trace)
fi
fi
if [[ "$OUTPUT_DIR" = "" ]]; then
echo "ERROR: please specify a build products directory with -d."
exit 1
fi
if ! $SHOW_TASKS; then
if [[ "$REPO_SERVER_API_USERNAME" = "" ]]; then
echo "ERROR: please specify a repo server API username with -u."
exit 1
fi
if [[ "$REPO_SERVER_API_TOKEN_FILE" = "" ]]; then
echo "ERROR: please specify a repo server API token file with -c."
exit 1
fi
if [[ "$REPOSITORY" = "" ]]; then
echo "ERROR: please specify a repository name with -r."
exit 1
fi
fi
}
parse_options "$@"
OUTPUT_DIR=$(absolute_path "$OUTPUT_DIR")
if [[ "$REPO_SERVER_API_TOKEN_FILE" = "" ]]; then
REPO_SERVER_API_TOKEN_FILE="`absolute_path \"$REPO_SERVER_API_TOKEN_FILE\"`"
fi
EXTRA_MOUNTS=()
if [[ "$LOG_DIR" != "" ]]; then
LOG_DIR=$(absolute_path "$LOG_DIR")
EXTRA_MOUNTS+=(-v "$LOG_DIR:/work")
run mkdir -p "$LOG_DIR"
fi
if tty -s; then
TTY_ARGS="-t -i"
else
TTY_ARGS=
fi
if $SHOW_TASKS; then
exec docker run \
--rm $TTY_ARGS \
-v "$SELFDIR/internal:/system/internal:ro" \
-v "$OUTPUT_DIR:/output:ro" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
-e "SHOW_TASKS=true" \
-e "LC_CTYPE=C.UTF-8" \
"$BUILDBOX_IMAGE" \
/sbin/my_init --quiet --skip-runit --skip-startup-files -- \
/system/internal/scripts/inituidgid.sh \
/system/internal/publish/preinit.sh \
/sbin/setuser app \
rake -f /system/internal/publish/Rakefile -T --trace
else
echo "-------- Entering Docker container --------"
exec docker run \
--rm $TTY_ARGS \
-v "$SELFDIR/internal:/system/internal:ro" \
-v "$OUTPUT_DIR:/output:ro" \
-v "$REPO_SERVER_API_TOKEN_FILE:/repo_server_api_token.txt:ro" \
"${EXTRA_MOUNTS[@]}" \
-e "REPOSITORY=$REPOSITORY" \
-e "YANK=$YANK" \
-e "YANK_ALL=$YANK_ALL" \
-e "REPO_SERVER_API_USERNAME=$REPO_SERVER_API_USERNAME" \
-e "SHOW_OVERVIEW_PERIODICALLY=$SHOW_OVERVIEW_PERIODICALLY" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
-e "LC_CTYPE=C.UTF-8" \
"$BUILDBOX_IMAGE" \
/sbin/my_init --quiet --skip-runit --skip-startup-files -- \
/system/internal/scripts/inituidgid.sh \
/system/internal/publish/preinit.sh \
/sbin/setuser app \
rake -f /system/internal/publish/Rakefile -j "$CONCURRENCY" "${ARGV[@]}"
fi