-
Notifications
You must be signed in to change notification settings - Fork 34
/
curation.ps1
125 lines (106 loc) · 3.25 KB
/
curation.ps1
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
# this _should_ make powershell stop on first error, but apparently there are lots of edge cases. yay.
$ErrorActionPreference = "Stop"
function in_ci
{
return (Test-Path "env:CI") -and ($env:CI -eq "true")
}
function missing_required_env
{
param ([string]$name)
write-host "Required environment variable ""$name"" is missing or empty"
exit 1
}
if (($args.Count) -eq 0)
{
echo "At least one argument must be provided, and one must be the name of a service within docker-compose.yml"
exit 1
}
# args defined in docker-compose.yml
$uid=1000
$gid=1000
$user=(split-path -path $(Get-WMIObject -class Win32_ComputerSystem | select username).username -leaf)
write-host "Running as user ""$user""..."
$pwd=(get-location)
$dkr_run_args = @(
"compose",
"run",
"-v", """${pwd}/.git:/home/curation/project/curation/.git""",
"-v", """${pwd}/data_steward:/home/curation/project/curation/data_steward""",
"-v", """${pwd}/tests:/home/curation/project/curation/tests""",
"-v", """${pwd}/tools:/home/curation/project/curation/tools""",
"-v", """${pwd}/.circleci:/home/curation/project/curation/.circleci"""
)
# If running specific tests using env var
if ((Test-Path "env:CURATION_TESTS_FILEPATH") -and (-not ($env:CURATION_TESTS_FILEPATH -eq "") ))
{
$tests_path = (Resolve-Path $env:CURATION_TESTS_FILEPATH)
$dkr_run_args += "-v"
$dkr_run_args += """${tests_path}:/tests-to-run.txt"""
$dkr_run_args += "-e"
$dkr_run_args += """CURATION_TESTS_FILEPATH=/tests-to-run.txt"""
}
if (-not (in_ci))
{
write-host "Running outside of CI"
if ((-not (Test-Path "env:GOOGLE_APPLICATION_CREDENTIALS")) -or ($env:GOOGLE_APPLICATION_CREDENTIALS -eq ""))
{
(missing_required_env "GOOGLE_APPLICATION_CREDENTIALS")
}
$gcreds=$env:GOOGLE_APPLICATION_CREDENTIALS
write-host "Ensuring image is up to date..."
$build_args=@(
"compose",
"build",
"--build-arg", "UID=${uid}",
"--build-arg", "GID=${gid}",
"--quiet",
"develop"
)
& docker @build_args
if ($lastexitcode -ne 0)
{
write-host "Error(s) occurred while building image"
exit 1
}
# add gcreds path volume mount to runtime args
$dkr_run_args += "-v"
$dkr_run_args += """${gcreds}:/home/curation/project/curation/aou-res-curation-test.json"""
}
else
{
write-host "Running in CI."
}
# finally, add any / all remaining args provided to this script as args to pass into docker
# If the arg list contains "--", assume this to be the separation point between flags to send to
# docker compose, and the container entrypoint command.
#
# Otherwise, assume entire list is to be sent to container entrypoint
#
# This is necessary as we need to inject the name of the service defined within docker-compose.yaml that we want to
# run in-between the flags intended for `docker compose run` and container entrypoint.
if ($args -match "--")
{
$at_command=0
foreach ($a in $args)
{
if (($a -eq "--") -and ($at_command -eq 0))
{
$at_command=1
$dkr_run_args+="develop"
}
else
{
$dkr_run_args += $a
}
}
}
else
{
$dkr_run_args+="develop"
foreach ($a in $args)
{
$dkr_run_args += $a
}
}
# do the thing.
& docker @dkr_run_args