-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstart-local-env.ps1
104 lines (95 loc) · 2.44 KB
/
start-local-env.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
## SQL
# Create volumes
# Run MySQL container
function Start-MySQLContainer {
docker volume create --name mysql8-data
docker volume create --name mysql8-conf
# Must specify --all to get stopped containers
$ExistingId = docker container list --all --quiet --filter name=mysql
if ($ExistingId) {
docker container start mysql
}
else {
docker container run --detach --name mysql `
--hostname mysql `
-p 3308:3306 `
--env MYSQL_DATABASE=canopeum_db `
--env MYSQL_ROOT_PASSWORD=Canopeum12345!@ `
--env MYSQL_USER=canopeum_user `
--env MYSQL_PASSWORD=CanopeumUser12345!@ `
--volume mysql8-data:/var/lib/mysql `
--volume mysql8-conf:/etc/mysql/conf.d mysql:8
}
}
# Backend
# Update virtual environment / Install dependencies
# Run Django server
$commandsBackend = @'
cd canopeum_backend
uv sync --locked
uv run manage.py runserver
'@
# Frontend
# Install dependencies
# Run React Vite server
$commandsFrontend = @'
cd canopeum_frontend
npm install
npm run dev
'@
# Initialize database
$commandsInitializeDatabase = @'
cd canopeum_backend
uv run manage.py initialize_database
cd ..
'@
# Generate OpenAPI specs
$commandsGenerateOpenAPI = @'
cd canopeum_frontend
npm run generate-api-client
cd ..
'@
function Show-Menu {
param (
[string]$Title = 'Run Local Environment'
)
Write-Host "================ $Title ================"
Write-Host '1: Run all services'
Write-Host '2: Run MySQL container'
Write-Host '3: Run Django server'
Write-Host '4: Run React Vite server'
Write-Host '5: Initialize database'
Write-Host '6: Generate OpenAPI specs'
Write-Host 'Q: Quit'
}
do {
Show-Menu
$userInput = Read-Host 'Please make a selection'
# Use Invoke-Expression to run in the same window if the command isn't long-running
switch ($userInput) {
'1' {
Start-MySQLContainer
Start-Process powershell -ArgumentList '-NoExit', '-Command', $commandsBackend
Start-Process powershell -ArgumentList '-NoExit', '-Command', $commandsFrontend
}
'2' {
Start-MySQLContainer
}
'3' {
Start-Process powershell -ArgumentList '-NoExit', '-Command', $commandsBackend
}
'4' {
Start-Process powershell -ArgumentList '-NoExit', '-Command', $commandsFrontend
}
'5' {
Invoke-Expression $commandsInitializeDatabase
}
'6' {
Invoke-Expression $commandsGenerateOpenAPI
}
'q' {
break
}
}
}
until ($true)