Add "occlum new" command
This commit is contained in:
parent
0252f0949d
commit
66e5cefec2
@ -30,12 +30,16 @@ Hello World
|
|||||||
```
|
```
|
||||||
Note that the Occlum toolchain is not cross-compiling in the traditional sense: the binaries built by the Occlum toolchain is also runnable on Linux. This property makes it convenient to compile, debug, and test user programs intended for Occlum.
|
Note that the Occlum toolchain is not cross-compiling in the traditional sense: the binaries built by the Occlum toolchain is also runnable on Linux. This property makes it convenient to compile, debug, and test user programs intended for Occlum.
|
||||||
|
|
||||||
**Step 2. Initialize a directory as the Occlum instance via `occlum init`**
|
**Step 2. Initialize a directory as the Occlum instance via `occlum init` or `occlum new`**
|
||||||
```
|
```
|
||||||
$ mkdir occlum_instance && cd occlum_instance
|
$ mkdir occlum_instance && cd occlum_instance
|
||||||
$ occlum init
|
$ occlum init
|
||||||
```
|
```
|
||||||
The `occlum init` command creates the compile-time and run-time state of Occlum in the current working directory. Each Occlum instance directory should be used for a single instance of an application; multiple applications or different instances of a single application should use different Occlum instances.
|
or
|
||||||
|
```
|
||||||
|
$ occlum new occlum_instance
|
||||||
|
```
|
||||||
|
The `occlum init` command creates the compile-time and run-time state of Occlum in the current working directory. The `occlum new` command does basically the same thing but in a new instance diretory. Each Occlum instance directory should be used for a single instance of an application; multiple applications or different instances of a single application should use different Occlum instances.
|
||||||
|
|
||||||
**Step 3. Generate a secure Occlum FS image and Occlum SGX enclave via `occlum build`**
|
**Step 3. Generate a secure Occlum FS image and Occlum SGX enclave via `occlum build`**
|
||||||
```
|
```
|
||||||
|
@ -21,9 +21,9 @@ int occlum_pal_get_version(void);
|
|||||||
* Occlum PAL attributes
|
* Occlum PAL attributes
|
||||||
*/
|
*/
|
||||||
typedef struct occlum_pal_attr {
|
typedef struct occlum_pal_attr {
|
||||||
// Occlum instance directory.
|
// Occlum instance directory.
|
||||||
//
|
//
|
||||||
// Specifies the path of an Occlum instance directory, which is usually created with the
|
// Specifies the path of an Occlum instance directory, which is usually created with the
|
||||||
// `occlum new` command. The default value is "."; that is, the current working directory
|
// `occlum new` command. The default value is "."; that is, the current working directory
|
||||||
// is the Occlum instance directory.
|
// is the Occlum instance directory.
|
||||||
const char *instance_dir;
|
const char *instance_dir;
|
||||||
|
30
tools/occlum
30
tools/occlum
@ -34,8 +34,11 @@ report_arg_error() {
|
|||||||
echo ""
|
echo ""
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage:
|
Usage:
|
||||||
|
occlum new <path>
|
||||||
|
Create a new directory at <path> and initialize as the Occlum instance.
|
||||||
|
|
||||||
occlum init
|
occlum init
|
||||||
Initialize a directory as the Occlum instance
|
Initialize a directory as the Occlum instance.
|
||||||
|
|
||||||
occlum build [--sign-key <key_path>] [--sign-tool <tool_path>] [-f/--force]
|
occlum build [--sign-key <key_path>] [--sign-tool <tool_path>] [-f/--force]
|
||||||
Build and sign an Occlum SGX enclave (.so) and generate its associated secure FS image
|
Build and sign an Occlum SGX enclave (.so) and generate its associated secure FS image
|
||||||
@ -70,6 +73,28 @@ check_has_built() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cmd_new() {
|
||||||
|
if [ -z $@ ]; then
|
||||||
|
echo "Error: target directory is not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dir_path="$@"
|
||||||
|
if [[ "$dir_path" != "/"* ]]; then
|
||||||
|
dir_path="$instance_dir/$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -e "$dir_path" ]]; then
|
||||||
|
echo "Error: destination \"$dir_path\" already exists"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p $dir_path
|
||||||
|
instance_dir=$dir_path
|
||||||
|
status_file=$instance_dir/.__occlum_status
|
||||||
|
cd $dir_path && cmd_init
|
||||||
|
}
|
||||||
|
|
||||||
cmd_init() {
|
cmd_init() {
|
||||||
if [ -f "$status_file" ]; then
|
if [ -f "$status_file" ]; then
|
||||||
echo "Error: the current working directory has been initialized as an Occlum instance"
|
echo "Error: the current working directory has been initialized as an Occlum instance"
|
||||||
@ -261,6 +286,9 @@ fi
|
|||||||
|
|
||||||
cmd=$1
|
cmd=$1
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
|
new)
|
||||||
|
cmd_new "${@:2:1}"
|
||||||
|
;;
|
||||||
init)
|
init)
|
||||||
cmd_init
|
cmd_init
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user