Skip to content

Commit

Permalink
Merge pull request #18 from playground/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
playground authored Nov 29, 2021
2 parents 8053408 + 601d918 commit defd31e
Show file tree
Hide file tree
Showing 35 changed files with 1,145 additions and 695 deletions.
124 changes: 35 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ Open Horizon toolkit is a CLI built with Typescript for the NodeJS developers.

## Pre-release version of hzn-cli, howto?

For now, you can give it a test drive by cloning this repo

```git clone [email protected]:playground/hzn-cli.git```

cd into hzn-cli then run the following command to install it on your device, this will install hzn-cli and the command will be available globally.

NOTE: Node version 12 or higher is required to be installed before running the following command

```npm run local```
```npm i -g hzn-cli```

After installlation run

Expand All @@ -25,86 +17,40 @@ After installlation run
Deploy <action> to Org <org>
Positionals:
action Available actions: test, buildServiceImage, pushServiceImage,
publishService, publishPatterrn, buildMMSImage, pushMMSImage,
publishMMSService, publishMMSPattern, agentRun, publishMMSObject,
unregisterAgent, registerAgent, showHznInfo, updateHznInfo,
listService, listPattern, listNode, listObject, listDeploymentPolicy,
listNodePattern, checkConfigState, getDeviceArch, createHznKey
action Available actions: allInOneMMS, buildMMSImage, buildServiceImage,
checkConfigState, createHznKey, dockerImageExists, getDeviceArch,
listDeploymentPolicy, listNode, listNodePattern, listObject,
listPattern, listService, publishMMSObject, publishMMSPattern,
publishMMSService, publishPatterrn, publishService, pullDockerImage,
pushMMSImage, pushServiceImage, registerAgent, setup, showHznInfo,
test, uninstallHorizon, unregisterAgent, updateHznInfo
[string] [required]
Options:
--version Show version number [boolean]
--org Organization to be deployed to [string]
--configpath Specify path to your configuration, default is ./config
[string]
--name Name of service, pattern, policy & etc. [string]
-h, --help Show help [boolean]
--version Show version number [boolean]
--org Organization to be deployed to [string]
--config_path Specify path to your configuration, default is
./config [string]
--name Name of service, pattern, policy & etc. [string]
--object_type Type of object [string]
--object_id Id of object to be published [string]
--object Object file to be published [string]
--pattern MMS pattern [string]
--skip_config_update Do not prompt for config updates [string]
-h, --help Show help [boolean]
```
## To setup your environment, you will need to run
```oh deploy setup```

## To execute any of the "oh" actions, .env-hzn.json config file is required
This will prompt you for your credential, Docker Hub Id & other configuration parameters.
This will also install and setup hzn envirnoment for you if it hasn't been installled.

.env-hzn.json template
```
{
"biz":
{
"envVars": {
"HZN_ORG_ID": "<HZN_ORG_ID>",
"HZN_EXCHANGE_USER_AUTH": "<HZN_EXCHANGE_USER_AUTH>",
"HZN_EXCHANGE_URL": "<HZN_EXCHANGE_URL>",
"HZN_FSS_CSSURL": "<HZN_FSS_CSSURL>",
"SERVICE_NAME": "<YOUR_SERVICE_NAME>",
"SERVICE_VERSION": "<YOUR_SERVICE_VERSION>",
"SERVICE_CONTAINER_NAME": "<YOUR_SERVICE_CONTAINER_NAME>",
"SERVICE_CONTAINER_CREDS": "",
"YOUR_DOCKERHUB_ID": "<YOUR_DOCKERHUB_ID>",
"VOLUME_MOUNT": "<VOLUME_MOUNT>",
"MMS_SHARED_VOLUME": "<MMS_SHARED_VOLUME>",
"MMS_CONTAINER_CREDS": "",
"MMS_CONTAINER_NAME": "<MMS_CONTAINER_NAME>",
"MMS_SERVICE_NAME": "<MMS_SERVICE_NAME>",
"MMS_SERVICE_VERSION": "<MMS_SERVICE_VERSION>",
"MMS_OBJECT_TYPE": "<MMS_OBJECT_TYPE>",
"MMS_OBJECT_ID": "<MMS_OBJECT_ID>",
"MMS_OBJECT_FILE": "config/config.json",
"UPDATE_FILE_NAME": "<UPDATE_FILE_NAME>"
},
"metaVars": {
}
},
"demo":
{
"envVars": {
"HZN_ORG_ID": "<HZN_ORG_ID>",
"HZN_EXCHANGE_USER_AUTH": "<HZN_EXCHANGE_USER_AUTH>",
"HZN_EXCHANGE_URL": "<HZN_EXCHANGE_URL>",
"HZN_FSS_CSSURL": "<HZN_FSS_CSSURL>",
"SERVICE_NAME": "<YOUR_SERVICE_NAME>",
"SERVICE_VERSION": "<YOUR_SERVICE_VERSION>",
"SERVICE_CONTAINER_NAME": "<YOUR_SERVICE_CONTAINER_NAME>",
"SERVICE_CONTAINER_CREDS": "",
"YOUR_DOCKERHUB_ID": "<YOUR_DOCKERHUB_ID>",
"VOLUME_MOUNT": "<VOLUME_MOUNT>",
"MMS_SHARED_VOLUME": "<MMS_SHARED_VOLUME>",
"MMS_CONTAINER_CREDS": "",
"MMS_CONTAINER_NAME": "<MMS_CONTAINER_NAME>",
"MMS_SERVICE_NAME": "<MMS_SERVICE_NAME>",
"MMS_SERVICE_VERSION": "<MMS_SERVICE_VERSION>",
"MMS_OBJECT_TYPE": "<MMS_OBJECT_TYPE>",
"MMS_OBJECT_ID": "<MMS_OBJECT_ID>",
"MMS_OBJECT_FILE": "config/config.json",
"UPDATE_FILE_NAME": "<UPDATE_FILE_NAME>"
},
"metaVars": {
}
}
}
```
## To execute any of the "oh" actions
```oh deploy <action>, for example: oh deploy registerAgent```

## After installation, you can test out the cli by running
## After installation and initialization, you can test out the cli by running

```oh deploy test --configpath /home/pi/config```
```oh deploy test```
```
_ _ _
Expand All @@ -121,25 +67,25 @@ process completed.
## Here are a few examples of actions you can perform with "oh", default org is "biz"

