-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildScript.ps1
67 lines (57 loc) · 1.42 KB
/
buildScript.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
$BINARY_NAME = "myapp"
$DSN = "host=localhost port=5432 user=postgres password=password dbname=concurrency sslmode=disable timezone=UTC connect_timeout=5"
$REDIS = "127.0.0.1:6379"
function StartDocker {
Write-Output "Starting Docker containers..."
docker-compose up -d
Write-Output "Docker containers started."
}
function StopDocker {
Write-Output "Stopping Docker containers..."
docker-compose down
Write-Output "Docker containers stopped."
}
function Build {
Write-Output "Building..."
$env:CGO_ENABLED = "0"
go build -ldflags="-s -w" -o $BINARY_NAME ./cmd/web
Remove-Item env:CGO_ENABLED
Write-Output "Built!"
}
function Run {
StartDocker
Build
Write-Output "Starting application..."
$env:DSN = $DSN
$env:REDIS = $REDIS
Start-Process -FilePath ".\$BINARY_NAME" -NoNewWindow
Write-Output "Application started."
}
function Clean {
Write-Output "Cleaning..."
go clean
Remove-Item $BINARY_NAME
Write-Output "Cleaned!"
}
function Start {
Run
}
function Stop {
Write-Output "Stopping application..."
Get-Process | Where-Object {$_.Path -eq (Resolve-Path $BINARY_NAME)} | Stop-Process -Force
StopDocker
Write-Output "Application stopped."
}
function Restart {
Stop
Start
}
function Test {
Write-Output "Testing..."
go test -v ./...
}
# Example usage: Uncomment the function call you wish to execute.
Run
# Clean
# Stop
# Test