From 7e6554b232f0616c0ea42348ed228ddefd15961c Mon Sep 17 00:00:00 2001 From: Kithmini Gunawardhana Date: Tue, 6 Sep 2022 09:17:37 +0530 Subject: [PATCH] Add Restart Policy to hpdevkit container (#7) --- linux/hpdevkit.sh | 6 +++++- windows/hpdevkit.ps1 | 47 ++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/linux/hpdevkit.sh b/linux/hpdevkit.sh index a03cdc1..b2b620c 100755 --- a/linux/hpdevkit.sh +++ b/linux/hpdevkit.sh @@ -54,6 +54,10 @@ function devKitContainer() { command+=" --entrypoint /bin/bash" fi + if [ ! -z "$RESTARTPOLICY" ]; then + command+=" --restart $RESTARTPOLICY" + fi + command+=" -e CLUSTER=$cluster -e CLUSTER_SIZE=$clusterSize -e DEFAULT_NODE=$defaultNode -e VOLUME=$volume -e NETWORK=$network" command+=" -e CONTAINER_PREFIX=$containerPrefix -e VOLUME_MOUNT=$volumeMount -e BUNDLE_MOUNT=$bundleMount -e HOTPOCKET_IMAGE=$instanceImage" command+=" -e CONFIG_OVERRIDES_FILE=$configOverridesFile -e CODEGEN_OUTPUT=$codegenOutputDir" @@ -96,7 +100,7 @@ function initializeDeploymentCluster() { AUTOREMOVE="true" MOUNTSOCK="true" CMD="cluster stop ; cluster create" devKitContainer run # Spin up management container. - NAME="$deploymentContainerName" DETACHED="true" MOUNTSOCK="true" MOUNTVOLUME="true" devKitContainer run + NAME="$deploymentContainerName" DETACHED="true" MOUNTSOCK="true" MOUNTVOLUME="true" RESTARTPOLICY="unless-stopped" devKitContainer run # Bind the instance mesh network config together. CONTAINERNAME="$deploymentContainerName" executeInContainer "cluster bindmesh" diff --git a/windows/hpdevkit.ps1 b/windows/hpdevkit.ps1 index 40e0f99..91d1c3a 100644 --- a/windows/hpdevkit.ps1 +++ b/windows/hpdevkit.ps1 @@ -23,7 +23,7 @@ $HPDevKitExeUrl = "$($CloudStorage)/hpdevkit-windows/hpdevkit.exe"; $HPDevKitBackup = "\hpdevkit.exe.bak"; $ExePath = (Get-Process -Id $pid).Path -function DevKitContainer([string]$Mode, [string]$Name, [switch]$Detached, [switch]$AutoRemove, [switch]$MountSock, [switch]$MountVolume, [string]$EntryPoint, [string]$Cmd, [switch]$Status) { +function DevKitContainer([string]$Mode, [string]$Name, [switch]$Detached, [switch]$AutoRemove, [switch]$MountSock, [switch]$MountVolume, [string]$EntryPoint, [string]$RestartPolicy, [string]$Cmd, [switch]$Status) { $Command = "docker $($Mode) -it" if ($Name) { @@ -51,6 +51,10 @@ function DevKitContainer([string]$Mode, [string]$Name, [switch]$Detached, [switc $Command += " --entrypoint /bin/bash" } + if ($RestartPolicy) { + $Command += " --restart $($RestartPolicy)" + } + # Pass environment variables used by our scripts. $Command += " -e CLUSTER=$($Cluster) -e CLUSTER_SIZE=$($ClusterSize) -e DEFAULT_NODE=$($DefaultNode) -e VOLUME=$($Volume) -e NETWORK=$($Network)" $Command += " -e CONTAINER_PREFIX=$($ContainerPrefix) -e VOLUME_MOUNT=$($VolumeMount) -e BUNDLE_MOUNT=$($BundleMount) -e HOTPOCKET_IMAGE=$($InstanceImage)" @@ -92,7 +96,7 @@ function InitializeDeploymentCluster() { DevKitContainer -Mode "run" -AutoRemove -MountSock -Cmd "cluster stop ; cluster create" # Spin up management container. - DevKitContainer -Mode "run" -Name $DeploymentContainerName -Detached -MountSock -MountVolume + DevKitContainer -Mode "run" -Name $DeploymentContainerName -Detached -MountSock -MountVolume -RestartPolicy "unless-stopped" # Bind the instance mesh network config together. ExecuteInDeploymentContainer -Cmd "cluster bindmesh" @@ -108,7 +112,7 @@ function TeardownDeploymentCluster() { Function Deploy([string]$Path) { if ($Path) { - + InitializeDeploymentCluster # If copying a directory, delete target bundle directory. If not create empty target bundle directory to copy a file. @@ -211,7 +215,17 @@ if (Test-Path -Path "$($ExePath)\$($HPDevKitBackup)") { Write-Host "HotPocket devkit launcher ($($Version))" $Command = $args[0] -$CommandError = "Invalid command. Expected: deploy | clean | start | stop | logs | gen | update" +$CommandError = "Invalid command. Try 'hpdevkit help' for available commands." +$HelpMessage = "Available commands: hpdevkit + COMMANDS: + deploy + clean + start + stop + logs + gen + update + help" if ($Command) { @@ -219,6 +233,20 @@ if ($Command) { Write-Host "Code generator" CodeGenerator $args[1] $args[2] $args[3] } + elseif ($Command -eq "help") { + Write-Host $HelpMessage + } + elseif ($Command -eq "update") { + try { + if (Test-Path -Path "$($ExePath)\hpdevkit.exe") { + UpdateHPDevKit + } + else { + Write-Host "No HotPocket devkit executable file was found." + } + } + catch { "An error occurred while updating." } + } else { Write-Host "command: $($Command) (cluster: $($Cluster))" if ($Command -eq "deploy") { @@ -230,17 +258,6 @@ if ($Command) { elseif ($Command -eq "logs" -OR $Command -eq "start" -OR $Command -eq "stop") { DevKitContainer -Mode "run" -AutoRemove -MountSock -EntryPoint "cluster" -Cmd "$($args)" } - elseif ($Command -eq "update") { - try { - if (Test-Path -Path "$($ExePath)\hpdevkit.exe") { - UpdateHPDevKit - } - else { - Write-Host "No HotPocket devkit executable file was found." - } - } - catch { "An error occurred while updating." } - } else { Write-Host $CommandError }