Compare commits
12 Commits
253d998b68
...
v0.0.1-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| cc51807819 | |||
| 8e039037a9 | |||
| ed40f4c77e | |||
| ccddef8ba8 | |||
| 05e31f4b9e | |||
| d2578b8850 | |||
| 392a9ef407 | |||
| 2d2337257f | |||
| 5a95bf3ef0 | |||
| 7e9401d8bb | |||
| 0c4465c91a | |||
| 5f9d49561a |
22
.env-example
22
.env-example
@@ -1,14 +1,18 @@
|
||||
# Change to production when ready to deploy in docker or iis
|
||||
APP_ENV=dev
|
||||
# uncomment this out to run in productions
|
||||
# APP_ENV=production
|
||||
|
||||
# lstv2 loc
|
||||
LSTV2="C\drive\loc"
|
||||
|
||||
# dev stuff below
|
||||
|
||||
# Gitea Info
|
||||
GITEA_URL=git.tuffraid.net
|
||||
GITEA_USERNAME=cowch
|
||||
GITEA_URL=git repo
|
||||
GITEA_USERNAME=username
|
||||
GITEA_REPO=logistics_support_tool
|
||||
GITEA_TOKEN=ad8eac91a01e3a1885a1dc10
|
||||
|
||||
# Build number info
|
||||
BUILD_NAME=rushjnnhj7212n
|
||||
|
||||
# lstv2 loc
|
||||
LSTV2=C\drive\loc
|
||||
# dev locs
|
||||
DEV_FOLDER=C\drive\loc
|
||||
ADMUSER=username
|
||||
ADMPASSWORD=password
|
||||
55
CHANGELOG.md
55
CHANGELOG.md
@@ -3,6 +3,61 @@
|
||||
All notable changes to LST will be documented in this file.
|
||||
|
||||
|
||||
## [0.0.1-alpha.5](https://git.tuffraid.net/cowch/logistics_support_tool/compare/v0.0.1-alpha.4...v0.0.1-alpha.5) (2025-07-21)
|
||||
|
||||
### 🌟 Enhancements
|
||||
|
||||
* **backend:** env added ([67b5976](https://git.tuffraid.net/cowch/logistics_support_tool/commit/67b59761769350951bc6b52ef715b592b5d4a862))
|
||||
* **backend:** set the static path to the docs ([5a9636c](https://git.tuffraid.net/cowch/logistics_support_tool/commit/5a9636cdc15f164ed3547f544e34858683b38241))
|
||||
* **docs:** added in the new docs to build alongside the backend ([3fdcc11](https://git.tuffraid.net/cowch/logistics_support_tool/commit/3fdcc110e3b4d7356af1fb025070bdf7413a8e88))
|
||||
* **env-example:** added in an example env ([a23b6a6](https://git.tuffraid.net/cowch/logistics_support_tool/commit/a23b6a6e9eef4dbeb2f84c325ca8dca178ab3ff3))
|
||||
* **env:** new env introduced to handle dev and prodution ([f41a1b3](https://git.tuffraid.net/cowch/logistics_support_tool/commit/f41a1b336389d6100e42681f53d9f618c8726f25))
|
||||
* **services:** just a 1 to 1 from lstv2 ([8e03903](https://git.tuffraid.net/cowch/logistics_support_tool/commit/8e039037a9b40994b9e77f59680a3ce1b6ebc3a0))
|
||||
* **update server:** new update server added with iis stop and old version included ([05e31f4](https://git.tuffraid.net/cowch/logistics_support_tool/commit/05e31f4b9e20799257da244b237420fa2b6435f8))
|
||||
|
||||
### 🐛 Bug fixes
|
||||
|
||||
* **backend:** ignored docs this should be built before running by the user ([fdf14b0](https://git.tuffraid.net/cowch/logistics_support_tool/commit/fdf14b06c88d3057f31184e03fb592bd9a959847))
|
||||
* **builds:** added in the gets/installs for our go project and node portons ([528d7af](https://git.tuffraid.net/cowch/logistics_support_tool/commit/528d7af0312cb3de43ddc93d8af22bde6aadea52))
|
||||
* **docs:** added a copy script to cp the build to the backend with ps1 ([0fb2ec5](https://git.tuffraid.net/cowch/logistics_support_tool/commit/0fb2ec52739def8294a57bbc6c497ba6531568a6))
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
* **env:** changes to have more clear info on the example doc ([5f9d495](https://git.tuffraid.net/cowch/logistics_support_tool/commit/5f9d49561a7c22a4d2cb85bd06bbbdb9fa952224))
|
||||
* **iiscontrol:** added in an example how to run i t ([ccddef8](https://git.tuffraid.net/cowch/logistics_support_tool/commit/ccddef8ba8f64774db6d99fba3ea7c7c54bea1a5))
|
||||
|
||||
### 🛠️ Code Refactor
|
||||
|
||||
* **backend:** changes to convert the backend to strictly the app ([1e649d1](https://git.tuffraid.net/cowch/logistics_support_tool/commit/1e649d1f23c404252754d746254810386bb0f233))
|
||||
* **build:** changes to remove the build name as it was not really realvent ([392a9ef](https://git.tuffraid.net/cowch/logistics_support_tool/commit/392a9ef407d4e64f573cbfc9109c8a81f55c14d5))
|
||||
* **config:** changes to autoformat go files ([4ef2d90](https://git.tuffraid.net/cowch/logistics_support_tool/commit/4ef2d90aa8595d5e3d18a289c012320bdf0dcc4a))
|
||||
* **createzip:** added in verbage to be clear what was done at the end ([452bdbe](https://git.tuffraid.net/cowch/logistics_support_tool/commit/452bdbedb48cde7fa0ef246fb61e304127c49e58))
|
||||
* **createzip:** changes to the way the app looks for better understanding ([d2578b8](https://git.tuffraid.net/cowch/logistics_support_tool/commit/d2578b885029ca98b750f4c6996e567053b2e517))
|
||||
* **createzip:** renamed the backend to app now that everything is in one ([0c4465c](https://git.tuffraid.net/cowch/logistics_support_tool/commit/0c4465c91a40cbea73048617952df26b476d01f4))
|
||||
* **docker:** removed frontend from being built ([9acfd1c](https://git.tuffraid.net/cowch/logistics_support_tool/commit/9acfd1ccd0b9019d5acc01153ddad15b82b6c74e))
|
||||
* **env-example:** changes to the env example to include the dev stuff ([2d23372](https://git.tuffraid.net/cowch/logistics_support_tool/commit/2d2337257f2b31c740f9eb7064be010528e14c7c))
|
||||
* **frontend:** changes to no longer use server side and only static files ([39d23f4](https://git.tuffraid.net/cowch/logistics_support_tool/commit/39d23f4a8a8af6b1acb87b913e5cd1929fe144e4))
|
||||
* **lstv2build:** changes to not always build the old app if we dont need too ([ed40f4c](https://git.tuffraid.net/cowch/logistics_support_tool/commit/ed40f4c77e9d81e36292f38c342e9c2b062f84b9))
|
||||
* **lstv2:** moved the loc to .env file ([7539b16](https://git.tuffraid.net/cowch/logistics_support_tool/commit/7539b1653d7a48dbe248847ed321ab065e58efa0))
|
||||
* **wrapper:** changes to handle docs and frontned now ([253d998](https://git.tuffraid.net/cowch/logistics_support_tool/commit/253d998b68b5808d6fd2d9731255616238fcdb71))
|
||||
|
||||
### 🚀 Performance
|
||||
|
||||
* **docs:** changes to stop the server from opening a browser when it started up ([f0bcea0](https://git.tuffraid.net/cowch/logistics_support_tool/commit/f0bcea0405db364e1e15471b5db74fc9d8f93788))
|
||||
|
||||
### 📝 Testing Code
|
||||
|
||||
* **app:** added production into the build so we dont fill logs up ([7e9401d](https://git.tuffraid.net/cowch/logistics_support_tool/commit/7e9401d8bb12589de6ce1517e4502d784788ab0f))
|
||||
* **docker:** changes to make all latest now instead of 2 apps ([5a95bf3](https://git.tuffraid.net/cowch/logistics_support_tool/commit/5a95bf3ef0f4d4b125f8e777d57cc96b3d3a894d))
|
||||
|
||||
### 📈 Project changes
|
||||
|
||||
* **wrapper:** changes to clean the publish folder ([5cc1fbe](https://git.tuffraid.net/cowch/logistics_support_tool/commit/5cc1fbe919a8c3fa46617f7b9ed2830559b8978f))
|
||||
|
||||
### 📈 Project Builds
|
||||
|
||||
* **docs:** added building the docs into the build script ([6072afc](https://git.tuffraid.net/cowch/logistics_support_tool/commit/6072afc8c01a4fe4980e0e17cfe41d5a9cd524ef))
|
||||
|
||||
## [0.0.1-alpha.4](https://git.tuffraid.net/cowch/logistics_support_tool/compare/v0.0.1-alpha.3...v0.0.1-alpha.4) (2025-07-16)
|
||||
|
||||
### 📈 Project changes
|
||||
|
||||
@@ -21,6 +21,7 @@ func main() {
|
||||
|
||||
// Set basePath dynamically
|
||||
basePath := "/"
|
||||
|
||||
if os.Getenv("APP_ENV") != "production" {
|
||||
basePath = "/lst" // Dev only
|
||||
}
|
||||
@@ -29,6 +30,10 @@ func main() {
|
||||
fmt.Println("Welcome to lst backend where all the fun happens.")
|
||||
r := gin.Default()
|
||||
|
||||
if os.Getenv("APP_ENV") == "production" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// // --- Add Redirects Here ---
|
||||
// // Redirect root ("/") to "/app" or "/lst/app"
|
||||
// r.GET("/", func(c *gin.Context) {
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
---
|
||||
services:
|
||||
lst_backend:
|
||||
# build: . # Tell Docker Compose to build the image using the Dockerfile in the current directory
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./backend/Dockerfile
|
||||
image: git.tuffraid.net/cowch/logistics_support_tool:backend-latest
|
||||
container_name: lst_backend # A friendly name for your running container
|
||||
no_cache: true
|
||||
image: git.tuffraid.net/cowch/logistics_support_tool:latest
|
||||
container_name: lst_backend
|
||||
volumes:
|
||||
- /path/to/backend/data:/data
|
||||
ports:
|
||||
- "8080:8080"
|
||||
restart: unless-stopped
|
||||
|
||||
lst_frontend:
|
||||
# build: . # Tell Docker Compose to build the image using the Dockerfile in the current directory
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./frontend/Dockerfile
|
||||
image: git.tuffraid.net/cowch/logistics_support_tool:frontend-latest
|
||||
container_name: lst_frontend # A friendly name for your running container
|
||||
volumes:
|
||||
- /path/to/frontend/data:/data
|
||||
ports:
|
||||
- "3120:3000"
|
||||
restart: unless-stopped
|
||||
pull_policy: never
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "logistics_support_tool",
|
||||
"version": "0.0.1-alpha.4",
|
||||
"version": "0.0.1-alpha.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "logistics_support_tool",
|
||||
"version": "0.0.1-alpha.4",
|
||||
"version": "0.0.1-alpha.5",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.2.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "logistics_support_tool",
|
||||
"version": "0.0.1-alpha.4",
|
||||
"version": "0.0.1-alpha.5",
|
||||
"description": "This is the new logisitcs support tool",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
|
||||
@@ -26,10 +26,10 @@ if (Test-Path $envFile) {
|
||||
Write-Host ".env file not found at $envFile"
|
||||
}
|
||||
|
||||
if (-not $env:BUILD_NAME) {
|
||||
Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
||||
exit 1
|
||||
}
|
||||
# if (-not $env:BUILD_NAME) {
|
||||
# Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
||||
# exit 1
|
||||
# }
|
||||
|
||||
function Get-PackageVersion {
|
||||
param (
|
||||
@@ -78,7 +78,7 @@ function Update-BuildNumber {
|
||||
$name = $matches[2]
|
||||
|
||||
$newNumber = $number + 1
|
||||
$newBuildNumber = "$newNumber-$name"
|
||||
$newBuildNumber = "$newNumber"
|
||||
|
||||
Set-Content -Path $buildNumberFile -Value $newBuildNumber
|
||||
|
||||
@@ -95,14 +95,14 @@ function Update-BuildNumber {
|
||||
Push-Location $rootDir/backend
|
||||
Write-Host "Building the app"
|
||||
go get
|
||||
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_backend.exe ./main.go
|
||||
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_app.exe ./main.go
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Warning "Backend build failed!"
|
||||
Write-Warning "app build failed!"
|
||||
Pop-Location
|
||||
break
|
||||
}
|
||||
|
||||
Write-Host "Backend build finished successfully."
|
||||
Write-Host "app build finished successfully."
|
||||
|
||||
Pop-Location
|
||||
|
||||
@@ -123,10 +123,10 @@ function Update-BuildNumber {
|
||||
Write-Host "Building wrapper"
|
||||
Push-Location $rootDir/LstWrapper
|
||||
#remove the publish folder as we done need it
|
||||
if (-not (Test-Path "/publish")) {
|
||||
if (-not (Test-Path "publish")) {
|
||||
Write-Host "The publish folder is already deleted nothing else to do"
|
||||
} else {
|
||||
Remove-Item -LiteralPath "/publish" -Force -Recurse
|
||||
Remove-Item -LiteralPath "publish" -Force -Recurse
|
||||
}
|
||||
|
||||
dotnet publish -c Release -o ./publish
|
||||
|
||||
@@ -71,9 +71,9 @@ $tempStageDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "lst_sta
|
||||
|
||||
# Copy files to organized structure
|
||||
$filesToCopy = @(
|
||||
@{ Source = "backend\lst_backend.exe"; Destination = "backend\lst_backend.exe" },
|
||||
@{ Source = "backend\docs"; Destination = "backend\docs\" },
|
||||
@{ Source = "backend\frontend"; Destination = "backend\frontend\" },
|
||||
@{ Source = "backend\lst_app.exe"; Destination = "app\lst_app.exe" },
|
||||
@{ Source = "backend\docs"; Destination = "app\docs\" },
|
||||
@{ Source = "backend\frontend"; Destination = "app\frontend\" },
|
||||
@{ Source = "LstWrapper\publish"; Destination = "lstwrapper\" },
|
||||
#@{ Source = "frontend\.nitro"; Destination = "frontend\.nitro" },
|
||||
#@{ Source = "frontend\.tanstack"; Destination = "frontend\.tanstack" },
|
||||
@@ -85,6 +85,7 @@ $filesToCopy = @(
|
||||
# scripts to be copied over
|
||||
@{ Source = "scripts\tmp"; Destination = "tmp" }
|
||||
@{ Source = "scripts\iisControls.ps1"; Destination = "scripts\iisControls.ps1" }
|
||||
@{ Source = "scripts\services.ps1"; Destination = "scripts\services.ps1" }
|
||||
# docs
|
||||
# @{ Source = "lst-docs\build"; Destination = "lst-docs\build" }
|
||||
)
|
||||
@@ -103,7 +104,7 @@ Remove-Item $tempStageDir -Recurse -Force
|
||||
|
||||
Write-Host "`nRelease package created at: $($zipPath)"
|
||||
Write-Host "Organized structure:"
|
||||
Write-Host "- backend/"
|
||||
Write-Host "- app/"
|
||||
Write-Host "- frontend/"
|
||||
Write-Host "- lstwrapper/"
|
||||
Write-Host "- scripts/"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
Write-Host "Building the docker images for front and backend"
|
||||
#docker build -t logistics_support_tool:frontend-latest -f ./frontend/Dockerfile --no-cache ./frontend
|
||||
docker build -t logistics_support_tool:backend-latest -f ./backend/Dockerfile --no-cache ./backend
|
||||
docker build -t logistics_support_tool:latest -f ./backend/Dockerfile --no-cache ./backend
|
||||
|
||||
Write-Host "Tagging the builds with latest this is for testing test basically."
|
||||
#docker tag logistics_support_tool:frontend-latest git.tuffraid.net/cowch/logistics_support_tool:frontend-latest
|
||||
docker tag logistics_support_tool:backend-latest git.tuffraid.net/cowch/logistics_support_tool:latest
|
||||
docker tag logistics_support_tool:latest git.tuffraid.net/cowch/logistics_support_tool:latest
|
||||
|
||||
# docker build -t logistics_support_tool:frontend-latest --no-cache .
|
||||
Write-Host "Push both builds to our gitea server."
|
||||
|
||||
@@ -4,6 +4,9 @@ param (
|
||||
[string]$StopOrStart
|
||||
)
|
||||
|
||||
# Example string to run with the parameters in it.
|
||||
# .\iisControls.ps1 -ServerName "usmcd1vms036" -AppPoolName "LogisticsSupportTool" -StopOrStart "stop"
|
||||
|
||||
write-host $StopOrStart
|
||||
if ($StopOrStart -eq "stop") {
|
||||
Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock {
|
||||
|
||||
@@ -36,11 +36,20 @@ function Build-LstV2-And-Copy {
|
||||
New-Item -Path $scriptDir -Name "tmp" -ItemType "Directory"
|
||||
}
|
||||
|
||||
Write-Host "Jumping into lstV2 to build it."
|
||||
$defaultChoice = "n"
|
||||
$input = Read-Host "Do we want to build lstV2? (Y/n) [$defaultChoice]"
|
||||
|
||||
$choice = if ([string]::IsNullOrWhiteSpace($input)) { $defaultChoice } else { $input.ToLower() }
|
||||
|
||||
if($choice -eq "n"){
|
||||
Write-Host "Just going to copy the latest build over as we dont want to build a new one."
|
||||
} else {
|
||||
Write-Host "Jumping into lstV2 to build it."
|
||||
Push-Location $lstv2Loc
|
||||
npm run build
|
||||
|
||||
Write-Host "LSTV2 Finished building."
|
||||
}
|
||||
|
||||
Write-Host "Copy the latest build to the tmpLoc"
|
||||
|
||||
|
||||
207
scripts/services.ps1
Normal file
207
scripts/services.ps1
Normal file
@@ -0,0 +1,207 @@
|
||||
param (
|
||||
[string]$serviceName,
|
||||
[string]$option,
|
||||
[string]$appPath,
|
||||
[string]$command, # just the command like run start or what ever you have in npm.
|
||||
[string]$description,
|
||||
[string]$remote,
|
||||
[string]$server,
|
||||
[string]$username,
|
||||
[string]$admpass
|
||||
)
|
||||
|
||||
# Example string to run with the parameters in it.
|
||||
# .\scripts\services.ps1 -serviceName "LST_app" -option "install" -appPath "E:\LST" -description "Logistics Support Tool in go" -command "E:\LST\app\lst_app.exe"
|
||||
|
||||
$nssmPath = $AppPath + "\nssm.exe"
|
||||
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
||||
|
||||
# Convert the plain-text password to a SecureString
|
||||
$securePass = ConvertTo-SecureString $admpass -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||
|
||||
if($remote -eq "true"){
|
||||
|
||||
# if(-not $username -or -not $admpass){
|
||||
# Write-host "Missing adm account info please try again."
|
||||
# exit 1
|
||||
# }
|
||||
|
||||
$plantFunness = {
|
||||
param ($service, $processType, $location)
|
||||
# Call your PowerShell script inside plantFunness
|
||||
# & "$($location)\dist\server\scripts\services.ps1" -serviceName $service -option $processType -appPath $location
|
||||
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
Write-Host "Error: This script must be run as Administrator."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if(-not $service -or -not $processType){
|
||||
Write-host "The service name or option is missing please enter one of them and try again."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($processType -eq "start"){
|
||||
write-host "Starting $($service)."
|
||||
Start-Service $service
|
||||
}
|
||||
|
||||
if ($processType -eq "stop"){
|
||||
write-host "Stoping $($service)."
|
||||
Stop-Service $service
|
||||
}
|
||||
|
||||
if ($processType -eq "restart"){
|
||||
write-host "Stoping $($service) to be restarted"
|
||||
Stop-Service $service
|
||||
Start-Sleep 3 # so we give it enough time to fully stop
|
||||
write-host "Starting $($service)"
|
||||
Start-Service $service
|
||||
}
|
||||
|
||||
if ($processType -eq "prodStop"){
|
||||
if(-not $location){
|
||||
Write-host "The path to the app is missing please add it in and try again."
|
||||
exit 1
|
||||
}
|
||||
& $nssmPath stop $service
|
||||
write-host "Removing $($service)"
|
||||
#& $nssmPath remove $serviceName confirm
|
||||
sc.exe config $service start= disabled
|
||||
|
||||
}
|
||||
|
||||
if ($processType -eq "prodStart"){
|
||||
if(-not $location){
|
||||
Write-host "The path to the app is missing please add it in and try again."
|
||||
exit 1
|
||||
}
|
||||
& $nssmPath start $service
|
||||
write-host "Removing $($service)"
|
||||
#& $nssmPath remove $serviceName confirm
|
||||
sc.exe config $service start= auto
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Invoke-Command -ComputerName $server -ScriptBlock $plantFunness -ArgumentList $serviceName, $option, $appPath -Credential $credentials
|
||||
} else {
|
||||
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
Write-Host "Error: This script must be run as Administrator."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if(-not $serviceName -or -not $option){
|
||||
Write-host "The service name or option is missing please enter one of them and try again."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($option -eq "start"){
|
||||
write-host "Starting $($serviceName)."
|
||||
Start-Service $serviceName
|
||||
}
|
||||
|
||||
if ($option -eq "stop"){
|
||||
write-host "Stoping $($serviceName)."
|
||||
Stop-Service $serviceName
|
||||
}
|
||||
|
||||
if ($option -eq "restart"){
|
||||
write-host "Stoping $($serviceName) to be restarted"
|
||||
Stop-Service $serviceName
|
||||
Start-Sleep 3 # so we give it enough time to fully stop
|
||||
write-host "Starting $($serviceName)"
|
||||
Start-Service $serviceName
|
||||
}
|
||||
|
||||
if ($option -eq "delete"){
|
||||
if(-not $appPath){
|
||||
Write-host "The path to the app is missing please add it in and try again."
|
||||
exit 1
|
||||
}
|
||||
& $nssmPath stop $serviceName
|
||||
write-host "Removing $($serviceName)"
|
||||
& $nssmPath remove $serviceName confirm
|
||||
|
||||
}
|
||||
|
||||
if ($option -eq "prodStop"){
|
||||
if(-not $appPath){
|
||||
Write-host "The path to the app is missing please add it in and try again."
|
||||
exit 1
|
||||
}
|
||||
& $nssmPath stop $serviceName
|
||||
write-host "Removing $($serviceName)"
|
||||
#& $nssmPath remove $serviceName confirm
|
||||
sc.exe config $serviceName start= disabled
|
||||
|
||||
}
|
||||
|
||||
if ($option -eq "prodStart"){
|
||||
if(-not $appPath){
|
||||
Write-host "The path to the app is missing please add it in and try again."
|
||||
exit 1
|
||||
}
|
||||
& $nssmPath start $serviceName
|
||||
write-host "Removing $($serviceName)"
|
||||
#& $nssmPath remove $serviceName confirm
|
||||
sc.exe config $serviceName start= auto
|
||||
|
||||
}
|
||||
|
||||
if($option -eq "install"){
|
||||
if(-not $appPath -or -not $description -or -not $command){
|
||||
Write-host "Please check all parameters are passed to install the app.."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
|
||||
|
||||
if(-not $service){
|
||||
write-host $serviceName "is not installed we will install it now"
|
||||
|
||||
Write-Host "Installing $serviceName..."
|
||||
if($command.Contains(".exe")){
|
||||
|
||||
& $nssmPath install $serviceName $command
|
||||
|
||||
$fullAppPath = "$appPath\app"
|
||||
& $nssmPath set $serviceName AppDirectory $fullAppPath
|
||||
}else {
|
||||
& $nssmPath install $serviceName $npmPath $command
|
||||
& $nssmPath set $serviceName AppDirectory $appPath
|
||||
}
|
||||
|
||||
|
||||
& $nssmPath set $serviceName Description $description
|
||||
& $nssmPath set $serviceName AppStdout "E:\LST\logs\service.log"
|
||||
& $nssmPath set $serviceName AppStderr "E:\LST\logs\service-error.log"
|
||||
& $nssmPath set $serviceName DependOnService "MSSQLSERVER"
|
||||
# Set recovery options
|
||||
sc.exe failure $serviceName reset= 0 actions= restart/5000/restart/5000/restart/5000
|
||||
& $nssmPath start $serviceName
|
||||
}else{
|
||||
write-host $serviceName "is already installed will push the updated info"
|
||||
Write-Host "Updating $serviceName..."
|
||||
& $nssmPath stop $serviceName
|
||||
|
||||
if($command.Contains(".exe")){
|
||||
$fullAppPath = "$appPath\app"
|
||||
& $nssmPath set $serviceName AppDirectory $fullAppPath
|
||||
}else {
|
||||
& $nssmPath set $serviceName AppDirectory $appPath
|
||||
}
|
||||
|
||||
& $nssmPath set $serviceName Description $description
|
||||
# & $nssmPath set $serviceName DependOnService "IISADMIN MSSQLSERVER"
|
||||
# Set recovery options
|
||||
sc.exe failure $serviceName reset= 0 actions= restart/5000/restart/5000/restart/5000
|
||||
Start-Sleep 4
|
||||
& $nssmPath start $serviceName
|
||||
}
|
||||
}
|
||||
}
|
||||
245
scripts/updateServer.ps1
Normal file
245
scripts/updateServer.ps1
Normal file
@@ -0,0 +1,245 @@
|
||||
param (
|
||||
[string]$server,
|
||||
[string]$token,
|
||||
[string]$location,
|
||||
[string]$devFolder,
|
||||
[string]$serverIP,
|
||||
[string]$build,
|
||||
[string]$type,
|
||||
[string]$username,
|
||||
[string]$admpass,
|
||||
[string]$obslst,
|
||||
[string]$obsBuild
|
||||
)
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||
$rootDir = Join-Path $scriptDir ".."
|
||||
|
||||
# example run script is
|
||||
# .\updateServer.ps1 -username "username" -admpass "password" -token "test3" -server "usmcd1vms036" -serverIP "10.193.0.56" -build "C:\Users\matthes01\Documents\logistics_support_tool\releases" -location "E:\LST"
|
||||
|
||||
# Convert the plain-text password to a SecureString
|
||||
$securePass = ConvertTo-SecureString $admpass -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||
|
||||
# lets get the version of the app we are updating
|
||||
$pkgFile = "$rootDir\package.json"
|
||||
$package = Get-Content -Path $pkgFile -Raw | ConvertFrom-Json
|
||||
$buildNumberFile = Join-Path $rootDir "BUILD_NUMBER"
|
||||
|
||||
if (Test-Path $buildNumberFile) {
|
||||
$buildNumber = Get-Content $buildNumberFile -Raw
|
||||
$buildNumber = $buildNumber.Trim()
|
||||
Write-Host "Current build number: $buildNumber"
|
||||
} else {
|
||||
Write-Warning "BUILD_NUMBER file not found at $buildNumberFile"
|
||||
}
|
||||
|
||||
$version = "$($package.version)-$($buildNumber)"
|
||||
|
||||
# Checking to make sure the server is up and online
|
||||
Write-Output "Checking if $($token) is online to update."
|
||||
$pingResult = Test-Connection -ComputerName $serverIP -Count 2 -Quiet
|
||||
|
||||
if (-not $pingResult) {
|
||||
Write-Output "Server $($server) $($serverIP) is NOT reachable. Exiting script."
|
||||
exit 1 # Terminate the script with a non-zero exit code
|
||||
}
|
||||
|
||||
Write-Output "Server $($server) ($serverIP) is online."
|
||||
|
||||
|
||||
$buildZip = "release-v$version.zip"
|
||||
if (-Not (Test-Path -Path "$($build)\$($buildZip)")) {
|
||||
Write-Host "Build is missing from the build folder."
|
||||
Write-host $buildZip
|
||||
exit
|
||||
} else {
|
||||
Write-Host "We have the build lets move to next step"
|
||||
}
|
||||
|
||||
|
||||
Write-Host "Starting the update Process"
|
||||
Write-Host "File to be copied over is $buildZip"
|
||||
Write-Host "Coping files to $($server)"
|
||||
$destination = "\\$($server)\$($location)" -replace ":", "$"
|
||||
Write-Host $destination
|
||||
Write-Host "Forcing the removal of the mapped drive, just incase it was lingering"
|
||||
|
||||
Get-PSDrive -Name "z" -ErrorAction SilentlyContinue | Remove-PSDrive -Force
|
||||
|
||||
|
||||
# Create a mapped drive with credentials using New-PSDrive for the current session
|
||||
|
||||
try {
|
||||
net use $server /delete /y 2>$null
|
||||
#New-PSDrive -Name "z" -PSProvider FileSystem -Root $destination -Credential $credentials
|
||||
New-PSDrive -Name "Z" -PSProvider FileSystem -Root $destination -Persist -Credential $credentials
|
||||
|
||||
# Create the update folder if it doesn't exist
|
||||
if (-not (Test-Path -Path $destination)) {
|
||||
New-Item -ItemType Directory -Path $destination -Force
|
||||
}
|
||||
|
||||
# Copying files to the server
|
||||
Write-Host "Copying files to $($server)"
|
||||
Copy-Item -Path "$($build)\$($buildZip)" -Destination "Z:\" -Recurse -Force
|
||||
Write-Host "Files copied to $($server)"
|
||||
} catch {
|
||||
Write-Host "Error: $_"
|
||||
} finally {
|
||||
# Remove the mapped drive after copying
|
||||
if (Get-PSDrive -Name "Z" -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Removing mapped drive..."
|
||||
Remove-PSDrive -Name "Z"
|
||||
}
|
||||
}
|
||||
|
||||
# create the extracted path
|
||||
$extractedFolderPath = "$server\$location$(if ($token -eq "usiow2") { "_2" })"
|
||||
|
||||
$plantFunness = {
|
||||
param ($server, $token, $location, $buildFile, $buildLoc)
|
||||
|
||||
$localPath = $location -replace '\$', ':'
|
||||
$serverFile = "$($localPath)\$buildFile"
|
||||
$serverPath = "$($localPath)"
|
||||
|
||||
|
||||
# $appPath = $extractedFolderPath
|
||||
$nssmPath = $serverPath + "\nssm.exe"
|
||||
$npmPath = "C:\Program Files\nodejs\npm.cmd"
|
||||
|
||||
$serviceApp = "LST_app$(if ($token -eq "usiow2") { "_2" })"
|
||||
#$serviceFrontEnd = "LST-frontend$(if ($token -eq "usiow2") { "_2" })"
|
||||
$serviceOcme = "LST-Ocme$(if ($token -eq "usiow2") { "_2" })"
|
||||
$serviceLstV2 = "LSTV2$(if ($token -eq "usiow2") { "_2" })"
|
||||
|
||||
Write-Host "In the plant we go!!!!!"
|
||||
# $servicesScript = Join-Path $PSScriptRoot "scripts\services.ps1"
|
||||
# $iisContorl = Join-Path $PSScriptRoot "scripts\iisControls.ps1"
|
||||
######################################################################################
|
||||
# Stop the services and iis to do the updates.
|
||||
######################################################################################
|
||||
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||
|
||||
Write-Host "Stopping $serviceApp"
|
||||
Stop-Service -DisplayName $serviceApp -Force
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
Write-Host "Stopping $serviceLstV2"
|
||||
Stop-Service -DisplayName $serviceLstV2 -Force
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
if($token -eq "usday1"){
|
||||
Write-Host "Stopping $($serviceOcme)"
|
||||
Stop-Service -DisplayName $serviceOcme -Force
|
||||
}
|
||||
|
||||
Write-Host "Stopping iis application"
|
||||
Stop-WebAppPool -Name LogisticsSupportTool #-ErrorAction Stop
|
||||
|
||||
|
||||
######################################################################################
|
||||
# Removing the cashed stuff to keep the folder clean.
|
||||
######################################################################################
|
||||
|
||||
# Delete the directories after extraction
|
||||
Write-Host "Deleting app and other cache stuff"
|
||||
|
||||
Set-Location $serverPath
|
||||
if (-not (Test-Path "app")) {
|
||||
Write-Host "The app folder is already deleted nothing else to do"
|
||||
} else {
|
||||
Remove-Item -LiteralPath "app" -Force -Recurse
|
||||
}
|
||||
|
||||
if (-not (Test-Path "lstWrapper")) {
|
||||
Write-Host "The lstWrapper folder is already deleted nothing else to do"
|
||||
} else {
|
||||
Remove-Item -LiteralPath "lstWrapper" -Force -Recurse
|
||||
}
|
||||
|
||||
if (-not (Test-Path "scripts")) {
|
||||
Write-Host "The scripts folder is already deleted nothing else to do"
|
||||
} else {
|
||||
Remove-Item -LiteralPath "scripts" -Force -Recurse
|
||||
}
|
||||
|
||||
if (-not (Test-Path "tmp")) {
|
||||
Write-Host "The scripts folder is already deleted nothing else to do"
|
||||
} else {
|
||||
Remove-Item -LiteralPath "tmp" -Force -Recurse
|
||||
}
|
||||
|
||||
|
||||
######################################################################################
|
||||
# Extract everything the cashed stuff to keep the folder clean.
|
||||
######################################################################################
|
||||
|
||||
Write-Host "Unzipping the folder..."
|
||||
try {
|
||||
# Expand the archive
|
||||
Expand-Archive -Path $serverFile -DestinationPath $serverPath -Force
|
||||
|
||||
# Delete the zip file after extraction
|
||||
Write-Host "Deleting the zip file..."
|
||||
Remove-Item -Path $serverFile -Force
|
||||
} catch {
|
||||
Write-Host "Error: $_"
|
||||
exit 1 # Exit with a non-zero code if there's an error
|
||||
}
|
||||
|
||||
Write-Host "Unzip the LSTV2 app"
|
||||
|
||||
#lstv2 loc
|
||||
$lstv2 = Get-ChildItem -Path "$($localPath)\tmp" -Filter *.zip
|
||||
|
||||
write-host $lstv2[0].FullName
|
||||
|
||||
if ($lstv2.Count -eq 0) {
|
||||
Write-Host "No zip files found in $localPath\tmp"
|
||||
|
||||
} else {
|
||||
$zipToExtract = $lstv2[0].FullName
|
||||
$destination = "$localPath\lstv2"
|
||||
|
||||
Expand-Archive -Path $zipToExtract -DestinationPath $destination -Force
|
||||
Write-Host "Extracted $zipToExtract to $destination"
|
||||
|
||||
$removePath = "$($localPath)\tmp"
|
||||
Remove-Item -Path $removePath -Force /Y
|
||||
}
|
||||
|
||||
######################################################################################
|
||||
# Doing the update stuff.
|
||||
# for now just on the old version.
|
||||
######################################################################################
|
||||
Push-Location $serverPath/lstv2
|
||||
npm i
|
||||
npm run db:migrate
|
||||
|
||||
######################################################################################
|
||||
# Start the services and iis backup.
|
||||
######################################################################################
|
||||
Write-Host "Starting the services up."
|
||||
|
||||
Write-Host "Starting $serviceApp"
|
||||
Start-Service -DisplayName $serviceApp
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
Write-Host "Starting $serviceLstV2"
|
||||
Start-Service -DisplayName $serviceLstV2
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
if($token -eq "usday1"){
|
||||
Write-Host "Starting $($serviceOcme)"
|
||||
Start-Service -DisplayName $serviceOcme
|
||||
}
|
||||
|
||||
Write-Host "Starting iis application"
|
||||
Start-WebAppPool -Name LogisticsSupportTool
|
||||
|
||||
}
|
||||
|
||||
Invoke-Command -ComputerName $server -ScriptBlock $plantFunness -ArgumentList $server, $token, $location, $buildZip, $buildLoc -Credential $credentials
|
||||
Reference in New Issue
Block a user