-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.ps1
118 lines (96 loc) · 3.46 KB
/
package.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
param(
[Parameter(ParameterSetName="CreateEnvFile",
HelpMessage="If .env file doesn't exist, one will be created for you with default values",
Mandatory=$False)]
[string]$createEnvFile=$False,
[Parameter(ParameterSetName="DeployArtifactPath",
HelpMessage="Location to use when packaging artifacts",
Mandatory=$False)]
[string]$artifactPath
)
$scriptPath = Split-Path $MyInvocation.MyCommand.Path -Parent
. $scriptPath\SetPsEnv.ps1
# If env file doesn't exist AND we want to initialize file...
if(-not(Test-Path -Path "$scriptPath\.env") -and $createEnvFile) {
Write-Output "An Environment file does not exist on your machine. We'll create one!"
if([string]::IsNullOrEmpty($artifactPath))
{
Write-Output "You need to give us an artifact location to use! Please provide the`DeployArtifactPath` parameter"
exit 1
}
$path = "$scriptPath\.env"
New-Item $path
$defaultContents = "
artifactPath=$artifactPath
overwrite=true
"
Set-Content $path $defaultContents
Write-Output "Environment file created!"
Write-Output $defaultContents
}
Set-PsEnv
$deploy = [System.Environment]::GetEnvironmentVariable("artifactPath")
$overwrite = [System.Environment]::GetEnvironmentVariable("overwrite")
$apiPath = "$deploy\api"
$dbPath = "$deploy\db"
if(-not(Test-Path -Path $dbPath))
{
Write-Output "Creating Db Deployment Directory..."
New-Item -Type Directory -Path $dbPath
}
if(Test-Path -Path $dbPath\docker-compose.yml)
{
if($overwrite)
{
Write-Output "Copying newer version of docker-compose-db.yml"
Remove-Item $dbPath\docker-compose.yml
Copy-Item $scriptPath\docker-compose-db.yml -Destination $dbPath\docker-compose.yml
Write-Output "Ensuring Db run script is up-to-date..."
Remove-Item $dbPath\run.ps1
New-Item $dbPath\run.ps1
Set-Content $dbPath\run.ps1 "docker-compose up -d"
}
}
else
{
Write-Output "Copying `docker-compose-db.yml` as `docker-compose.yml` to $dbPath"
Copy-Item $scriptPath\docker-compose-db.yml -Destination $dbPath\docker-compose.yml
Write-Output "Creating Db run script..."
New-Item $dbPath\run.ps1
Set-Content $dbPath\run.ps1 "docker-compose up -d"
}
if(-not(Test-Path -Path $apiPath))
{
Write-Output "Creating API Deployment Directory..."
New-Item -Type Directory -Path $apiPath
}
if(Test-Path -Path $apiPath\docker-compose.yml)
{
if($overwrite) {
Write-Output "Copying new version of `docker-compose-api.yml` to `docker-compose.yml` at $apiPath"
Remove-Item $apiPath\docker-compose.yml
Copy-Item $scriptPath\docker-compose-api.yml -Destination $apiPath\docker-compose.yml
}
}
else
{
Write-Output "Copying `docker-compose-api.yml` to `docker-compose.yml` at $apiPath"
Copy-Item $scriptPath\docker-compose-api.yml -Destination $apiPath\docker-compose.yml
}
if(Test-Path -Path $apiPath\appsettings.json)
{
if($overwrite)
{
Write-Output "Copying new version of `appsettings.json` at $apiPath"
Remove-Item $apiPath\appsettings.json
Copy-Item $scriptPath\Api\appsettings.json -Destination $apiPath\appsettings.json
}
}
else
{
Write-Output "Copying `appsettings.json` at $apiPath"
Copy-Item $scriptPath\Api\appsettings.json
}
Write-Output "Building Api Docker Image..."
docker build -f $scriptPath\Api\Dockerfile -t social-coder-api .
Write-Output "Packaging Complete..."