Skip to content

Commands CheatSheet

GregoireBailly edited this page Aug 6, 2020 · 8 revisions

Worspace Initialisation

sudo npm i -g iexec
iexec wallet create
 mkdir ~/iexec-projects
 cd ~/iexec-projects
 git clone https://github.com/iExecBlockchainComputing/private-code-valorisation_tutorial.git
cd private-code-valorisation_tutorial/
iexec init --skip-wallet
iexec storage init
iexec wallet show --chain goerli
iexec wallet getRLC
iexec account deposit 200
iexec account show

Application development

Preparation

 cd ~iexec-projects/private-code-valorisation_tutorial/app/

~/iexec-projects/private-code-valorisation_tutorial/app/src/app.py

import os
import sys
import json
iexec_out = os.environ['IEXEC_OUT']
iexec_in = os.environ['IEXEC_IN']

sys.path.insert(0, iexec_in + '/private-code-dataset')
import private_code

private_code.main()


print("POST Private code operations")

# Declare everything is computed
with open(iexec_out + '/determinism.txt', 'w+') as fout:
    fout.write("It is deterministic.")
with open(iexec_out + '/computed.json', 'w+') as f:
    json.dump({ "deterministic-output-path" : iexec_out + '/determinism.txt' }, f)

print("END")
print("----------------------------")

~/iexec-projects/private-code-valorisation_tutorial/app/Dockerfile

FROM sconecuratedimages/public-apps:python-3.7.3-alpine3.10-scone3.0

### install python3 dependencies you need
RUN SCONE_MODE=sim pip3 install wget

COPY ./src /app

###  protect file system with Scone
COPY ./protect-fs.sh ./Dockerfile /build/
RUN sh /build/protect-fs.sh /app

ENTRYPOINT ["python", "-B", "/app/app.py"]
docker login
./build 
docker image push <username>/python-launcher-app:0.0.1

Deployment

iexec app init

~/iexec-projects/iexec.json

{  
  ...
  "app": {
    "owner": "<0x-your-wallet-address>",
    "name": "My python launcher App",
    "type": "DOCKER",
    "multiaddr": "registry.hub.docker.com/<username>/python-launcher-app:0.0.1",
    "checksum": "<0xf51494d7a...>",
    "mrenclave": "<5abc...|d72c...|16e7…|python -B /app/app.py>"
  }
  ...
}
iexec app deploy
iexec order init --app

~/iexec-projects/iexec.json

{
  ...
  "apporder": {
      "app": "0x...",
      "appprice": "0",
      "volume": "1000000",
      "tag": ["tee"],
      "datasetrestrict": "0x0000000000000000000000000000000000000000",
      "workerpoolrestrict": "0x0000000000000000000000000000000000000000",
      "requesterrestrict": "0x0000000000000000000000000000000000000000"
  ...
}
iexec order sign --app && iexec order publish --app

Dataset development

Preparation

iexec dataset init --encrypted
datasets/
├── encrypted
└── original
        └── private-code-dataset
            └── private_code.py

~/iexec-projects/private-code-valorisation_tutorial/datasets/original/private-code-dataset/private_code.py

import os
import sys
import wget

iexec_out = os.environ['IEXEC_OUT']
iexec_in = os.environ['IEXEC_IN']

def read_file(filepath):
    with open(filepath, "r") as f:
        f.seek(0)
        return f.read()

def write_file(path, data):
    with open(path, "w+") as f:
        f.write(data)


def bubbleSort(arr, asc):
    n = len(arr)
 
    # Traverse through all array elements
    for i in range(n):
 
        # Last i elements are already in place
        for j in range(0, n-i-1):
 
            # traverse the array from 0 to n-i-1
            # Swap if the element found is greater
            # than the next element
            if asc:
                if arr[j] > arr[j+1] :
                    arr[j], arr[j+1] = arr[j+1], arr[j]
            else:
                if arr[j] < arr[j+1] :
                    arr[j], arr[j+1] = arr[j+1], arr[j]

def main():
    print("------------------------")
    print("STARTING private code execution")

    # treat the args
    # /app/app.py https://inputfile_download_link.com <asc/desc> 
    args = sys.argv

    if len(args) <= 1:
        print("Error: Missing input arguments.\nUsage:")
        print("  iexec app run ... --args \"https://inputfile_download_link.com <asc/desc> \"")
        sys.exit(1)
    
    url = args[1]
    print(" - Using input file from URL: "+ url)

    direction_asc = True
    if len(args) > 2 and args[2] == "desc":
        direction_asc = False
        print(" - Descending sort")
    else:
        print(" - Ascending sort")


    # Download the input file
    print("DOWNLOADING input file")
    wget.download(url, iexec_in + '/inputs.csv')


    # Check the input file is here
    print("CHECKING Input file")
    if os.path.exists(iexec_in + '/inputs.csv'):
        data = read_file(iexec_in + '/inputs.csv').split(",")
        print("Input file content:   ", read_file(iexec_in + '/inputs.csv'))
    else:
        print("Cannot find input file, check that the dowload URL is correct")
        sys.exit(1)
    

    # Work on data
    # print(data, "data------")
    print("SORTING")
    sort = [float(i) for i in data]
 
    bubbleSort(sort, direction_asc)
    
    #write result
    print("WRITING result")
    result = str(sort)
    write_file(iexec_out + '/my-result.txt', result)

    print("END of the private code execution")
iexec dataset encrypt --algorithm scone

Deployment

~/iexec-projects/iexec.json

{
  ...
 "dataset": {
    "owner": "0x...",
    "name": "My private code dataset",
    "multiaddr": "https://github.com/iExecBlockchainComputing/private-code-valorisation_tutorial/raw/master/datasets/encrypted/dataset_privatecodedataset.zip",
    "checksum": "0x21415..."
  }
}
sha256sum datasets/encrypted/dataset_privatecodedataset.zip
iexec dataset deploy
iexec dataset push-secret <0x-your-dataset-address>
iexec order init --dataset

~/iexec-projects/iexec.json

{
  ...
 "datasetorder": {
      "dataset": "0x...",
      "datasetprice": "20",
      "volume": "100",
      "tag": []",
      "apprestrict": "0x...",
      "workerpoolrestrict": "0x0000000000000000000000000000000000000000",
      "requesterrestrict": "0x0000000000000000000000000000000000000000"
    }
  ...
}

A running already deployed app if needed: 0xc348738d4Aa062D06bD4A047135bd5aA861646Ad.

iexec order sign --dataset && iexec order publish --dataset

Application execution

Preparation

input_data.csv

1,9,0,4,3,7,2,5,8,6,12,123,14,90,18

or https://github.com/iExecBlockchainComputing/private-code-valorisation_tutorial/raw/master/input_data.csv

iexec wallet create
iexec result generate-keys
iexec result push-secret

Execution

iexec app run <0x-your-app-address>  \
  --dataset <0x-your-dataset-address>  \
  --tag tee  \
  --args "<input-file-URL> <asc/desc>"  \
  --encrypt-result  \
  --watch

If needed:

  • A deployed app 0xc348738d4Aa062D06bD4A047135bd5aA861646Ad;
  • A deployed dataset 0x26e485f3F966a75a96Caadf551D5C327AB41Df46;
iexec task show <0x-your-task-id> --download
iexec result decrypt <0x-your-task-id.zip>
unzip results.zip -d my-decrypted-result
cat my-decrypted-result/my-result.txt
Clone this wiki locally