-
Notifications
You must be signed in to change notification settings - Fork 19
/
make.sh
executable file
·197 lines (170 loc) · 9.88 KB
/
make.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
G_SYNOPSIS="
NAME
make.sh
SYNOPSIS
make.sh [up|down]
ARGS
[up|down]
Denotes whether to fire up or tear down the set of services for the development env.
DESCRIPTION
make.sh script will depending on the argument fire up or tear down the
Chris store development environment.
"
if [[ "$#" -eq 0 ]] || [[ "$#" -gt 1 ]]; then
echo "$G_SYNOPSIS"
exit 1
fi
source ./decorate.sh
source ./cparse.sh
declare -i STEP=0
HERE=$(pwd)
if [[ "$1" == 'up' ]]; then
title -d 1 "Changing permissions to 755 on" " $HERE"
echo "chmod -R 755 $HERE" | ./boxes.sh
chmod -R 755 $HERE
windowBottom
title -d 1 "Pulling core containers where needed..."
printf "${LightCyan}%40s${Green}%-40s${Yellow}\n" \
"docker pull" " postgres:16" | ./boxes.sh
docker pull postgres:16 | ./boxes.sh
echo "" | ./boxes.sh
windowBottom
title -d 1 "Starting containerized development environment using " " ./docker-compose_dev.yml"
echo "docker-compose -f docker-compose_dev.yml up -d --build" | ./boxes.sh ${LightCyan}
windowBottom
docker-compose -f docker-compose_dev.yml up -d --build >& dc.out > /dev/null
echo -en "\033[2A\033[2K"
cat dc.out | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh ${LightGreen}
windowBottom
title -d 1 "Waiting until ChRIS store database server is ready to accept connections..."
echo "This might take a few seconds..." | ./boxes.sh ${Yellow}
windowBottom
docker-compose -f docker-compose_dev.yml exec chris_store_dev_db sh -c 'while ! psql -U chris -d chris_store_dev -c "select 1" 2> /dev/null; do sleep 5; done;' >& dc.out > /dev/null
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh ${LightGreen}
echo "" | ./boxes.sh
echo "ChRIS store database is ready to accept connections" | ./boxes.sh ${LightGreen}
echo "" | ./boxes.sh
windowBottom
title -d 1 "Running Django Unit tests..."
docker-compose -f docker-compose_dev.yml exec chris_store_dev python manage.py test --exclude-tag integration
status=$?
title -d 1 "Unit tests' results"
if (( $status == 0 )) ; then
printf "%40s${LightGreen}%40s${NC}\n" \
"Unit tests" "[ success ]" | ./boxes.sh
else
printf "%40s${Red}%40s${NC}\n" \
"Unit tests" "[ failure ]" | ./boxes.sh
fi
windowBottom
title -d 1 "Running Django Integration tests..."
docker-compose -f docker-compose_dev.yml exec chris_store_dev python manage.py test --tag integration
status=$?
title -d 1 "Integration tests' results"
if (( $status == 0 )) ; then
printf "%40s${LightGreen}%40s${NC}\n" \
"Integration tests" "[ success ]" | ./boxes.sh
else
printf "%40s${Red}%40s${NC}\n" \
"Integration tests" "[ failure ]" | ./boxes.sh
fi
windowBottom
title -d 1 "Creating two ChRIS store API users"
echo "" | ./boxes.sh
echo "Setting superuser chris:chris1234..." | ./boxes.sh ${LightCyan}
docker-compose -f docker-compose_dev.yml exec chris_store_dev /bin/bash -c 'python manage.py createsuperuser --noinput --username chris --email [email protected] 2> /dev/null;'
docker-compose -f docker-compose_dev.yml exec chris_store_dev /bin/bash -c \
'python manage.py shell -c "from django.contrib.auth.models import User; user = User.objects.get(username=\"chris\"); user.set_password(\"chris1234\"); user.save()"'
echo "" | ./boxes.sh
echo "Setting normal user cubeadmin:cubeadmin1234..." | ./boxes.sh ${LightCyan}
docker-compose -f docker-compose_dev.yml exec chris_store_dev /bin/bash -c 'python manage.py createsuperuser --noinput --username cubeadmin --email [email protected] 2> /dev/null;'
docker-compose -f docker-compose_dev.yml exec chris_store_dev /bin/bash -c \
'python manage.py shell -c "from django.contrib.auth.models import User; user = User.objects.get(username=\"cubeadmin\"); user.set_password(\"cubeadmin1234\"); user.save()"'
echo "" | ./boxes.sh
windowBottom
title -d 1 "Automatically uploading some plugins to the ChRIS STORE..."
# Declare an array variable for the list of plugin names to be automatically registered
# Add a new plugin name to the list if you want it to be automatically registered
declare -a plugins=( "pl-simplefsapp"
"pl-simpledsapp"
"pl-s3retrieve"
"pl-dircopy"
"pl-topologicalcopy"
)
declare -i i=1
for plugin in "${plugins[@]}"; do
echo "" | ./boxes.sh
echo "${STEP}.$i: Uploading $plugin representation to the ChRIS store..." | ./boxes.sh ${LightCyan}
PLUGIN_DOCK="fnndsc/${plugin}"
PLUGIN_MODULE="${plugin:3}"
docker pull "$PLUGIN_DOCK"
PLUGIN_REP=$(docker run --rm "$PLUGIN_DOCK" "${PLUGIN_MODULE}" --json 2> /dev/null;)
docker-compose -f docker-compose_dev.yml exec chris_store_dev python plugins/services/manager.py add "${plugin}" cubeadmin https://github.com/FNNDSC "$PLUGIN_DOCK" --descriptorstring "$PLUGIN_REP" >/dev/null
((i++))
done
windowBottom
title -d 1 "Automatically creating a locked pipeline in the ChRIS STORE" "(mutable by the owner and not available to other users)"
S3_PLUGIN_VER=$(docker run --rm fnndsc/pl-s3retrieve s3retrieve --version)
SIMPLEDS_PLUGIN_VER=$(docker run --rm fnndsc/pl-simpledsapp simpledsapp --version)
PIPELINE_NAME="s3retrieve_v${S3_PLUGIN_VER}-simpledsapp_v${SIMPLEDS_PLUGIN_VER}"
printf "%20s${LightBlue}%60s${NC}\n" \
"Creating pipeline..." "[ $PIPELINE_NAME ]" | ./boxes.sh ${LightCyan}
STR1='[{"plugin_name": "pl-s3retrieve", "plugin_version": "'
STR2='", "plugin_parameter_defaults": [{"name": "awssecretkey", "default": "somekey"},{"name": "awskeyid", "default": "somekeyid"}], "previous_index": null},
{"plugin_name": "pl-simpledsapp", "plugin_version": "'
STR3='", "previous_index": 0}]'
PLUGIN_TREE=${STR1}${S3_PLUGIN_VER}${STR2}${SIMPLEDS_PLUGIN_VER}${STR3}
windowBottom
docker-compose -f docker-compose_dev.yml exec chris_store_dev python pipelines/services/manager.py add "${PIPELINE_NAME}" cubeadmin "${PLUGIN_TREE}" >& dc.out >/dev/null
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh
windowBottom
title -d 1 "Automatically creating an unlocked pipeline in the ChRIS STORE" "(unmutable and available to all users)"
PIPELINE_NAME="simpledsapp_v${SIMPLEDS_PLUGIN_VER}-simpledsapp_v${SIMPLEDS_PLUGIN_VER}-simpledsapp_v${SIMPLEDS_PLUGIN_VER}"
printf "%20s${LightBlue}%60s${NC}\n" \
"Creating pipeline..." "[ $PIPELINE_NAME ]" | ./boxes.sh ${LightCyan}
STR4='[{"plugin_name": "pl-simpledsapp", "plugin_version": "'
STR5='", "previous_index": null},{"plugin_name": "pl-simpledsapp", "plugin_version": "'
STR6='", "previous_index": 0},{"plugin_name": "pl-simpledsapp", "plugin_version": "'
STR7='", "previous_index": 0}]'
PLUGIN_TREE=${STR4}${SIMPLEDS_PLUGIN_VER}${STR5}${SIMPLEDS_PLUGIN_VER}${STR6}${SIMPLEDS_PLUGIN_VER}${STR7}
windowBottom
docker-compose -f docker-compose_dev.yml exec chris_store_dev python pipelines/services/manager.py add "${PIPELINE_NAME}" cubeadmin "${PLUGIN_TREE}" --unlock >& dc.out >/dev/null
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh
windowBottom
title -d 1 "Restarting ChRIS store's Django development server..."
printf "${LightCyan}%40s${LightGreen}%40s\n" \
"Restarting" "chris_dev" | ./boxes.sh
windowBottom
docker-compose -f docker-compose_dev.yml restart chris_store_dev >& dc.out >/dev/null
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh
windowBottom
title -d 1 "Attaching interactive terminal (ctrl-a to detach)"
chris_store_dev=$(docker ps -f ancestor=fnndsc/chris_store:dev -q)
docker attach --detach-keys ctrl-a $chris_store_dev
fi
if [[ "$1" == 'down' ]]; then
title -d 1 "Destroying containerized development environment" "from ./docker-compose_dev.yml]"
echo "Do you want to also remove persistent volumes? [y/n]" | ./boxes.sh ${LightCyan}
windowBottom
old_stty_cfg=$(stty -g)
stty raw -echo ; REPLY=$(head -c 1) ; stty $old_stty_cfg
echo -en "\033[2A\033[2K"
# read -p " " -n 1 -r REPLY
if [[ $REPLY =~ ^[Yy]$ ]] ; then
printf "Removing persistent volumes...\n" | ./boxes.sh ${Yellow}
windowBottom
docker-compose -f docker-compose_dev.yml down -v >& dc.out >/dev/null
else
printf "Keeping persistent volumes...\n" | ./boxes.sh ${Yellow}
windowBottom
docker-compose -f docker-compose_dev.yml down >& dc.out >/dev/null
fi
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh
windowBottom
fi