You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
2.2 KiB
41 lines
2.2 KiB
param(
|
|
[string]$Server = '192.168.18.155',
|
|
[string]$Identity = "$env:USERPROFILE\.ssh\senzapaura_deploy",
|
|
[Parameter(Mandatory=$true)][ValidatePattern('^\d{8}-\d{2}$')][string]$Release,
|
|
[switch]$Activate
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$workspace = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
|
$archive = Join-Path $workspace "artifacts\juegoland-$Release.tar.gz"
|
|
$content = @('db','deploy','docs','scripts','server','shared','src','static','tests','.env.example','.gitattributes','.gitignore','.prettierignore','.prettierrc.json','package.json','package-lock.json','README.md','tsconfig.json','tsconfig.server.json','vite.config.ts')
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $workspace 'artifacts') | Out-Null
|
|
& tar -czf $archive -C $workspace -- @content
|
|
if ($LASTEXITCODE -ne 0) { throw 'Packaging failed' }
|
|
$sshOptions = @('-4','-i',$Identity,'-o','BatchMode=yes','-o','ConnectTimeout=10')
|
|
& scp @sshOptions $archive "root@${Server}:/tmp/juegoland-$Release.tar.gz"
|
|
if ($LASTEXITCODE -ne 0) { throw 'Transfer failed' }
|
|
$prepare = @'
|
|
set -e
|
|
release=/opt/mesa-abierta/releases/RELEASE_ID
|
|
test ! -e "$release"
|
|
install -d -m 0755 -o mesa -g mesa "$release"
|
|
tar -xzf /tmp/juegoland-RELEASE_ID.tar.gz -C "$release" --no-same-owner
|
|
chown -R mesa:mesa "$release"
|
|
cd "$release"
|
|
local_address=$(ip -4 -o addr show scope global | awk '{split($4,a,"/");print a[1];exit}')
|
|
test -n "$local_address"
|
|
runuser -u mesa -- env HOME=/var/lib/mesa-abierta npm config set local-address "$local_address" --location=user
|
|
runuser -u mesa -- env HOME=/var/lib/mesa-abierta NODE_OPTIONS=--dns-result-order=ipv4first npm ci --local-address="$local_address" --no-audit --no-fund
|
|
runuser -u mesa -- npm run design:check
|
|
runuser -u mesa -- npm run check
|
|
runuser -u mesa -- npm test -- --maxWorkers=1
|
|
runuser -u mesa -- npm run build
|
|
'@
|
|
$prepare = $prepare.Replace('RELEASE_ID',$Release).Replace("`r",'')
|
|
& ssh @sshOptions "root@$Server" $prepare
|
|
if ($LASTEXITCODE -ne 0) { throw 'Remote release verification failed; no activation performed' }
|
|
if ($Activate) {
|
|
& ssh @sshOptions "root@$Server" "bash /opt/mesa-abierta/releases/$Release/deploy/activate-release.sh $Release"
|
|
if ($LASTEXITCODE -ne 0) { throw 'Activation failed; inspect services and the saved previous release' }
|
|
}
|