Build service docker image
```oh deploy buildServiceImage --config_path /home/pi/config```
```oh deploy buildServiceImage```

Push service docker image
```oh deploy pushServiceImage --config_path /home/pi/config```
```oh deploy pushServiceImage```

Publish service to management hub
```oh deploy publishService --config_path /home/pi/config```
```oh deploy publishService```

Publish service pattern
```oh deploy publishPattern --config_path /home/pi/config```
```oh deploy publishPattern```

Publish MMS service
```oh deploy publishMMSService --config_path /home/pi/config```
```oh deploy publishMMSService```

Publish MMS pattern
Publish MMS pattern and specify path to the policy.json
```oh deploy publishMMSPattern --config_path /home/pi/config```

Publish MMS Object file
```oh deploy publishMMSObject --object_type=object_detection --object_id=config.json --object=/Users/jeff/Downloads/demo-model/demo/version1/model.zip --pattern=pattern-pi-mms-service-arm --config_path=config```
```oh deploy publishMMSObject --object_type=object_detection --object_id=config.json --object=/Users/jeff/Downloads/demo-model/demo/version1/model.zip --pattern=pattern-pi-mms-service-arm```

*Register agent (org=demo)-
```oh deploy registerAgent --configpath /home/pi/config --org demo```
```oh deploy registerAgent --org demo```
1 change: 1 addition & 0 deletions build/commands/deploy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare type Options = {
object_id: string | undefined;
object: string | undefined;
pattern: string | undefined;
skip_config_update: string | undefined;
};
export declare const command: string;
export declare const desc: string;
Expand Down
88 changes: 66 additions & 22 deletions build/commands/deploy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/commands/deploy.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions build/common/src/config/mms/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "pattern-${MMS_SERVICE_NAME}-$ARCH",
"label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH",
"description": "Pattern for $MMS_SERVICE_NAME for $ARCH",
"public": false,
"services": [
{
"serviceUrl": "$MMS_SERVICE_NAME",
"serviceOrgid": "$HZN_ORG_ID",
"serviceArch": "$ARCH",
"serviceVersions": [
{
"version": "$MMS_SERVICE_VERSION"
}
]
}
]
}
9 changes: 9 additions & 0 deletions build/common/src/config/mms/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": [
{
"name": "openhorizon.allowPrivileged",
"value": true
}
],
"constraints": [ ]
}
Loading

0 comments on commit defd31e

Please sign in to comment.