31
31
echo -e " -h --help Print this Help."
32
32
echo -e " -x --debug Verbose mode."
33
33
echo -e " -b --background Run docker compose up in detached mode."
34
+ echo -e " --dnt Disable telemetry collection"
34
35
echo -e " "
35
36
}
36
37
@@ -39,13 +40,133 @@ Help()
39
40
docker_compose_debug_yaml=" docker-compose.debug.yaml"
40
41
dot_env=" .env"
41
42
dot_env_dev=" .env.dev"
42
- flags=" flags.yml"
43
- temporal_yaml=" temporal/dynamicconfig/development.yaml"
44
- # any string is an array to POSIX shell. Space seperates values
43
+ flags=" flags.yml"
44
+ temporal_yaml=" temporal/dynamicconfig/development.yaml"
45
+ # any string is an array to POSIX shell. Space separates values
45
46
all_files=" $docker_compose_yaml $docker_compose_debug_yaml $dot_env $dot_env_dev $flags $temporal_yaml "
46
47
47
48
base_github_url=" https://raw.githubusercontent.com/airbytehq/airbyte-platform/v$VERSION /"
48
49
50
+ telemetrySuccess=false
51
+ telemetrySessionULID=" "
52
+ telemetryUserULID=" "
53
+ telemetryEnabled=true
54
+ # telemetry requires curl to be installed
55
+ if ! command -v curl > /dev/null; then
56
+ telemetryEnabled=false
57
+ fi
58
+
59
+ # TelemetryConfig configures the telemetry variables and will disable telemetry if it cannot be configured.
60
+ TelemetryConfig ()
61
+ {
62
+ # only attempt to do anything if telemetry is not disabled
63
+ if $telemetryEnabled ; then
64
+ telemetrySessionULID=$( curl -s http://ulid.abapp.cloud/ulid | xargs)
65
+
66
+ if [[ $telemetrySessionULID = " " || ${# telemetrySessionULID} -ne 26 ]]; then
67
+ # if we still don't have a ulid, give up on telemetry data
68
+ telemetryEnabled=false
69
+ return
70
+ fi
71
+
72
+ # if we have an analytics file, use it
73
+ if test -f ~ /.airbyte/analytics.yml; then
74
+ telemetryUserULID=$( cat ~ /.airbyte/analytics.yml | grep " anonymous_user_id" | cut -d " :" -f2 | xargs)
75
+ fi
76
+ # if the telemtery ulid is still undefined, attempt to create it and write the analytics file
77
+ if [[ $telemetryUserULID = " " || ${# telemetryUserULID} -ne 26 ]]; then
78
+ telemetryUserULID=$( curl -s http://ulid.abapp.cloud/ulid | xargs)
79
+ if [[ $telemetryUserULID = " " || ${# telemetryUserULID} -ne 26 ]]; then
80
+ # if we still don't have a ulid, give up on telemetry data
81
+ telemetryEnabled=false
82
+ else
83
+ # we created a new ulid, write it out
84
+ echo " Thanks you for using Airbyte!"
85
+ echo " Anonymous usage reporting is currently enabled. For more information, please see https://docs.airbyte.com/telemetry"
86
+ mkdir -p ~ /.airbyte
87
+ cat > ~ /.airbyte/analytics.yml << EOL
88
+ # This file is used by Airbyte to track anonymous usage statistics.
89
+ # For more information or to opt out, please see
90
+ # - https://docs.airbyte.com/operator-guides/telemetry
91
+ anonymous_user_id: $telemetryUserULID
92
+ EOL
93
+ fi
94
+ fi
95
+ fi
96
+ }
97
+
98
+ # TelemetryDockerUp checks if the webapp container is in a running state. If it is it will send a successful event.
99
+ # if after 10 minutes it hasn't succeeded, a failed event will be sent (or if the user terminates early, a failed event would
100
+ # also be sent).
101
+ #
102
+ # Note this only checks if the webapp container is running, that doesn't actually mean the entire stack is up.
103
+ # Some further refinement on this metric may be necessary.
104
+ TelemetryDockerUp ()
105
+ {
106
+ if ! $telemetryEnabled ; then
107
+ return
108
+ fi
109
+
110
+ # for up to 600 seconds (10 minutes), check to see if the server services is in a running state
111
+ end=$(( SECONDS+ 600 ))
112
+ while [ $SECONDS -lt $end ]; do
113
+ webappState=$( docker compose ps --all --format " {{.Service}}:{{.State}}" 2> /dev/null | grep server | cut -d " :" -f2 | xargs)
114
+ if [ " $webappState " = " running" ]; then
115
+ TelemetrySend " success" " install"
116
+ break
117
+ fi
118
+ sleep 1
119
+ done
120
+
121
+ TelemetrySend " failed" " install" " webapp was not running within 600 seconds"
122
+ }
123
+
124
+ readonly telemetryKey=" kpYsVGLgxEqD5OuSZAQ9zWmdgBlyiaej"
125
+ readonly telemetryURL=" https://api.segment.io/v1/track"
126
+ TelemetrySend ()
127
+ {
128
+ if $telemetrySuccess ; then
129
+ # due to how traps work, we don't want to send a failure for exiting docker after we sent a success
130
+ return
131
+ fi
132
+
133
+ if $telemetryEnabled ; then
134
+ # start, failed, success
135
+ local state=$1
136
+ # install, uninstall
137
+ local event=$2
138
+ # optional error
139
+ local err=${3:- " " }
140
+
141
+ local now=$( date -u " +%Y-%m-%dT%H:%M:%SZ" )
142
+ local body=$( cat << EOL
143
+ {
144
+ "anonymousId":"$telemetryUserULID ",
145
+ "event":"$event ",
146
+ "properties": {
147
+ "deployment_mode":"run_ab",
148
+ "session_id":"$telemetrySessionULID ",
149
+ "state":"$state ",
150
+ "os":"$OSTYPE ",
151
+ "script_version":"$VERSION ",
152
+ "testing":"true",
153
+ "error":"$err "
154
+ },
155
+ "timestamp":"$now ",
156
+ "writeKey":"$telemetryKey "
157
+ }
158
+ EOL
159
+ )
160
+ curl -s -o /dev/null -H " Content-Type: application/json" -X POST -d " $body " $telemetryURL
161
+ if [[ $state = " success" ]]; then {
162
+ telemetrySuccess=true
163
+ }
164
+ fi
165
+ fi
166
+ }
167
+
168
+ TelemetryConfig
169
+
49
170
# ###########################################################
50
171
# Download #
51
172
# ###########################################################
@@ -95,27 +216,53 @@ this_file_directory=$(dirname $0)
95
216
# Run this from the / directory because we assume relative paths
96
217
cd ${this_file_directory}
97
218
219
+ args=$@
220
+ # Parse the arguments for specific flags before parsing for actions.
221
+ for argument in $args ; do
222
+ case $argument in
223
+ -h | --help)
224
+ Help
225
+ exit
226
+ ;;
227
+ -b | --background)
228
+ dockerDetachedMode=" -d"
229
+ ;;
230
+ --dnt)
231
+ telemetryEnabled=false
232
+ ;;
233
+ esac
234
+ done
98
235
99
- for argument in $@ ; do
236
+ for argument in $args ; do
100
237
case $argument in
101
238
-d | --download)
239
+ TelemetrySend " start" " download"
240
+ trap ' TelemetrySend "failed" "download" "sigint"' SIGINT
241
+ trap ' TelemetrySend "failed" "download" "sigterm"' SIGTERM
102
242
Download
243
+ TelemetrySend " success" " download"
103
244
exit
104
245
;;
105
246
-r | --refresh)
247
+ TelemetrySend " start" " refresh"
248
+ trap ' TelemetrySend "failed" "refresh" "sigint"' SIGINT
249
+ trap ' TelemetrySend "failed" "refresh" "sigterm"' SIGTERM
106
250
DeleteLocalAssets
107
251
Download
108
- exit
109
- ;;
110
- -h | --help)
111
- Help
252
+ TelemetrySend " success" " refresh"
112
253
exit
113
254
;;
114
255
-x | --debug)
115
256
set -o xtrace # -x display every line before execution; enables PS4
116
257
;;
258
+ -h | --help)
259
+ # noop, this was checked in the previous for loop
260
+ ;;
117
261
-b | --background)
118
- dockerDetachedMode=" -d"
262
+ # noop, this was checked in the previous for loop
263
+ ;;
264
+ --dnt)
265
+ # noop, this was checked in the previous for loop
119
266
;;
120
267
* )
121
268
echo " $argument is not a known command."
@@ -124,9 +271,11 @@ for argument in $@; do
124
271
exit
125
272
;;
126
273
esac
127
- shift
128
274
done
129
275
276
+ TelemetrySend " start" " install"
277
+ trap ' TelemetrySend "failed" "install" "sigint"' SIGINT
278
+ trap ' TelemetrySend "failed" "install" "sigterm"' SIGTERM
130
279
131
280
# ######### Pointless Banner for street cred ##########
132
281
# Make sure the console is huuuge
148
297
# ######### Dependency Check ##########
149
298
if ! docker compose version > /dev/null 2> /dev/null; then
150
299
echo -e " $red_text " " docker compose v2 not found! please install docker compose!" " $default_text "
300
+ TelemetrySend " failed" " install" " docker compose not installed"
151
301
exit 1
152
302
fi
153
303
154
304
Download
155
305
156
- # ######### Source Envionmental Variables ##########
306
+ # ######### Source Environmental Variables ##########
157
307
158
308
for file in $dot_env $dot_env_dev ; do
159
309
echo -e " $blue_text " " Loading Shell Variables from $file ..." " $default_text "
@@ -162,16 +312,23 @@ done
162
312
163
313
164
314
# ######### Start Docker ##########
165
-
166
315
echo
167
316
echo -e " $blue_text " " Starting Docker Compose" " $default_text "
317
+ if [ -z " $dockerDetachedMode " ]; then
318
+ # if running in docker-detach mode, kick off a background task as `docker compose up` will be a blocking
319
+ # call and we'll have no way to determine when we've successfully started.
320
+ TelemetryDockerUp &
321
+ fi
168
322
169
323
docker compose up $dockerDetachedMode
170
324
171
325
# $? is the exit code of the last command. So here: docker compose up
172
326
if test $? -ne 0; then
173
327
echo -e " $red_text " " Docker compose failed. If you are seeing container conflicts" " $default_text "
174
328
echo -e " $red_text " " please consider removing old containers" " $default_text "
329
+ TelemetrySend " failed" " install" " docker compose failed"
330
+ else
331
+ TelemetrySend " success" " install"
175
332
fi
176
333
177
334
# ######### Ending Docker ##########
0 commit comments