-
Notifications
You must be signed in to change notification settings - Fork 1
/
windows-pull-run.bat
325 lines (260 loc) · 11.2 KB
/
windows-pull-run.bat
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
@ECHO OFF
setlocal enabledelayedexpansion
@REM Default to normal exit code
SET exitcode=0
GOTO loop
@REM printusage: Block to print the script's usage and exit with a specified exit code
:printusage
echo.
echo SYNOPSIS:
echo windows-pull-run.bat [OPTIONS]
echo.
echo OPTIONS:
echo -h, --help Displays this help message
echo -o, --no-open Disables automatic opening of the dashboard in your browser
echo -t ^<TAG^>, --tag=^<TAG^> Specifies the tag of the dashboard image you want to pull/run.
echo By default, the "latest" tag is used
echo -d ^<TAG^>, --dist-tag=^<TAG^> Specifies the tag of the engineering-data-distributor-image to pull and run.
echo If no tag is specified, the image tagged "latest" will be used.
echo - NOTE: The sc1-data-format submodule in the engineering-data-distributor-image
echo will automatically be synced with that of the chase-car-dashboard-image being run.
echo -c ^<CONFIG^>, --config=^<CONFIG^> Specifies the configuration in which to run the dasboard and data distribution server.
echo The following are the available configurations:
echo - "competition": Run only the chase-car-dashboard-image on this computer. This computer will be
echo connected to another device running the engineering-data-distributor-image via a LAN.
echo The device running the distribution server will receive data from the solar car and pipe it to
echo the computers connected to it.
echo - NOTE: In order to run this configuration, the ethernet port connected to the device running
echo the distribution server has to be on the 192.168.1.0/24 subnet, and it cannot have an
echo IP address in the following range: 192.168.1.15-17. Additionally, ensure that you have
echo inbound and outbound firewall rules allowing the remote IP address 192.168.1.15 to
echo communicate with local IP addresses on the 192.168.1.0/24 subnet via TCP through port 4003.
echo - "dev": Run only the chase-car-dashboard-image on this computer. This configuration will run the data
echo generator within the dashboard to create random mock datasets to display.
exit /b %exitcode%
@REM badargerror: Block for erroring out due to a bad argument being provided
:badargerror
echo.
powershell write-host -fore Red [ERROR] Bad argument: %1
SET exitcode=1
GOTO printusage
@REM multipledisttagserror: Block for erroring out due to multiple engineering-data-distributor-image tags being specified
:multipledisttagserror
echo.
powershell write-host -fore Red [ERROR] Provided more than one engineering-data-distributor-image tag
SET exitcode=1
GOTO printusage
@REM multipletagserror: Block for erroring out due to multiple chase-car-dashboard-image tags being specified
:multipletagserror
echo.
powershell write-host -fore Red [ERROR] Provided more than one chase-car-dashboard-image tag
SET exitcode=1
GOTO printusage
@REM multipleconfigserror: Block for erroring out due to multiple run configurations being specified
:multipleconfigserror
echo.
powershell write-host -fore Red [ERROR] Provided more than one run configuration
SET exitcode=1
GOTO printusage
@REM emptytagerror: Block for erroring out due to an empty tag being specified
:emptytagerror
echo.
powershell write-host -fore Red '[ERROR] No tag provided for %1'
SET exitcode=1
GOTO printusage
@REM emptyconfigerror: Block for erroring out due to an empty configuration being specified
:emptyconfigerror
echo.
powershell write-host -fore Red [ERROR] No configuration provided for %1
SET exitcode=1
GOTO printusage
@REM invalidconfigerror: Block for erroring out due to an invalid configuration being specified
:invalidconfigerror
echo.
powershell write-host -fore Red [ERROR] Bad run configuration: %config%
SET exitcode=1
GOTO printusage
@REM setnoopen: Block to set the flag to prevent opening of the dashboard in a browser
:setnoopen
SHIFT
SET no_open=true
GOTO loop
@REM settag: Block to set the chase-car-dashboard-image tag as specified by the CLAs
:settag
SET tag=%2
@REM Remove quotes around/in the tag value
@REM Need to check if config is truly empty to avoid errors with findstr below
IF "%tag%"=="" GOTO emptytagerror
IF %tag%=="" GOTO emptytagerror
IF %tag%=='' GOTO emptytagerror
SET tag=%tag:"=%
SET tag=%tag:'=%
echo %tag%|findstr /r /c:"^-.*"
IF errorlevel 1 (
IF "%tag%"=="" GOTO emptytagerror
) ELSE (
GOTO emptytagerror
)
SHIFT
SHIFT
GOTO loop
@REM setdisttag: Block to set the engineering-data-distributor-image tag as specified by the CLAs
:setdisttag
SET disttag=%2
@REM Remove quotes around/in the disttag value
@REM Need to check if config is truly empty to avoid errors with findstr below
IF "%disttag%"=="" GOTO emptytagerror
IF %disttag%=="" GOTO emptytagerror
IF %disttag%=='' GOTO emptytagerror
SET disttag=%disttag:"=%
SET disttag=%disttag:'=%
echo %disttag%|findstr /r /c:"^-.*"
IF errorlevel 1 (
IF "%disttag%"=="" GOTO emptytagerror
) ELSE (
GOTO emptytagerror
)
SHIFT
SHIFT
GOTO loop
@REM setconfig: Block to set the run configuration as specified by the CLAs
:setconfig
SET config=%2
@REM Remove quotes around/in the configuration value
@REM Need to check if config is truly empty to avoid errors with findstr below
IF "%config%"=="" GOTO emptyconfigerror
IF %config%=="" GOTO emptyconfigerror
IF %config%=='' GOTO emptyconfigerror
SET config=%config:"=%
SET config=%config:'=%
echo %config%|findstr /r /c:"^-.*"
IF errorlevel 1 (
IF "%config%"=="" GOTO emptyconfigerror
) ELSE (
GOTO emptyconfigerror
)
SET validconfig=no
IF "%config%"=="competition" SET validconfig=yes
IF "%config%"=="individual" SET validconfig=yes
IF "%config%"=="dev" SET validconfig=yes
IF "%validconfig%"=="no" GOTO invalidconfigerror
SHIFT
SHIFT
GOTO loop
:loop
IF NOT "%1"=="" (
@REM Reset tagaction, disttagaction, and configaction so that they do not run in the next iteration of the loop
SET tagaction=
SET disttagaction=
SET configaction=
@REM Handle no open options
IF "%1"=="-o" GOTO setnoopen
IF "%1"=="--no-open" GOTO setnoopen
@REM Handle tag options
IF "%1"=="-t" SET tagaction=set
IF "%1"=="--tag" SET tagaction=set
IF "%1"=="--tag=*" (
SET tagaction=set
)
@REM Set tag if parsing a tag option
IF "!tagaction!"=="set" (
@REM Check if a tag has already been set. If so, throw an error
IF NOT "%tag%"=="" (
GOTO multipletagserror
)
GOTO settag
)
@REM Handle dist tag options
IF "%1"=="-d" SET disttagaction=set
IF "%1"=="--dist-tag" SET disttagaction=set
IF "%1"=="--dist-tag=*" (
SET disttagaction=set
)
@REM Set disttag if parsing a dist tag option
IF "!disttagaction!"=="set" (
@REM Check if a disttag has already been set. If so, throw an error
IF NOT "%disttag%"=="" (
GOTO multipledisttagserror
)
GOTO setdisttag
)
@REM Handle configuration options
IF "%1"=="-c" SET configaction=set
IF "%1"=="--config" SET configaction=set
IF "%1"=="--config=*" (
SET configaction=set
)
@REM Set config if parsing a configuration option
IF "!configaction!"=="set" (
@REM Check if a configuration has already been set. If so, throw an error
IF NOT "%config%"=="" (
GOTO multipleconfigserror
)
GOTO setconfig
)
@REM Handle help options
IF "%1"=="-h" SET help=true
IF "%1"=="--help" SET help=true
IF "!help!"=="true" (
GOTO printusage
)
@REM If the argument was none of the above, it's invalid
GOTO badargerror
)
@REM Set default values for options that were not provided as command line arguments
IF "%tag%"=="" SET tag=latest
IF "%disttag%"=="" SET disttag=latest
IF "%config%"=="" SET config=individual
@REM Setting timezone correctly
for /f %%i in ('powershell -executionpolicy remotesigned -File .\convertTZstamp.ps1') do set timezone=%%i
@REM Pull the dashboard image
docker pull ghcr.io/badgerloop-software/chase-car-dashboard-image:%tag%
@REM Validate the version of the image if the "individual" configuration was specified
IF "%config%"=="individual" (
@REM Create a temporary container to parse package.json for the image's version. If it is lower than 3.8.0, making it
@REM incompatible with the "individual" configuration, store it in low_ver so that the script can exit below
> tempchasecardashboardversion.txt (
docker run --rm ghcr.io/badgerloop-software/chase-car-dashboard-image:%tag% bash -c "grep -oP '(?<=\"version\": \"^)^(\d^)+\.^(\d^)+\.^(\d^)+' package.json ^> v; if [[ $^(cut -d '.' -f 1 v^) -lt 3 ^|^| ^($^(cut -d '.' -f 1 v^) -eq 3 ^&^& $^(cut -d '.' -f 2 v^) -lt 8^) ]]; then cat v; fi"
)
SET /p low_ver=<tempchasecardashboardversion.txt
DEL tempchasecardashboardversion.txt
IF NOT "!low_ver!"=="" (
echo.
powershell write-host -fore Red '[ERROR] The specified chase-car-dashboard-image ^(v!low_ver!^) does not support the \"%config%\" configuration. The image must be v3.8.0 or newer.'
echo.
exit /b 1
)
@REM Pull the engineering-data-distributor image with the specified tag
docker pull ghcr.io/badgerloop-software/engineering-data-distributor-image:%disttag%
)
@REM Open the dashboard if no open wasn't specified
IF NOT "%no_open%"=="true" start http://localhost:3000
@REM Create the Docker volume
SET recdatapath=%cd%
mkdir recordedData
docker volume create --name chasecar --opt type=none --opt device=%recdatapath%/recordedData --opt o=bind
@REM Arguments that remain constant for all instances of running the Docker images
SET "const_chase_car_args=-e TZ=%timezone% -p 3000:3000 -p 4001:4001 -v chasecar:/chase-car-dashboard/Backend/recordedData/processedData ghcr.io/badgerloop-software/chase-car-dashboard-image:%tag%"
SET "const_data_dist_args=-i -a stdin -a stdout -a stderr ghcr.io/badgerloop-software/engineering-data-distributor-image:%disttag%"
@REM Run the image(s) according to the configuration specified
IF "%config%"=="competition" (
@REM Run the chase-car-dashboard image in the background and get container id
> tempchasecardashboardcid.txt (docker run -d %const_chase_car_args%)
SET /p cid=<tempchasecardashboardcid.txt
DEL tempchasecardashboardcid.txt
@REM Log output to file
docker logs cid
@REM Run chase car dashboard and redis
docker run --net=container:!cid! redis/redis-stack-server:latest
) ELSE IF "%config%"=="dev" (
@REM Run the chase-car-dashboard image in the background and get container id
> tempchasecardashboardcid.txt (docker run -d %const_chase_car_args% npm run start-dev)
SET /p cid=<tempchasecardashboardcid.txt
DEL tempchasecardashboardcid.txt
@REM Log output to file
docker logs cid
@REM Run chase car dashboard and redis
docker run --net=container:!cid! redis/redis-stack-server:latest
)
@REM #The server will be run at http://localhost:3000, it will take one to two minutes to start up
@REM #if this window does not automatically pop up then please enter the URL manually