From f4881538414d182f9e153d334f77f47ba78f7062 Mon Sep 17 00:00:00 2001 From: ravinsp <33562092+ravinsp@users.noreply.github.com> Date: Sat, 6 May 2023 19:53:27 +0530 Subject: [PATCH] Cleanup. --- README.md | 97 ++++--------- linux/hpdevkit.sh | 319 ------------------------------------------- npm/README.md | 42 +----- windows/.gitignore | 1 - windows/hpdevkit.ps1 | 268 ------------------------------------ 5 files changed, 29 insertions(+), 698 deletions(-) delete mode 100755 linux/hpdevkit.sh delete mode 100644 windows/.gitignore delete mode 100644 windows/hpdevkit.ps1 diff --git a/README.md b/README.md index 929f976..fd8e950 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,51 @@ -# HotPocket developer toolkit -Developer toolkit for HotPocket smart contract development. This toolkit makes use of Docker to provide a cross-platform development tools for developers. Using the toolkit, developers can spin-up local HotPocket clusters on their developer machines and test HotPocket smart contracts. +# HotPocket developer kit -We use Docker containers to run HotPocket and smart contracts in a Linux environment. We also use Docker containers to distribute developer tools so developers can use the tools on any platform as long as they install Docker. +This is the source repository of developer kit for HotPocket smart contract development. This toolkit makes use of Docker and NodeJS to provide a cross-platform HotPocket development tool for developers. Using the HotPocket developer kit, developers can spin-up local HotPocket clusters on their development machines and test HotPocket smart contracts. -image +We use Docker containers to run HotPocket and smart contracts in a Linux environment. We also use Docker containers and NodeJS for tooling so developers can use the tools on any platform as long as they install Docker and NodeJS. + +image ## Public documentation -Available [here](https://github.com/HotPocketDev/evernode-sdk/tree/main/hpdevkit) + +https://github.com/EvernodeXRPL/evernode-sdk/blob/main/hpdevkit/index.md ## Prerequisites + - [Docker](https://docs.docker.com/engine/install/) +- [NodeJS](https://nodejs.org/) ## Docker build -Docker image containing cross-platform cluster management scripts. -### Local build +Docker image containing cluster management shell scripts. + ``` cd docker docker build -t evernodedev/hpdevkit . -``` - -### Push to Docker hub -``` docker push evernodedev/hpdevkit ``` ### Run + ``` docker run -it --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock evernodedev/hpdevkit cluster create 2 ``` -## Windows build -Contains windows launcher scripts. Written using powershell and compiled to exe using [ps2exe](https://github.com/MScholtes/PS2EXE). +## hpdevkit npm build -### Prerequisites -```powershell -Install-Module ps2exe +hpdevkit is a cross-platform CLI tool distributed via NPM. + +``` +# local build +cd npm +npm install +npm run build + +# publish to npm +npm login +npm run publish ``` -### Powershell script usage -```powershell -# Deploy contract to single-node cluster. -.\hpdevkit.ps1 deploy +### NPM package -# Stop and cleanup everything (required for changing cluster size) -.\hpdevkit.ps1 clean - -# Use different cluster size. -$env:HP_CLUSTER_SIZE = 3 -.\hpdevkit.ps1 deploy - -# Look at specific node's logs. -.\hpdevkit.ps1 logs - -# Start/stop all nodes. -.\hpdevkit.ps1 start -.\hpdevkit.ps1 stop - -# Start/stop specific node. -.\hpdevkit.ps1 start -.\hpdevkit.ps1 stop -``` - -If the contract files directory also contains a file named `hp.cfg.override`, it will be used to override the hp.cfg of all nodes. This can be used to set contract specific parameters like 'bin_path' and 'bin_args' - -Example `hp.cfg.override` for a nodejs application: -``` -{ - "contract": { - "bin_path": "/usr/bin/node", - "bin_args": "app.js" - } -} -``` - -#### Code generator -``` -# Generate nodejs starter contract project -.\hpdevkit.ps1 gen nodejs starter-contract -``` - -### Generate executable -```powershell -cd windows -Invoke-ps2exe .\hpdevkit.ps1 hpdevkit.exe -``` -The executable can be distributed to be run as a CLI tool on developer machine. - -## Environment variables -| Name | Description | Default value | -| --- | --- | --- | -| HP_CLUSTER_SIZE | Number of nodes in the cluster. Applied with 'deploy' command. | `1` | -| HP_DEFAULT_NODE | The node the 'deploy' command uses to display logs. | `1` | -| HP_DEVKIT_IMAGE | Docker image to be used for devkit cluster management. | `evernodedev/hpdevkit` | -| HP_INSTANCE_IMAGE | Docker image to be used for HotPocket instances. | `evernodedev/hotpocket:0.6.0-ubt.20.04-njs.16` | \ No newline at end of file +https://www.npmjs.com/package/hpdevkit diff --git a/linux/hpdevkit.sh b/linux/hpdevkit.sh deleted file mode 100755 index e01c530..0000000 --- a/linux/hpdevkit.sh +++ /dev/null @@ -1,319 +0,0 @@ -#!/bin/bash -globalPrefix="hpdevkit" -version="0.1.0" - -cluster="default" -clusterSize=$([ -z $HP_CLUSTER_SIZE ] && echo 3 || echo "$HP_CLUSTER_SIZE") -defaultNode=$([ -z $HP_DEFAULT_NODE ] && echo 1 || echo "$HP_DEFAULT_NODE") -devkitImage=$([ -z $HP_DEVKIT_IMAGE ] && echo "evernodedev/hpdevkit" || echo "$HP_DEVKIT_IMAGE") -instanceImage=$([ -z $HP_INSTANCE_IMAGE ] && echo "evernodedev/hotpocket:0.6.0-ubt.20.04-njs.16" || echo "$HP_INSTANCE_IMAGE") -hpUserPortBegin=$([ -z $HP_USER_PORT_BEGIN ] && echo 8081 || echo "$HP_USER_PORT_BEGIN") -hpPeerPortBegin=$([ -z $HP_PEER_PORT_BEGIN ] && echo 22861 || echo "$HP_PEER_PORT_BEGIN") - -volumeMount=/$globalPrefix\_vol -volume=$globalPrefix\_$cluster\_vol -network=$globalPrefix\_$cluster\_net -containerPrefix=$globalPrefix\_$cluster\_node -bundleMount=$volumeMount/contract_bundle -deploymentContainerName=$globalPrefix\_$cluster\_deploymgr -codegenContainerName=$globalPrefix\_codegen -configOverridesFile="hp.cfg.override" -codegenOutputDir="/codegen-output" - -cloudStorage="https://stevernode.blob.core.windows.net/evernode-dev-bb7ec110-f72e-430e-b297-9210468a4cbb" -bashScriptUrl="$cloudStorage/$globalPrefix-linux/$globalPrefix.sh" -hpdevkitDataDir="/etc/$globalPrefix" -versionTimestampFile="$hpdevkitDataDir/linuxlauncherscript.timestamp" -scriptBinPath="/usr/bin/$globalPrefix" - -function devKitContainer() { - command="docker $1 -it" - if [ ! -z "$NAME" ]; then - command+=" --name $NAME" - fi - - if [ ! -z "$DETACHED" ]; then - command+=" -d" - fi - - if [ ! -z "$AUTOREMOVE" ]; then - command+=" --rm" - fi - - if [ ! -z "$MOUNTSOCK" ]; then - command+=" --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock" - fi - - if [ ! -z "$MOUNTVOLUME" ]; then - command+=" --mount type=volume,src=$volume,dst=$volumeMount" - fi - - if [ ! -z "$ENTRYPOINT" ]; then - command+=" --entrypoint $ENTRYPOINT" - else - 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" - command+=" -e HP_USER_PORT_BEGIN=$hpUserPortBegin -e HP_PEER_PORT_BEGIN=$hpPeerPortBegin" - - command+=" $devkitImage" - - if [ ! -z "$CMD" ]; then - if [ ! -z "$ENTRYPOINT" ]; then - command+=" $CMD" - else - command+=" -c '$CMD'" - fi - fi - - eval $command - lastExitedCode=$? - if [ ! -z "STATUS" ]; then - if [ $lastExitedCode -eq 0 ]; then - return 0 - else - return 1 - fi - fi -} - -function executeInContainer() { - if [ ! -z "$CONTAINERNAME" ]; then - cmd="docker exec -it $CONTAINERNAME /bin/bash -c '$1'" - ! eval $cmd && echo "Docker execution failed." - fi -} - -function initializeDeploymentCluster() { - docker inspect $deploymentContainerName &>/dev/null - if [[ $? -gt 0 ]]; then - echo "Initializing deployment cluster" - - # Stop cluster if running. Create cluster if not exists. - AUTOREMOVE="true" MOUNTSOCK="true" CMD="cluster stop ; cluster create" devKitContainer run - - # Spin up management container. - 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" - fi -} - -function teardownDeploymentCluster() { - docker stop $deploymentContainerName 2>/dev/null - docker rm $deploymentContainerName 2>/dev/null - AUTOREMOVE="true" MOUNTSOCK="true" CMD="cluster stop ; cluster destroy" devKitContainer run -} - -function deploy() { - if [ ! -z "$1" ]; then - path="$1" - initializeDeploymentCluster - - # If copying a directory, delete target bundle directory. If not create empty target bundle directory to copy a file. - prepareBundleDir=" " - if [[ -d "$path" ]]; then - prepareBundleDir="rm -rf $bundleMount" - - else - prepareBundleDir="mkdir -p $bundleMount && rm -rf $bundleMount/* $bundleMount/.??*" - fi - - CONTAINERNAME="$deploymentContainerName" executeInContainer "$prepareBundleDir" - docker cp "$path" "$deploymentContainerName:$bundleMount" - - # Sync contract bundle to all instance directories in the cluster. - CONTAINERNAME="$deploymentContainerName" executeInContainer "cluster stop ; cluster sync ; cluster start" - - if [ $defaultNode -gt 0 ]; then - echo "Streaming logs of node $defaultNode:" - CONTAINERNAME="$deploymentContainerName" executeInContainer "cluster logs $defaultNode" - fi - - else - echo "Please specify directory or file path to deploy." - fi -} - -function codeGenerator() { - platform=$1 - apptype=$2 - projName=$3 - if [[ -d $projName ]]; then - echo "Directory '$projName' already exists." - exit 1 - fi - - NAME="$codegenContainerName" ENTRYPOINT="codegen" STATUS="true" CMD="$platform $apptype $projName" devKitContainer run - lastExitedCode=$? - if [ $lastExitedCode == 0 ]; then - ! docker cp $codegenContainerName:$codegenOutputDir ./$projName && echo "Project '$projName' generation failed." && exit 1 - echo "Project '$projName' created." - fi - - docker rm $codegenContainerName &>/dev/null - -} - -function removeLauncher() { - rm $scriptBinPath -} - -function createLauncher() { - # Copying the current script file to the bin directory - ! curl -fsSL $bashScriptUrl --output $scriptBinPath &>/dev/null && echo "Error in creating launcher." && return 1 - ! chmod +x $scriptBinPath &>/dev/null && echo "Error in changing permission for the launcher." && return 1 - return 0 -} - -function updateDevKit() { - local latestVersionTimestamp=$(online_version_timestamp $bashScriptUrl) - [ -z "$latestVersionTimestamp" ] && echo "Online launcher not found." && exit 1 - - # If Timestamp file is not found, re-run the install function. - if [ ! -f $versionTimestampFile ]; then - install - else - local currentVersionTimestamp=$(cat $versionTimestampFile) - if [ "$currentVersionTimestamp" == "$latestVersionTimestamp" ]; then - echo "HotPocket devkit is already upto date." - else - echo "Found a new version of HotPocket devkit." - ! removeLauncher && echo "Removing the launcher failed." - ! createLauncher && echo "Launcher creation failed." - echo $latestVersionTimestamp >$versionTimestampFile - echo "HotPocket devkit update completed !!" - fi - fi - - echo "Updating docker images..." - docker pull $devkitImage &>/dev/null - docker pull $instanceImage &>/dev/null - - # Clear if there's already deployed cluster since they are outdated now. - if docker inspect $deploymentContainerName &>/dev/null; then - echo "Cleaning the deployed contracts..." - teardownDeploymentCluster - fi - - echo "Update Completed !!" - echo "NOTE: You need to re-deploy your contracts to make the new changes effective." -} - -function checkExistance() { - command -v hpdevkit &>/dev/null && [ -f $scriptBinPath ] && [ -d $hpdevkitDataDir ] && - echo -e "hpdevkit is already installed on your host. \nUse the 'hpdevkit' start your local HotPocket testing." && - exit 1 -} - -function online_version_timestamp() { - # Send HTTP HEAD request and get last modified timestamp of the installer package or setup.sh. - curl --silent --head $1 | grep 'Last-Modified:' | sed 's/[^ ]* //' -} - -function install() { - checkExistance - - if [[ ! -d $hpdevkitDataDir ]]; then - ! mkdir $hpdevkitDataDir && echo "Data path creation error." && exit 1 - fi - - ! createLauncher && echo "Launcher creation failed." - - # Creating timestamp file - local latestVersionTimestamp=$(online_version_timestamp $bashScriptUrl) - echo $latestVersionTimestamp >$versionTimestampFile -} - -function uninstall() { - # Remove deployment cluster if exist. - if docker inspect $deploymentContainerName &>/dev/null; then - echo "Cleaning the deployed contracts..." - teardownDeploymentCluster - fi - - # Remove docker images if exist. - if docker image inspect $devkitImage &>/dev/null; then - echo "Removing devkit docker image..." - docker image rm $devkitImage &>/dev/null - fi - if docker image inspect $instanceImage &>/dev/null; then - echo "Removing instance docker image..." - docker image rm $instanceImage &>/dev/null - fi - - echo "Removing binaries..." - if [[ -d $hpdevkitDataDir ]]; then - rm -r $hpdevkitDataDir - fi - - echo "Removing the launcher..." - removeLauncher -} - -function is_user_root() { - [ "$(id -u)" -ne 0 ] && echo "Please run with root privileges (sudo)." && exit 1 -} - -echo "HotPocket devkit launcher ($version)" - -funcCommand=$1 -helpMessage="\nAvailable commands: hpdevkit - \n COMMANDS: - \n\tdeploy - \n\tclean - \n\tstart - \n\tstop - \n\tlogs - \n\tgen - \n\tupdate - \n\tuninstall - \n\thelp" -funcCommandError="Invalid command. Try 'hpdevkit help' for available commands." - -if [ ! -z "$funcCommand" ]; then - if [ "$funcCommand" == "gen" ]; then - echo "Code generator" - codeGenerator $2 $3 $4 - elif [ "$funcCommand" == "update" ]; then - is_user_root - echo "Checking for updates..." - updateDevKit - elif [ "$funcCommand" == "install" ]; then - is_user_root - echo "Installing..." - install - echo "Installation completed." - echo -e $helpMessage - elif [ "$funcCommand" == "uninstall" ]; then - is_user_root - echo "Unstalling hpdevkit..." - uninstall - echo -e "Unstallation Completed.\nThank you for using HotPocket devkit !" - elif [ "$funcCommand" == "help" ]; then - echo -e $helpMessage - else - echo "command: $funcCommand (cluster: $cluster)" - if [ "$funcCommand" == "deploy" ]; then - deploy "$2" - elif [ "$funcCommand" == "clean" ]; then - teardownDeploymentCluster - elif [[ "$funcCommand" == "logs" || "$funcCommand" == "start" || "$funcCommand" == "stop" ]]; then - AUTOREMOVE="true" MOUNTSOCK="true" ENTRYPOINT="cluster" CMD="$1 $2" devKitContainer run - else - echo "$funcCommandError" - fi - fi -else - echo -e $helpMessage -fi - -exit 0 diff --git a/npm/README.md b/npm/README.md index da0efa4..4aef5d0 100644 --- a/npm/README.md +++ b/npm/README.md @@ -1,43 +1,7 @@ # HotPocket developer kit + Evernode uses HotPocket as its smart contract engine. HotPocket smart contracts can be developed using any POSIX-compliant language/framework. To make it easy to develop and test HotPocket smart contracts on your local PC, you can use HotPocket developer kit. -## Installation +## Public documentation -### Prerequisites -HotPocket developer kit requires you to install [Docker Engine](https://docs.docker.com/engine/install/) and [NodeJs](https://nodejs.org/en/) on your development machine. - -### Supports cross platform -This is a npm global package which supports both Linux and Windows -1. Install [prerequisites](#prerequisites). -2. Run the following command to install hpdevkit on your machine. - ``` - npm i -g hpdevkit - ``` - -## Updates -Update `hpdevkit` to the latest and update the supporting docker images. - -Run one of following commands to update hpdevkit. -- Method 1 - Using hpdevkit CLI - ``` - hpdevkit update - ``` - -- Method 2 - Using npm - ``` - npm update -g hpdevkit - ``` - -**NOTE: You need to re-deploy your contracts to make the new changes effective.** - -## Uninstall -Uninstall `hpdevkit` and the supporting docker images and containers. - -- Using hpdevkit CLI - ``` - hpdevkit uninstall - ``` - -**NOTE: Uninstalling from hpdevkit CLI is recommended. If you uninstall using npm you'll have to clean hpdevkit supporting docker images and containers manually.** - -_**NOTE:** In Linux platforms, for Installation, Update and Uninstallation you'll need root privileges. Add `sudo` to above commands._ +https://github.com/EvernodeXRPL/evernode-sdk/blob/main/hpdevkit/index.md diff --git a/windows/.gitignore b/windows/.gitignore deleted file mode 100644 index adb36c8..0000000 --- a/windows/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.exe \ No newline at end of file diff --git a/windows/hpdevkit.ps1 b/windows/hpdevkit.ps1 deleted file mode 100644 index 219c34a..0000000 --- a/windows/hpdevkit.ps1 +++ /dev/null @@ -1,268 +0,0 @@ -$GlobalPrefix = "hpdevkit" -$Version = "0.1.0" - -$Cluster = "default" -$ClusterSize = if ($env:HP_CLUSTER_SIZE) { $env:HP_CLUSTER_SIZE } else { 3 }; -$DefaultNode = if ($env:HP_DEFAULT_NODE) { $env:HP_DEFAULT_NODE } else { 1 }; -$DevKitImage = if ($env:HP_DEVKIT_IMAGE) { $env:HP_DEVKIT_IMAGE } else { "evernodedev/hpdevkit" }; -$InstanceImage = if ($env:HP_INSTANCE_IMAGE) { $env:HP_INSTANCE_IMAGE } else { "evernodedev/hotpocket:0.6.0-ubt.20.04-njs.16" }; -$HpUserPortBegin = if ($env:HP_USER_PORT_BEGIN) { $env:HP_USER_PORT_BEGIN } else { 8081 }; -$HpPeerPortBegin = if ($env:HP_PEER_PORT_BEGIN) { $env:HP_PEER_PORT_BEGIN } else { 22861 }; - -$VolumeMount = "/$($GlobalPrefix)_vol" -$Volume = "$($GlobalPrefix)_$($Cluster)_vol" -$Network = "$($GlobalPrefix)_$($Cluster)_net" -$ContainerPrefix = "$($GlobalPrefix)_$($Cluster)_node" -$BundleMount = "$($VolumeMount)/contract_bundle" -$DeploymentContainerName = "$($GlobalPrefix)_$($Cluster)_deploymgr" -$CodegenContainerName = "$($GlobalPrefix)_codegen" -$ConfigOverridesFile = "hp.cfg.override" -$CodegenOutputDir = "/codegen-output" -$CloudStorage = "https://stevernode.blob.core.windows.net/evernode-dev-bb7ec110-f72e-430e-b297-9210468a4cbb" -$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]$RestartPolicy, [string]$Cmd, [switch]$Status) { - - $Command = "docker $($Mode) -it" - if ($Name) { - $Command += " --name $($Name)" - } - if ($Detached) { - $Command += " -d" - } - if ($AutoRemove) { - $Command += " --rm" - } - if ($MountSock) { - # We mount the host docker socket into the container so we can use it to issue commands to the docker host. - # We use this ability to spin up other containers (HotPocket nodes) on the host. - $Command += " --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock" - } - if ($MountVolume) { - $Command += " --mount type=volume,src=$($Volume),dst=$($VolumeMount)" - } - - if ($EntryPoint) { - $Command += " --entrypoint $($EntryPoint)" - } - else { - $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)" - $Command += " -e CONFIG_OVERRIDES_FILE=$($ConfigOverridesFile) -e CODEGEN_OUTPUT=$($CodegenOutputDir)" - $Command += " -e HP_USER_PORT_BEGIN=$($HpUserPortBegin) -e HP_PEER_PORT_BEGIN=$($HpPeerPortBegin)" - - $Command += " $($DevKitImage)" - if ($Cmd) { - if ($EntryPoint) { - $Command += " $($Cmd)" - } - else { - $Command += " -c '$($Cmd)'" - } - } - - Invoke-Expression $Command 2>&1 | Write-Host - - if ($Status) { - if ($LASTEXITCODE -eq 0) { - return $True - } - else { - return $False - } - } -} - -function ExecuteInDeploymentContainer([string]$Cmd) { - docker exec -it $DeploymentContainerName /bin/bash -c $Cmd -} - -function InitializeDeploymentCluster() { - $Null = docker inspect $DeploymentContainerName *>&1 - if (! ($?)) { - Write-Host "Initializing deployment cluster" - - # Stop cluster if running. Create cluster if not exists. - DevKitContainer -Mode "run" -AutoRemove -MountSock -Cmd "cluster stop ; cluster create" - - # Spin up management container. - DevKitContainer -Mode "run" -Name $DeploymentContainerName -Detached -MountSock -MountVolume -RestartPolicy "unless-stopped" - - # Bind the instance mesh network config together. - ExecuteInDeploymentContainer -Cmd "cluster bindmesh" - } -} - -function TeardownDeploymentCluster() { - $Null = docker stop $DeploymentContainerName *>&1 - $Null = docker rm $DeploymentContainerName *>&1 - DevKitContainer -Mode "run" -AutoRemove -MountSock -Cmd "cluster stop ; cluster destroy" -} - -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. - $PrepareBundleDir = "" - if ((Get-Item $Path) -is [System.IO.DirectoryInfo]) { - $PrepareBundleDir = "rm -rf $($BundleMount)" - } - else { - $PrepareBundleDir = "mkdir -p $($BundleMount) && rm -rf $($BundleMount)/* $($BundleMount)/.??*" - } - ExecuteInDeploymentContainer -Cmd $PrepareBundleDir - docker cp $Path "$($DeploymentContainerName):$($BundleMount)" - - # Sync contract bundle to all instance directories in the cluster. - ExecuteInDeploymentContainer -Cmd "cluster stop ; cluster sync ; cluster start" - - if ($DefaultNode -gt 0) { - Write-Host "Streaming logs of node $($DefaultNode):" - ExecuteInDeploymentContainer -Cmd "cluster logs $($DefaultNode)" - } - } - else { - Write-Host "Please specify directory or file path to deploy." - } -} - -Function CodeGenerator() { - $ProjName = $args[2] - if (Test-Path -Path $ProjName) { - "Directory '$($ProjName)' already exists." - return - } - - if (DevKitContainer -Status -Mode "run" -Name $CodegenContainerName -EntryPoint "codegen" -Cmd "$($args[0]) $($args[1]) $($ProjName)") { - docker cp "$($CodegenContainerName):$($CodegenOutputDir)" ./$ProjName - Write-Host "Project '$($ProjName)' created." - } - docker rm "$($CodegenContainerName)" 2>&1 | Out-Null -} - -Function UpdateHPDevKit() { - Write-Host "Checking for HotPocket devkit updates..." - $ResHeaders = (Invoke-WebRequest -Uri $HPDevKitExeUrl -Method Head -UseBasicParsing).Headers - $LastRemoteModifiedTime = [datetime]$ResHeaders["Last-Modified"] - - $currentExeModifiedTime = [datetime]((Get-ItemProperty -Path "$($ExePath)\hpdevkit.exe" -Name LastWriteTime).LastWriteTime).ToUniversalTime() - if ($ResHeaders["Last-Modified"]) { - if ($LastRemoteModifiedTime -lt $currentExeModifiedTime) { - Write-Host "Your HotPocket devkit is up to date." - } - else { - Write-Host "An HotPocket devkit update is available." - # Download the updated version. - Write-Host "Downloading the update..." - Invoke-WebRequest -Uri $HPDevKitExeUrl -OutFile "$($ExePath)\hpdevkit.exe.new" - - # Swap the files. - Rename-Item -Path "$($ExePath)\hpdevkit.exe" -NewName "$($ExePath)\$($HPDevKitBackup)" - Rename-Item -Path "$($ExePath)\hpdevkit.exe.new" -NewName "$($ExePath)\hpdevkit.exe" - Write-Host "HotPocket devkit update completed !!" - } - - } - else { - Write-Host "Could not check for hpdevkit updates. Online installer not found." - } - - ## Pull the HPDevkit updated Docker Image from Docker Hub. - Write-Host "Pulling the latest $DevKitImage Image." - docker pull $DevKitImage - - ## Pull the updated Docker instance image from Docker Hub. - Write-Host "Pulling the latest $InstanceImage Image." - docker pull $InstanceImage - - ## Clear if there's already deployed cluster since they are outdated now. - $Null = docker inspect $DeploymentContainerName *>&1 - if ($?) { - Write-Host "Cleaning the deployed contracts." - TeardownDeploymentCluster - } - - Write-Host "Update Completed !!" - Write-Host "NOTE: You need to re-deploy your contracts to make the new changes effective." -} - -if ($ExePath.Contains('hpdevkit.exe')) { - $ExePath = $ExePath.Replace("\hpdevkit.exe", "") -} -elseif ($ExePath.Contains('powershell.exe')) { - # If Powershell script is used. - $ExePath = $PSScriptRoot -} - -if (Test-Path -Path "$($ExePath)\$($HPDevKitBackup)") { - # Removing the previous version backup file when launching the new version. - Remove-Item "$($ExePath)\$($HPDevKitBackup)" -} - -Write-Host "HotPocket devkit launcher ($($Version))" - -$Command = $args[0] -$CommandError = "Invalid command. Try 'hpdevkit help' for available commands." -$HelpMessage = "Available commands: hpdevkit - COMMANDS: - deploy - clean - start - stop - logs - gen - update - help" - -if ($Command) { - - if ($Command -eq "gen") { - 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") { - Deploy -Path $args[1] - } - elseif ($Command -eq "clean") { - TeardownDeploymentCluster - } - elseif ($Command -eq "logs" -OR $Command -eq "start" -OR $Command -eq "stop") { - DevKitContainer -Mode "run" -AutoRemove -MountSock -EntryPoint "cluster" -Cmd "$($args)" - } - else { - Write-Host $CommandError - } - } -} -else { - Write-Host $CommandError -} \ No newline at end of file