forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-ab-platform.sh
executable file
·169 lines (144 loc) · 5.5 KB
/
run-ab-platform.sh
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
#!/bin/bash
VERSION=0.44.4
# Run away from anything even a little scary
set -o nounset # -u exit if a variable is not set
set -o errexit # -f exit for any command failure"
# text color escape codes (please note \033 == \e but OSX doesn't respect the \e)
blue_text='\033[94m'
red_text='\033[31m'
default_text='\033[39m'
# set -x/xtrace uses a Sony PS4 for more info
PS4="$blue_text""${BASH_SOURCE}:${LINENO}: ""$default_text"
############################################################
# Help #
############################################################
Help()
{
# Display Help
echo -e "This Script will download the necessary files for running docker compose"
echo -e "It will also run docker compose up"
echo -e "Take Warning! These assets may become stale over time!"
echo
# $0 is the currently running program
echo -e "Syntax: $0"
echo -e "options:"
echo -e " -d --download Only download files - don't run docker compose"
echo -e " -r --refresh ${red_text}DELETE${default_text} existing assets and re-download new ones"
echo -e " -h --help Print this Help."
echo -e " -x --debug Verbose mode."
echo -e ""
}
########## Declare assets care about ##########
docker_compose_yaml="docker-compose.yaml"
docker_compose_debug_yaml="docker-compose.debug.yaml"
dot_env=".env"
dot_env_dev=".env.dev"
flags="flags.yml"
# any string is an array to POSIX shell. Space seperates values
all_files="$docker_compose_yaml $docker_compose_debug_yaml $dot_env $dot_env_dev $flags"
base_github_url="https://raw.githubusercontent.com/airbytehq/airbyte-platform/v$VERSION/"
############################################################
# Download #
############################################################
Download()
{
########## Check if we already have the assets we are looking for ##########
for file in $all_files; do
if test -f $file; then
# Check if the assets are old. A possibly sharp corner
if test $(find $file -type f -mtime +60 > /dev/null); then
echo -e "$red_text""Warning your $file may be stale!""$default_text"
echo -e "$red_text""rm $file to refresh!""$default_text"
else
echo -e "$blue_text""found $file locally!""$default_text"
fi
else
echo -e "$blue_text""Downloading $file""$default_text"
curl --location\
--fail\
--silent\
--show-error \
${base_github_url}${file} > $file
fi
done
}
DeleteLocalAssets()
{
for file in $all_files; do
echo -e "$blue_text""Attempting to delete $file!""$default_text"
if test -f $file; then
rm $file && echo -e "It's gone!"
else
echo -e "$file not found locally. Nothing to delete."
fi
done
}
# $0 is the currently running program (this file)
this_file_directory=$(dirname $0)
# Run this from the / directory because we assume relative paths
cd ${this_file_directory}
for argument in $@; do
case $argument in
-d | --download)
Download
exit
;;
-r | --refresh)
DeleteLocalAssets
exit
;;
-h | --help)
Help
exit
;;
-x | --debug)
set -o xtrace # -x display every line before execution; enables PS4
;;
*)
echo "$argument is not a known command."
echo
Help
exit
;;
esac
shift
done
########## Pointless Banner for street cred ##########
# Make sure the console is huuuge
if test $(tput cols) -ge 64; then
# Make it green!
echo -e "\033[32m"
echo -e " █████╗ ██╗██████╗ ██████╗ ██╗ ██╗████████╗███████╗"
echo -e "██╔══██╗██║██╔══██╗██╔══██╗╚██╗ ██╔╝╚══██╔══╝██╔════╝"
echo -e "███████║██║██████╔╝██████╔╝ ╚████╔╝ ██║ █████╗ "
echo -e "██╔══██║██║██╔══██╗██╔══██╗ ╚██╔╝ ██║ ██╔══╝ "
echo -e "██║ ██║██║██║ ██║██████╔╝ ██║ ██║ ███████╗"
echo -e "╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚══════╝"
echo -e " Move Data"
# Make it less green
echo -e "\033[0m"
sleep 1
fi
########## Dependency Check ##########
if ! docker compose version >/dev/null 2>/dev/null; then
echo -e "$red_text""docker compose v2 not found! please install docker compose!""$default_text"
exit 1
fi
Download
########## Source Envionmental Variables ##########
for file in $dot_env $dot_env_dev; do
echo -e "$blue_text""Loading Shell Variables from $file...""$default_text"
source $file
done
########## Start Docker ##########
echo
echo -e "$blue_text""Starting Docker Compose""$default_text"
docker compose up
# $? is the exit code of the last command. So here: docker compose up
if test $? -ne 0; then
echo -e "$red_text""Docker compose failed. If you are seeing container conflicts""$default_text"
echo -e "$red_text""please consider removing old containers""$default_text"
fi
########## Ending Docker ##########
docker compose down
echo -e "$blue_text""Stopping Docker Compose""$default_text"