-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows.conf
62 lines (47 loc) · 2.44 KB
/
windows.conf
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
<powershell>
# Disable firewall
netsh advfirewall set allprofiles state off
# Install python
$python_version = "3.11.8"
Invoke-WebRequest "https://www.python.org/ftp/python/$python_version/python-${python_version}-amd64.exe" -OutFile C:\Windows\Temp\python.exe -UseBasicParsing
Start-Process C:\Windows\Temp\python.exe -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1" -NoNewWindow -Wait
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# Install nginx
$nginx_version = "nginx-1.25.4"
Invoke-WebRequest "https://nginx.org/download/${nginx_version}.zip" -OutFile C:\Windows\Temp\nginx.zip -UseBasicParsing
Expand-Archive C:\Windows\Temp\nginx.zip C:\Windows\Temp -Force
Copy-Item "C:\Windows\Temp\$nginx_version" C:\nginx -Recurse -Force
# Install the Non-Sucking Service Manager
$nssm_version = "nssm-2.24"
Invoke-WebRequest "https://nssm.cc/release/${nssm_version}.zip" -OutFile C:\Windows\Temp\nssm.zip -UseBasicParsing
Expand-Archive C:\Windows\Temp\nssm.zip C:\Windows\Temp -Force
Copy-Item "C:\Windows\Temp\$nssm_version" C:\nssm -Recurse -Force
# Download repo
Invoke-WebRequest https://github.com/RFCreate/ec2-webpage/archive/refs/heads/main.zip -OutFile C:\Windows\Temp\repo.zip -UseBasicParsing
Expand-Archive C:\Windows\Temp\repo.zip C:\Windows\Temp
# Copy python app to root directory
Copy-Item C:\Windows\Temp\ec2-webpage-main\flask-nginx\app C:\ -Recurse -Force
# Create and activate virtual environment
python -m venv C:\app\.venv
& C:\app\.venv\Scripts\Activate.ps1
# Install pip requirements
pip install -r C:\app\requirements.txt
# Set nginx config
Copy-Item C:\Windows\Temp\ec2-webpage-main\flask-nginx\nginx.conf C:\nginx\conf\default.conf -Force
# Add 'include default.conf' line before server{} in nginx.conf
Get-Content "C:\Windows\Temp\$nginx_version\conf\nginx.conf" |
ForEach-Object {
if ($_ -cmatch "^\s+server\s?\{") {
Write-Output " include default.conf;`n"
}
Write-Output $_
} | Set-Content C:\nginx\conf\nginx.conf
# Create flask service to start automatically
C:\nssm\win64\nssm.exe install "Flask-App" "C:\app\.venv\Scripts\python.exe" "C:\app\app.py"
# Start flask service
C:\nssm\win64\nssm.exe start "Flask-App"
# Create nginx service to start automatically
C:\nssm\win64\nssm.exe install "Nginx-Flask" "C:\nginx\nginx.exe"
# Start nginx service
C:\nssm\win64\nssm.exe start "Nginx-Flask"
</powershell>