Compare commits
6 Commits
6a717c81e5
...
0273703bfb
| Author | SHA1 | Date | |
|---|---|---|---|
| 0273703bfb | |||
| 50927ca341 | |||
| fe05ff17e1 | |||
| ab5af87362 | |||
| 2aca7e9a0e | |||
| abcd5b5f3c |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -7,7 +7,9 @@ lstWrapper/obj
|
||||
lstWrapper/publish
|
||||
testScripts
|
||||
.build
|
||||
.controller-build
|
||||
builds
|
||||
controllerBuilds
|
||||
# ignoring the old app that will be built into this one to make deploying faster and more easy as we do the migration
|
||||
lstV2
|
||||
|
||||
@@ -186,3 +188,8 @@ go.work.sum
|
||||
|
||||
lstWrapper/Program_working_node_ws.txt
|
||||
lstWrapper/web.config.txt
|
||||
controller/-docker-compose.yml
|
||||
controller/docker-compose.yml
|
||||
controller/Dockerfile
|
||||
controller/Dockerfile-ignore
|
||||
controller/docker-compose.yml
|
||||
|
||||
1
.include
1
.include
@@ -1,7 +1,6 @@
|
||||
dist
|
||||
frontend/dist
|
||||
lstDocs/build
|
||||
lstWrapper/publish
|
||||
migrations
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
|
||||
7
.includeControls
Normal file
7
.includeControls
Normal file
@@ -0,0 +1,7 @@
|
||||
lstWrapper/publish
|
||||
controller/lst_ctl.exe
|
||||
scripts/update-controller-bumpBuild.ps1
|
||||
scripts/update-controller-server.ps1
|
||||
scripts/update-controller-zip.ps1
|
||||
scripts/update-controllers.ps1
|
||||
scripts/services.ps1
|
||||
@@ -4,8 +4,10 @@ COPY package*.json ./
|
||||
|
||||
RUN mkdir frontend
|
||||
RUN mkdir lstDocs
|
||||
RUN mkdir controller
|
||||
COPY frontend/package*.json ./frontend
|
||||
COPY lstDocs/package*.json ./lstDocs
|
||||
COPY controller/index.html ./controller
|
||||
|
||||
RUN npm install
|
||||
RUN npm run install:front
|
||||
@@ -17,6 +19,7 @@ WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=deps /app/frontend/node_modules ./frontend/node_modules
|
||||
COPY --from=deps /app/lstDocs/node_modules ./lstDocs/node_modules
|
||||
COPY --from=deps /app/controller/index.html ./controller/index.html
|
||||
COPY . ./
|
||||
RUN npm run build:app
|
||||
RUN npm run build:front
|
||||
@@ -29,7 +32,7 @@ COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/frontend/dist ./frontend/dist
|
||||
COPY --from=builder /app/lstDocs/build ./lstDocs/build
|
||||
|
||||
COPY --from=deps /app/controller/index.html ./controller/index.html
|
||||
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import express from "express";
|
||||
import morgan from "morgan";
|
||||
import { createServer } from "http";
|
||||
import { setupRoutes } from "./internal/routerHandler/routeHandler.js";
|
||||
import { printers } from "./internal/ocp/printers/printers.js";
|
||||
import { setupRoutes } from "./src/internal/routerHandler/routeHandler.js";
|
||||
import { printers } from "./src/internal/ocp/printers/printers.js";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { db } from "./pkg/db/db.js";
|
||||
import { settings } from "./pkg/db/schema/settings.js";
|
||||
import { validateEnv } from "./pkg/utils/envValidator.js";
|
||||
import { createLogger } from "./pkg/logger/logger.js";
|
||||
import { returnFunc } from "./pkg/utils/return.js";
|
||||
import { initializeProdPool } from "./pkg/prodSql/prodSqlConnect.js";
|
||||
import { tryCatch } from "./pkg/utils/tryCatch.js";
|
||||
import { db } from "./src/pkg/db/db.js";
|
||||
import { settings } from "./src/pkg/db/schema/settings.js";
|
||||
import { validateEnv } from "./src/pkg/utils/envValidator.js";
|
||||
import { createLogger } from "./src/pkg/logger/logger.js";
|
||||
import { returnFunc } from "./src/pkg/utils/return.js";
|
||||
import { initializeProdPool } from "./src/pkg/prodSql/prodSqlConnect.js";
|
||||
import { tryCatch } from "./src/pkg/utils/tryCatch.js";
|
||||
import os from "os";
|
||||
import { sendNotify } from "./pkg/utils/notify.js";
|
||||
import { sendNotify } from "./src/pkg/utils/notify.js";
|
||||
|
||||
const main = async () => {
|
||||
const env = validateEnv(process.env);
|
||||
@@ -1,71 +0,0 @@
|
||||
# # ---- Builder Stage ----
|
||||
# FROM golang:1.24.4-alpine3.22 AS builder
|
||||
|
||||
# WORKDIR /app/controller
|
||||
|
||||
# # Copy Go module manifests
|
||||
# COPY controller/go.mod controller/go.sum ./
|
||||
# RUN go mod download
|
||||
|
||||
# # Copy the controller source code
|
||||
# COPY controller/ ./
|
||||
|
||||
# # Build the binary
|
||||
# RUN CGO_ENABLED=0 GOOS=linux go build -o /app/lst_ctl .
|
||||
|
||||
|
||||
# # ---- Runtime Stage ----
|
||||
# FROM alpine:latest
|
||||
|
||||
# WORKDIR /root/
|
||||
|
||||
# # Copy only the binary (no need for sources)
|
||||
# COPY --from=builder /app/lst_ctl .
|
||||
|
||||
# # (Optional) Persist data output if controller writes files
|
||||
# RUN mkdir -p /data
|
||||
# VOLUME /data
|
||||
|
||||
# # Expose Gin API port
|
||||
# EXPOSE 8080
|
||||
|
||||
# ENV RUNNING_IN_DOCKER=true
|
||||
|
||||
# CMD ["./lst_ctl"]
|
||||
|
||||
# ---- Build Go binary ----
|
||||
FROM golang:1.24.4-alpine3.22 AS gobuilder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# copy controller module
|
||||
COPY controller/go.mod controller/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# copy all controller source code
|
||||
COPY controller/ ./
|
||||
|
||||
# build binary into /bin
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /bin/lst_ctl .
|
||||
|
||||
|
||||
# ---- Runtime with Node ----
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# copy binary from builder
|
||||
COPY --from=gobuilder /bin/lst_ctl /usr/local/bin/lst_ctl
|
||||
|
||||
# copy repo root into /app (npm needs package.json, dist/, frontend/, etc)
|
||||
COPY . .
|
||||
|
||||
# clear Node's default entrypoint (Docker Hub node images use ["docker-entrypoint.sh"])
|
||||
ENTRYPOINT []
|
||||
|
||||
# expose gin api
|
||||
EXPOSE 8080
|
||||
ENV RUNNING_IN_DOCKER=true
|
||||
|
||||
# run binary (in PATH now, since it's under /usr/local/bin)
|
||||
CMD ["lst_ctl"]
|
||||
@@ -1,13 +0,0 @@
|
||||
services:
|
||||
controller:
|
||||
build:
|
||||
context: .. # repo root
|
||||
dockerfile: controller/Dockerfile
|
||||
working_dir: /root
|
||||
environment:
|
||||
- RUNNING_IN_DOCKER=true
|
||||
volumes:
|
||||
- ..:/app # mount repo root for zipping, etc.
|
||||
- ../builds:/builds # clean host->container builds mapping
|
||||
ports:
|
||||
- "8080:8080"
|
||||
@@ -55,9 +55,10 @@ func UpdateApp(server *socketio.Server) <-chan string {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
// 1. Stop services + pool
|
||||
stopService("LSTV2")
|
||||
time.Sleep(1 * time.Second)
|
||||
stopService("lst_app")
|
||||
stopAppPool("LogisticsSupportTool")
|
||||
time.Sleep(2 * time.Second)
|
||||
//stopAppPool("LogisticsSupportTool")
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
msg = "Checking cleanup of files"
|
||||
updates <- msg
|
||||
@@ -104,8 +105,10 @@ func UpdateApp(server *socketio.Server) <-chan string {
|
||||
updates <- msg
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
startService("lst_app")
|
||||
time.Sleep(2 * time.Second)
|
||||
startService("LSTV2")
|
||||
startAppPool("LogisticsSupportTool")
|
||||
time.Sleep(2 * time.Second)
|
||||
//startAppPool("LogisticsSupportTool")
|
||||
|
||||
if err := os.Remove(zips[0]); err != nil {
|
||||
msg = fmt.Sprintf("warning: failed to delete zip %s: %v", zips[0], err)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
@@ -55,10 +54,19 @@ func updateServer(server *socketio.Server, target string) {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "Could not retrieve hostname")
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Host value: [%q]", host)
|
||||
if strings.Contains(host, "VMS") || strings.Contains(host, "vms") {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "Your are about to check for a new build and then update the server.")
|
||||
go UpdateApp(server)
|
||||
//go UpdateApp(server)
|
||||
// Kick off the update
|
||||
go func() {
|
||||
updates := UpdateApp(server) // returns <-chan string
|
||||
for msg := range updates {
|
||||
fmt.Println(msg)
|
||||
//server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
@@ -67,7 +75,7 @@ func updateServer(server *socketio.Server, target string) {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "You seem to be on a dev server or not an actual production server, you MUST pass a server over. I.E. USMCD1VMS036")
|
||||
return
|
||||
} else {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", fmt.Sprintf("Running the update on: %v", target))
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", fmt.Sprintf("Running remote update on: %v", target))
|
||||
go triggerRemoteUpdate(server, target, UpdatePayload{Action: "update", Target: target})
|
||||
}
|
||||
}
|
||||
@@ -116,16 +124,3 @@ func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload Upda
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sendUpdate(c *gin.Context, flusher http.Flusher, server *socketio.Server, msg string) {
|
||||
// SSE stream
|
||||
if c != nil && flusher != nil {
|
||||
fmt.Fprintf(c.Writer, "event: log\ndata: %s\n\n", msg)
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
// Socket.IO
|
||||
if server != nil {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
container_name: lst_app
|
||||
ports:
|
||||
- "${VITE_PORT:-4200}:4200"
|
||||
#- "${VITE_PORT:-4200}:4200"
|
||||
- "4000:4200"
|
||||
environment:
|
||||
- NODE_ENV=devolpment
|
||||
- DATABASE_HOST=host.docker.internal
|
||||
|
||||
@@ -22,6 +22,7 @@ Please note that if you plan to utlize the scanner app you must use IIS to run a
|
||||

|
||||
|
||||
4. Name is LogisticsSupportTool
|
||||
- NOTE: You must not have spaces due to other scripts utlizing this name for updating.
|
||||
|
||||
- Change .NET CLR verion to not managed
|
||||
- leave the rest as default
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.0 KiB |
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts",
|
||||
"dev:app": "dotenvx run -f .env -- tsx watch app/main.ts",
|
||||
"dev:docs": "npm run translateDocs && cd lstDocs && npm start",
|
||||
"dev:front": "cd frontend && npm run dev",
|
||||
"dev:db:migrate": "npx drizzle-kit push --config=drizzle-dev.config.ts",
|
||||
|
||||
49
scripts/update-controller-bumpBuild.ps1
Normal file
49
scripts/update-controller-bumpBuild.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
function Bump-Build {
|
||||
param (
|
||||
[string]$AppRoot,
|
||||
[int]$KeepLast = 5 # number of builds to keep, default 5
|
||||
)
|
||||
|
||||
$BuildFile = Join-Path $AppRoot ".controller-build"
|
||||
$BuildFolder = Join-Path $AppRoot "controllerBuilds"
|
||||
|
||||
# Default to 1
|
||||
$BuildNumber = 1
|
||||
|
||||
|
||||
if (Test-Path $BuildFile) {
|
||||
$content = Get-Content $BuildFile | Select-Object -First 1
|
||||
$num = $content.Trim() -as [int] # safe cast
|
||||
|
||||
if ($num) {
|
||||
$BuildNumber = $num + 1
|
||||
} else {
|
||||
$BuildNumber = 1
|
||||
}
|
||||
}
|
||||
|
||||
# Convert to string
|
||||
$BuildNumber = $BuildNumber.ToString()
|
||||
|
||||
# Save new build number
|
||||
Set-Content -Path $BuildFile -Value $BuildNumber
|
||||
|
||||
Write-Output "New Build Number: $BuildNumber"
|
||||
|
||||
# --- Cleanup old builds ---
|
||||
if (Test-Path $BuildFolder) {
|
||||
# Get all zip files in build folder matching pattern
|
||||
$zips = Get-ChildItem -Path $BuildFolder -Filter "controllers-*.zip" |
|
||||
Sort-Object LastWriteTime -Descending
|
||||
|
||||
# Keep only the newest $KeepLast, remove the rest
|
||||
if ($zips.Count -gt $KeepLast) {
|
||||
$toRemove = $zips[$KeepLast..($zips.Count - 1)]
|
||||
foreach ($zip in $toRemove) {
|
||||
Remove-Item $zip.FullName -Force
|
||||
Write-Output "Removed old build: $($zip.Name)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
142
scripts/update-controller-server.ps1
Normal file
142
scripts/update-controller-server.ps1
Normal file
@@ -0,0 +1,142 @@
|
||||
function Update-Server {
|
||||
param (
|
||||
[string]$ADM_USER,
|
||||
[string]$ADM_PASS,
|
||||
[string]$AppRoot,
|
||||
[string]$Destination,
|
||||
[string]$Server,
|
||||
[string]$Token
|
||||
|
||||
)
|
||||
|
||||
$BuildFile = Join-Path $AppRoot ".controller-build"
|
||||
$BuildFolder = Join-Path $AppRoot "controllerBuilds"
|
||||
|
||||
$securePass = ConvertTo-SecureString $ADM_PASS -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($ADM_USER, $securePass)
|
||||
|
||||
|
||||
# Default to 1
|
||||
$BuildNumber = 1
|
||||
|
||||
|
||||
if (Test-Path $BuildFile) {
|
||||
$content = Get-Content $BuildFile | Select-Object -First 1
|
||||
$num = $content.Trim() -as [int] # safe cast
|
||||
|
||||
if ($num) {
|
||||
$BuildNumber = $num + 1
|
||||
} else {
|
||||
$BuildNumber = 1
|
||||
}
|
||||
}
|
||||
|
||||
# Get The current Build we have zipped up
|
||||
$BuildNumber = $BuildNumber - 1
|
||||
|
||||
# Convert to string
|
||||
$BuildNumber = $BuildNumber.ToString()
|
||||
|
||||
# copy the latest build over
|
||||
|
||||
Write-Host "Forcing the removal of the mapped drive."
|
||||
Get-PSDrive -Name "z" -ErrorAction SilentlyContinue | Remove-PSDrive -Force
|
||||
|
||||
try {
|
||||
|
||||
New-PSDrive -Name "z" -PSProvider FileSystem -Root "\\$Server\$Destination" -Credential $credentials
|
||||
|
||||
# Create the update folder if it doesn't exist
|
||||
if (-not (Test-Path -Path "\\$Server\$Destination")) {
|
||||
New-Item -ItemType Directory -Path "\\$Server\$Destination" -Force
|
||||
}
|
||||
|
||||
# Copying files to the server
|
||||
Write-Host "Copying files to $($Server)"
|
||||
$zipFile = Join-Path $BuildFolder "controllers-$BuildNumber.zip"
|
||||
Copy-Item -Path $zipFile -Destination "z:\" -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"
|
||||
}
|
||||
}
|
||||
|
||||
# do the stop services, unzip, and restart service and pool
|
||||
|
||||
$ControllerUpdate = {
|
||||
param ($Server, $Token, $Destination, $BuildFile)
|
||||
|
||||
|
||||
write-host "Running the update process now"
|
||||
# Change the destination to be local
|
||||
$LocalPath = $Destination -replace '\$', ':'
|
||||
$BuildFileLoc = "$LocalPath\$BuildFile"
|
||||
|
||||
# where is nssm.exe
|
||||
$nssmPath= Join-Path $LocalPath "nssm.exe"
|
||||
$npmPath = "C:\Program Files\nodejs\npm.cmd"
|
||||
|
||||
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||
|
||||
$Controller = "LST_ctl$(if ($Token -eq "usiow2") { "_2" })"
|
||||
$Wrapper = "LogisticsSupportTool$(if ($token -eq "usiow2") { "_2" })"
|
||||
|
||||
Write-Host "Stopping $($Controller)"
|
||||
Stop-Service -DisplayName $Controller -Force
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
try {
|
||||
Stop-WebAppPool -Name $Wrapper -ErrorAction Stop
|
||||
|
||||
Start-Sleep -Seconds 2
|
||||
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
||||
Write-Host "Result: $state"
|
||||
} catch {
|
||||
Write-Error $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
Write-Host "Unzipping the folder..."
|
||||
write-host $BuildFileLoc
|
||||
write-host $LocalPath
|
||||
|
||||
# Extract the files to the build path
|
||||
try {
|
||||
# Expand the archive
|
||||
Expand-Archive -Path $BuildFileLoc -DestinationPath $LocalPath -Force
|
||||
} catch {
|
||||
Write-Host "Error: $_"
|
||||
exit 1 # Exit with a non-zero code if there's an error
|
||||
}
|
||||
|
||||
# Delete the zip file after extraction
|
||||
Write-Host "Deleting the zip file..."
|
||||
Remove-Item -Path $BuildFileLoc -Force
|
||||
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
Write-Host "Starting $($Controller)"
|
||||
Start-Service -DisplayName $Controller
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
try {
|
||||
Start-WebAppPool -Name $Wrapper
|
||||
Start-Sleep -Seconds 2
|
||||
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
||||
Write-Host "Result: $state"
|
||||
} catch {
|
||||
Write-Error $_.Exception.Message
|
||||
exit 1
|
||||
}
|
||||
|
||||
write-host "Controllers updated and restarted :D"
|
||||
|
||||
}
|
||||
|
||||
Invoke-Command -ComputerName $Server -ScriptBlock $ControllerUpdate -ArgumentList $Server, $Token, $Destination, "controllers-$BuildNumber.zip" -Credential $credentials
|
||||
}
|
||||
60
scripts/update-controller-zip.ps1
Normal file
60
scripts/update-controller-zip.ps1
Normal file
@@ -0,0 +1,60 @@
|
||||
function Zip-Includes {
|
||||
param (
|
||||
[string]$IncludesFile,
|
||||
[string]$BuildNumber,
|
||||
[string]$BuildFolder,
|
||||
[string]$AppRoot
|
||||
)
|
||||
|
||||
# Read all paths from .includes
|
||||
$itemsToZip = @()
|
||||
Get-Content $IncludesFile | ForEach-Object {
|
||||
$relPath = $_.Trim()
|
||||
if ($relPath -ne "") {
|
||||
$fullPath = Join-Path $AppRoot $relPath
|
||||
if (Test-Path $fullPath) {
|
||||
$itemsToZip += [PSCustomObject]@{
|
||||
FullPath = $fullPath
|
||||
RelativePath = $relPath
|
||||
}
|
||||
} else {
|
||||
Write-Warning "Path not found: $fullPath"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-Not $itemsToZip) {
|
||||
Write-Warning "No valid files or folders to zip."
|
||||
return
|
||||
}
|
||||
|
||||
$zipFileName = Join-Path $BuildFolder "controllers-$BuildNumber.zip"
|
||||
|
||||
if (Test-Path $zipFileName) {
|
||||
Remove-Item $zipFileName
|
||||
}
|
||||
|
||||
# Create zip preserving relative paths
|
||||
$tempFolder = Join-Path $env:TEMP "zip-temp-$BuildNumber"
|
||||
if (Test-Path $tempFolder) { Remove-Item $tempFolder -Recurse -Force }
|
||||
New-Item -Path $tempFolder -ItemType Directory | Out-Null
|
||||
|
||||
foreach ($item in $itemsToZip) {
|
||||
$dest = Join-Path $tempFolder $item.RelativePath
|
||||
$destDir = Split-Path $dest
|
||||
if (-Not (Test-Path $destDir)) { New-Item -Path $destDir -ItemType Directory | Out-Null }
|
||||
|
||||
if ((Get-Item $item.FullPath).PSIsContainer) {
|
||||
Copy-Item -Path $item.FullPath -Destination $dest -Recurse
|
||||
} else {
|
||||
Copy-Item -Path $item.FullPath -Destination $dest
|
||||
}
|
||||
}
|
||||
|
||||
Compress-Archive -Path (Join-Path $tempFolder "*") -DestinationPath $zipFileName
|
||||
|
||||
# Cleanup temp folder
|
||||
Remove-Item $tempFolder -Recurse -Force
|
||||
|
||||
Write-Output "Created zip: $zipFileName"
|
||||
}
|
||||
111
scripts/update-controllers.ps1
Normal file
111
scripts/update-controllers.ps1
Normal file
@@ -0,0 +1,111 @@
|
||||
param (
|
||||
[string]$App_Path = "C:\Users\matthes01\Documents\lst", # with this it makes it optional to pass a new parameter over.
|
||||
[string]$Server = "usmcd1vms036",
|
||||
[string]$Token = "test3",
|
||||
[string]$Remote_Path = "E$\LST"
|
||||
)
|
||||
|
||||
# imports of the other functions
|
||||
. ".\update-controller-zip"
|
||||
. ".\update-controller-bumpBuild"
|
||||
. ".\update-controller-server"
|
||||
|
||||
# example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts
|
||||
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Server "usmcd1vms036" -Token "test3" -Remote_Path "E$\LST"
|
||||
|
||||
$EnvFile = Join-Path $App_Path ".env"
|
||||
if (-Not (Test-Path $EnvFile)) {
|
||||
Write-Error "File not found: $EnvFile"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Read and parse the .env file into a dictionary
|
||||
$envDict = @{}
|
||||
|
||||
Get-Content $EnvFile | ForEach-Object {
|
||||
if ($_ -match "^\s*#") { return } # skip comments
|
||||
if ([string]::IsNullOrWhiteSpace($_)) { return } # skip blank lines
|
||||
$parts = $_ -split '=', 2
|
||||
if ($parts.Count -eq 2) {
|
||||
$envDict[$parts[0].Trim()] = $parts[1].Trim()
|
||||
}
|
||||
}
|
||||
|
||||
# Read the .env file and set each key as a variable
|
||||
Get-Content $EnvFile | ForEach-Object {
|
||||
if ($_ -match "^\s*#") { return } # skip comments
|
||||
if ([string]::IsNullOrWhiteSpace($_)) { return } # skip blank lines
|
||||
|
||||
$parts = $_ -split '=', 2
|
||||
if ($parts.Count -eq 2) {
|
||||
$key = $parts[0].Trim()
|
||||
$value = $parts[1].Trim()
|
||||
|
||||
# Set as PowerShell variable
|
||||
Set-Variable -Name $key -Value $value -Scope Global
|
||||
}
|
||||
}
|
||||
|
||||
# create the new zip build.
|
||||
# ---------------------------------------------------------------------------------
|
||||
#check it file is there
|
||||
$BuildNumber = "1"
|
||||
$buildfile = Join-Path $App_Path ".controller-build"
|
||||
|
||||
if (-Not (Test-Path $buildfile)) {
|
||||
Write-Error "File not found: $buildfile, creating it."
|
||||
New-Item -Path $buildfile -ItemType File | Out-Null
|
||||
$BuildNumber = "1"
|
||||
Set-Content -Path $BuildFile -Value $BuildNumber
|
||||
}
|
||||
else {
|
||||
$content = Get-Content $BuildFile -Raw
|
||||
if (![string]::IsNullOrWhiteSpace($content)) {
|
||||
$BuildNumber = $content.Trim()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# do the same check on the .includeControls file
|
||||
$ControlIncludes = Join-Path $App_Path ".includeControls"
|
||||
if (-Not (Test-Path $ControlIncludes)) {
|
||||
Write-Error "File not found: $ControlIncludes, exiting as we dont want to zip up the entire app."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# last one to make sure we have is the build folder
|
||||
$BuildFolder = Join-Path $App_Path "controllerBuilds"
|
||||
if (-Not (Test-Path $BuildFolder)) {
|
||||
write-host "Build folder missing creating it"
|
||||
New-Item -Path $BuildFolder -ItemType Directory | Out-Null
|
||||
}
|
||||
|
||||
# now we can create the zip
|
||||
Zip-Includes -IncludesFile $ControlIncludes -BuildNumber $BuildNumber -BuildFolder $BuildFolder -AppRoot $App_Path
|
||||
Start-Sleep -Seconds 3
|
||||
#------------------------------------------------------------------------------------
|
||||
|
||||
# Checking to make sure the server is up and online
|
||||
Write-Output "Checking if $($Token) is online to update."
|
||||
$pingResult = Test-Connection -ComputerName $Server -Count 2 -Quiet
|
||||
|
||||
if (-not $pingResult) {
|
||||
Write-Output "Server $($Server), token $($Token) is NOT reachable. Exiting script."
|
||||
exit 1 # Terminate the script with a non-zero exit code
|
||||
}
|
||||
|
||||
Write-Output "Server $($Server), token $($Token) is online."
|
||||
|
||||
|
||||
# now that the server is up lets update the server with the current build
|
||||
# do the update to the plant.
|
||||
Update-Server -ADM_USER $ADM_USER -ADM_PASS $ADM_PASS -AppRoot $App_Path -Destination $Remote_Path -Server $Server -Token $Token
|
||||
|
||||
# bump the build number
|
||||
$BuildNumber = Bump-Build -AppRoot $App_Path
|
||||
|
||||
|
||||
# function to create the zip controller-1.zip
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
"include": [
|
||||
"app/src",
|
||||
"database/testFiles/test-tiPostOrders.ts",
|
||||
"scripts/translateScript.js"
|
||||
"scripts/translateScript.js",
|
||||
"app/main.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
||||
Reference in New Issue
Block a user