mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
update url-downloader to fluence cli (#442)
* update to fluence cli * update aqua * add config toml, update aqua script
This commit is contained in:
parent
d3a5daab30
commit
cdec8be7ae
@ -1,18 +1,31 @@
|
||||
data GetWorkersInfoDealsDefaultWorker:
|
||||
installationSpells: ?u8
|
||||
definition: string
|
||||
timestamp: string
|
||||
dealIdOriginal: string
|
||||
dealId: string
|
||||
chainNetwork: string
|
||||
chainNetworkId: f64
|
||||
chainNetworkId: u64
|
||||
|
||||
data GetWorkersInfoDeals:
|
||||
defaultWorker: GetWorkersInfoDealsDefaultWorker
|
||||
|
||||
data GetWorkersInfoHostsDefaultWorkerInstallationSpells:
|
||||
hostId: string
|
||||
spellId: string
|
||||
workerId: string
|
||||
|
||||
data GetWorkersInfoHostsDefaultWorker:
|
||||
definition: string
|
||||
installationSpells: []GetWorkersInfoHostsDefaultWorkerInstallationSpells
|
||||
timestamp: string
|
||||
relayId: string
|
||||
|
||||
data GetWorkersInfoHosts:
|
||||
defaultWorker: GetWorkersInfoHostsDefaultWorker
|
||||
|
||||
data GetWorkersInfo:
|
||||
deals: GetWorkersInfoDeals
|
||||
hosts: ?u8
|
||||
hosts: GetWorkersInfoHosts
|
||||
|
||||
func getWorkersInfo() -> GetWorkersInfo:
|
||||
<- GetWorkersInfo(deals=GetWorkersInfoDeals(defaultWorker=GetWorkersInfoDealsDefaultWorker(installationSpells=nil,definition="bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy",timestamp="2023-04-04T00:29:31.854Z",dealIdOriginal="0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E",dealId="d0c75aeea62bc0abf16f5f01361277cc8287ab0e",chainNetwork="testnet",chainNetworkId=80001.0)),hosts=nil)
|
||||
<- GetWorkersInfo(deals=GetWorkersInfoDeals(defaultWorker=GetWorkersInfoDealsDefaultWorker(definition="bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m",timestamp="2023-04-23T07:01:18.682Z",dealIdOriginal="0x9d7503E13Bc2d3430536e3d5D635D8172141d884",dealId="9d7503e13bc2d3430536e3d5d635d8172141d884",chainNetwork="testnet",chainNetworkId=1313161555)),hosts=GetWorkersInfoHosts(defaultWorker=GetWorkersInfoHostsDefaultWorker(definition="bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m",installationSpells=[GetWorkersInfoHostsDefaultWorkerInstallationSpells(hostId="12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE",spellId="039f4e06-923e-4a21-8814-8164fa9b137c",workerId="12D3KooWKsxVXgnpL4wrTts9d49jiNSEN1auaxotdMYa4HpFS66g")],timestamp="2023-04-23T07:00:05.549Z",relayId="12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA")))
|
||||
|
@ -48,16 +48,7 @@
|
||||
"nullable": true,
|
||||
"required": [],
|
||||
"title": "Volumes",
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)"
|
||||
},
|
||||
"preopenedFiles": {
|
||||
"type": "array",
|
||||
"title": "Preopened files",
|
||||
"description": "A list of files and directories that this module could access with WASI",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file"
|
||||
},
|
||||
"envs": {
|
||||
"type": "object",
|
||||
@ -153,16 +144,7 @@
|
||||
"nullable": true,
|
||||
"required": [],
|
||||
"title": "Volumes",
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)"
|
||||
},
|
||||
"preopenedFiles": {
|
||||
"type": "array",
|
||||
"title": "Preopened files",
|
||||
"description": "A list of files and directories that this module could access with WASI",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file"
|
||||
},
|
||||
"envs": {
|
||||
"type": "object",
|
||||
@ -257,7 +239,7 @@
|
||||
"type": "object",
|
||||
"title": "Dependencies",
|
||||
"nullable": true,
|
||||
"description": "A map of dependency versions",
|
||||
"description": "(For advanced users) Overrides for the project dependencies",
|
||||
"properties": {
|
||||
"npm": {
|
||||
"type": "object",
|
||||
@ -463,6 +445,14 @@
|
||||
]
|
||||
},
|
||||
"required": []
|
||||
},
|
||||
"aquaImports": {
|
||||
"type": "array",
|
||||
"description": "A list of path to be considered by aqua compiler to be used as imports. First dependency in the list has the highest priority. Priority of imports is considered in the following order: imports from --import flags, imports from aquaImports property in fluence.yaml, project's .fluence/aqua dir, npm dependencies from fluence.yaml, npm dependencies from user's .fluence/config.yaml, npm dependencies recommended by fluence",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -38,16 +38,7 @@
|
||||
"nullable": true,
|
||||
"required": [],
|
||||
"title": "Volumes",
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)"
|
||||
},
|
||||
"preopenedFiles": {
|
||||
"type": "array",
|
||||
"title": "Preopened files",
|
||||
"description": "A list of files and directories that this module could access with WASI",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file"
|
||||
},
|
||||
"envs": {
|
||||
"type": "object",
|
||||
|
@ -40,16 +40,7 @@
|
||||
"nullable": true,
|
||||
"required": [],
|
||||
"title": "Volumes",
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)"
|
||||
},
|
||||
"preopenedFiles": {
|
||||
"type": "array",
|
||||
"title": "Preopened files",
|
||||
"description": "A list of files and directories that this module could access with WASI",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file"
|
||||
},
|
||||
"envs": {
|
||||
"type": "object",
|
||||
@ -99,16 +90,7 @@
|
||||
"nullable": true,
|
||||
"required": [],
|
||||
"title": "Volumes",
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)"
|
||||
},
|
||||
"preopenedFiles": {
|
||||
"type": "array",
|
||||
"title": "Preopened files",
|
||||
"description": "A list of files and directories that this module could access with WASI",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
"description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file"
|
||||
},
|
||||
"envs": {
|
||||
"type": "object",
|
||||
|
@ -14,29 +14,6 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"installation_spells": {
|
||||
"type": "array",
|
||||
"description": "A list of installation spells",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"spell_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"worker_id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host_id",
|
||||
"spell_id",
|
||||
"worker_id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"definition": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -62,7 +39,6 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"installation_spells",
|
||||
"timestamp",
|
||||
"definition",
|
||||
"dealId",
|
||||
@ -80,6 +56,13 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"definition": {
|
||||
"type": "string"
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"description": "ISO timestamp of the time when the worker was deployed"
|
||||
},
|
||||
"installation_spells": {
|
||||
"type": "array",
|
||||
"description": "A list of installation spells",
|
||||
@ -103,21 +86,14 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"definition": {
|
||||
"type": "string"
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"description": "ISO timestamp of the time when the worker was deployed"
|
||||
},
|
||||
"relayId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"installation_spells",
|
||||
"timestamp",
|
||||
"definition",
|
||||
"installation_spells",
|
||||
"relayId"
|
||||
]
|
||||
},
|
||||
|
@ -3,11 +3,8 @@ name = "local_storage"
|
||||
load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/local_storage.wasm"
|
||||
logger_enabled = true
|
||||
|
||||
[module.wasi]
|
||||
preopened_files = [ "./tmp" ]
|
||||
|
||||
[module.wasi.mapped_dirs]
|
||||
sites = "./tmp"
|
||||
[module.wasi.mapped_dirs]
|
||||
sites = "./tmp"
|
||||
|
||||
[[module]]
|
||||
name = "curl_adapter"
|
||||
|
@ -5,12 +5,20 @@
|
||||
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md
|
||||
|
||||
version: 0
|
||||
hosts:
|
||||
defaultWorker:
|
||||
definition: bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m
|
||||
installation_spells:
|
||||
- host_id: 12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE
|
||||
spell_id: 039f4e06-923e-4a21-8814-8164fa9b137c
|
||||
worker_id: 12D3KooWKsxVXgnpL4wrTts9d49jiNSEN1auaxotdMYa4HpFS66g
|
||||
timestamp: 2023-04-23T07:00:05.549Z
|
||||
relayId: 12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA
|
||||
deals:
|
||||
defaultWorker:
|
||||
installation_spells: []
|
||||
definition: bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy
|
||||
timestamp: 2023-04-04T00:29:31.854Z
|
||||
dealIdOriginal: "0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E"
|
||||
dealId: d0c75aeea62bc0abf16f5f01361277cc8287ab0e
|
||||
definition: bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m
|
||||
timestamp: 2023-04-23T07:01:18.682Z
|
||||
dealIdOriginal: "0x9d7503E13Bc2d3430536e3d5D635D8172141d884"
|
||||
dealId: 9d7503e13bc2d3430536e3d5d635d8172141d884
|
||||
chainNetwork: testnet
|
||||
chainNetworkId: 80001
|
||||
chainNetworkId: 1313161555
|
||||
|
@ -1,16 +0,0 @@
|
||||
# yaml-language-server: $schema=schemas/workers.yaml.json
|
||||
|
||||
# A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command
|
||||
|
||||
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md
|
||||
|
||||
version: 0
|
||||
deals:
|
||||
defaultWorker:
|
||||
installation_spells: []
|
||||
definition: bafkreigvh7cxlf5nkisqqxq6alpoj32l44ttxkfxafa6agp2u344kl3k4m
|
||||
timestamp: 2023-04-03T22:37:49.594Z
|
||||
dealIdOriginal: "0xEA6f3D3177c40123C7B8B1d89440F1DdcfA6014B"
|
||||
dealId: ea6f3d3177c40123c7b8b1d89440f1ddcfa6014b
|
||||
chainNetwork: testnet
|
||||
chainNetworkId: 80001
|
@ -1,12 +0,0 @@
|
||||
# yaml-language-server: $schema=.fluence/schemas/fluence-lock.yaml.json
|
||||
|
||||
# Defines a lock file for Fluence Project dependencies. When dependencies are installed - their exact versions are saved here.
|
||||
|
||||
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence-lock.md
|
||||
|
||||
version: 0
|
||||
npm:
|
||||
"@fluencelabs/aqua": 0.10.3
|
||||
"@fluencelabs/aqua-lib": 0.6.0
|
||||
"@fluencelabs/spell": 0.5.7
|
||||
"@fluencelabs/registry": 0.8.2
|
@ -7,14 +7,8 @@
|
||||
version: 2
|
||||
aquaInputPath: src/aqua/main.aqua
|
||||
dependencies:
|
||||
npm:
|
||||
"@fluencelabs/aqua": 0.10.3
|
||||
"@fluencelabs/aqua-lib": 0.6.0
|
||||
"@fluencelabs/spell": 0.5.7
|
||||
"@fluencelabs/registry": 0.8.2
|
||||
cargo:
|
||||
marine: 0.14.0
|
||||
mrepl: 0.21.2
|
||||
mrepl: 0.21.3
|
||||
workers:
|
||||
defaultWorker:
|
||||
services: [ url_downloader ]
|
||||
@ -25,8 +19,8 @@ deals:
|
||||
hosts:
|
||||
defaultWorker:
|
||||
peerIds:
|
||||
- 12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr
|
||||
relays: kras
|
||||
- 12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE #stage
|
||||
relays: stage
|
||||
services:
|
||||
url_downloader:
|
||||
get: service
|
||||
|
@ -1,52 +1,59 @@
|
||||
import "workers.aqua"
|
||||
import "services.aqua"
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import "@fluencelabs/registry/subnetwork.aqua"
|
||||
import Registry, Record from "@fluencelabs/registry/registry-service.aqua"
|
||||
import "@fluencelabs/spell/spell_service.aqua"
|
||||
|
||||
export get_and_save, put, put_all, get, worker_n
|
||||
import "workers.aqua"
|
||||
import "services.aqua"
|
||||
|
||||
export put, get
|
||||
export put_workers, get_workers, get_and_save_workers
|
||||
|
||||
func getWorkers() -> []Record:
|
||||
workersInfo <- getWorkersInfo()
|
||||
dealId = workersInfo.deals.defaultWorker.dealId
|
||||
on HOST_PEER_ID:
|
||||
workersOp <- resolveSubnetwork(dealId)
|
||||
workersOp <- resolveSubnetwork(dealId)
|
||||
<- workersOp!
|
||||
|
||||
func worker_n() -> u32:
|
||||
workers <- getWorkers()
|
||||
<- workers.length
|
||||
|
||||
func get_and_save(url: string, fname: string) -> string:
|
||||
workers <- getWorkers()
|
||||
w = workers[8]
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
res = UrlDownloader.get_n_save(url, fname)
|
||||
<- res
|
||||
|
||||
func put_all(file_name: string, file_content: []u8) -> []string:
|
||||
res: *string
|
||||
workers <- getWorkers()
|
||||
for w <- workers:
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
try:
|
||||
res <- UrlDownloader.put(file_name, file_content)
|
||||
catch e:
|
||||
res <<- "failed to execute"
|
||||
<- res
|
||||
|
||||
func put(file_name: string, file_content: []u8) -> string:
|
||||
workers <- getWorkers()
|
||||
w = workers[1]
|
||||
w = workers[0]
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
res <- UrlDownloader.put(file_name, file_content)
|
||||
<- res
|
||||
|
||||
|
||||
func get(file_name: string) -> []u8:
|
||||
workers <- getWorkers()
|
||||
w = workers[5]
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
w = workers[0]
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
res <- UrlDownloader.get(file_name)
|
||||
<- res
|
||||
|
||||
func get_and_save(url: string, fname: string) -> string:
|
||||
workers <- getWorkers()
|
||||
w = workers[0]
|
||||
on w.metadata.peer_id via w.metadata.relay_id:
|
||||
res = UrlDownloader.get_n_save(url, fname)
|
||||
<- res
|
||||
|
||||
func put_workers(file_name: string, file_content: []u8) -> string:
|
||||
info <- getWorkersInfo()
|
||||
spell = info.hosts.defaultWorker.installationSpells[0]
|
||||
on spell.workerId via spell.hostId:
|
||||
res <- UrlDownloader.put(file_name, file_content)
|
||||
<- res
|
||||
|
||||
func get_workers(file_name: string) -> []u8:
|
||||
info <- getWorkersInfo()
|
||||
spell = info.hosts.defaultWorker.installationSpells[0]
|
||||
on spell.workerId via spell.hostId:
|
||||
res <- UrlDownloader.get(file_name)
|
||||
<- res
|
||||
|
||||
func get_and_save_workers(url: string, fname: string) -> string:
|
||||
info <- getWorkersInfo()
|
||||
spell = info.hosts.defaultWorker.installationSpells[0]
|
||||
on spell.workerId via spell.hostId:
|
||||
res = UrlDownloader.get_n_save(url, fname)
|
||||
<- res
|
Loading…
Reference in New Issue
Block a user