X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=deploy.ps1;h=5a1169784a5cca5bf8bdcad6795e1d971d014620;hb=3ebbe8172b0430bae5c554925a4582c9fec545f3;hp=7b4b5568a1c6b5f92dd47ea4983784091139dc9e;hpb=33493c8991d8971450fc0eb5114152c9a0faa6b1;p=recipes.git diff --git a/deploy.ps1 b/deploy.ps1 index 7b4b556..5a11697 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -1,28 +1,45 @@ -if ($args.Count -lt 1) { +# TODO: +# * copy the conf if it doesn't exist +# * create the destination directory if doesn't exist + +if ($args.Count -lt 3) { $scriptName = [Environment]::GetCommandLineArgs()[1] - echo "Usage: $scriptName " + Write-Output "Usage: $scriptName " exit 1 } -git pull -cargo build --release +$address=$args[0] +$destination=$args[1] +$ssh_key=$args[2] -systemctl --user stop www-recipes.service +$ssh_command = "ssh -i $ssh_key $address" +$scp_command = "scp -r -i $ssh_key" -$destination=$args[0] +function Invoke-SSH([string]$command) +{ + $expression = "$ssh_command $command" + Write-Output "Executing: $expression" + Invoke-Expression $expression | Write-Output +} -if (!(Test-Path -Path $destination)) { - New-Item -ItemType directory -Path $destination +function Copy-SSH([string]$source, [string]$destination) +{ + $expression = "$scp_command $source ${address}:$destination" + Write-Output "Executing: $expression" + Invoke-Expression $expression } -Copy-Item target/release/recipes -Destination $destination +cargo build --target arm-unknown-linux-gnueabihf --release -Copy-Item backend/static -Destination $destination -Recurse -Force +Invoke-SSH "sudo systemctl stop recipes" -# Do not overwrite the configuration. -if (!(Test-Path -Path $destination/conf.ron)) { - Copy-Item conf.ron -Destination $destination -} +Copy-SSH -source "./target/arm-unknown-linux-gnueabihf/release/recipes" -destination "~/recipes/" + +Invoke-SSH "rm -rf recipes/static" +Copy-SSH -source "./backend/static/" -destination "~/recipes/" -systemctl --user start www-recipes.service +Invoke-SSH "chmod u+x recipes/recipes" +Invoke-SSH "strip recipes/recipes" +Invoke-SSH "sudo systemctl start recipes" +Write-Output "Deployment finished"