mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
deploy url-downloader via workers
This commit is contained in:
parent
f8acb27502
commit
020e0c7319
@ -1,18 +1,20 @@
|
|||||||
data GetWorkersInfoDealsDefaultWorker:
|
data GetWorkersInfoHostsDefaultWorkerInstallationSpells:
|
||||||
installationSpells: ?u8
|
hostId: string
|
||||||
definition: string
|
spellId: string
|
||||||
timestamp: string
|
workerId: string
|
||||||
dealIdOriginal: string
|
|
||||||
dealId: string
|
|
||||||
chainNetwork: string
|
|
||||||
chainNetworkId: f64
|
|
||||||
|
|
||||||
data GetWorkersInfoDeals:
|
data GetWorkersInfoHostsDefaultWorker:
|
||||||
defaultWorker: GetWorkersInfoDealsDefaultWorker
|
definition: string
|
||||||
|
installationSpells: []GetWorkersInfoHostsDefaultWorkerInstallationSpells
|
||||||
|
timestamp: string
|
||||||
|
relayId: string
|
||||||
|
|
||||||
|
data GetWorkersInfoHosts:
|
||||||
|
defaultWorker: GetWorkersInfoHostsDefaultWorker
|
||||||
|
|
||||||
data GetWorkersInfo:
|
data GetWorkersInfo:
|
||||||
deals: GetWorkersInfoDeals
|
deals: ?u8
|
||||||
hosts: ?u8
|
hosts: GetWorkersInfoHosts
|
||||||
|
|
||||||
func getWorkersInfo() -> GetWorkersInfo:
|
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=nil,hosts=GetWorkersInfoHosts(defaultWorker=GetWorkersInfoHostsDefaultWorker(definition="bafkreic2hb3mqpqoapy6cb3ozzyvknds3jk5rvov5bty6zgdtegwg7j37i",installationSpells=[GetWorkersInfoHostsDefaultWorkerInstallationSpells(hostId="12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r",spellId="05759fa5-5c23-4d1e-9a8f-512e866b363e",workerId="12D3KooWC99oo2UvyJU8b5oKQsRxBCSs9tbgeCvH9zP4Pt35Twtr")],timestamp="2023-04-12T17:15:00.700Z",relayId="12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r")))
|
||||||
|
@ -48,16 +48,7 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"required": [],
|
"required": [],
|
||||||
"title": "Volumes",
|
"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)"
|
"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"
|
||||||
},
|
|
||||||
"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
|
|
||||||
},
|
},
|
||||||
"envs": {
|
"envs": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@ -153,16 +144,7 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"required": [],
|
"required": [],
|
||||||
"title": "Volumes",
|
"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)"
|
"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"
|
||||||
},
|
|
||||||
"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
|
|
||||||
},
|
},
|
||||||
"envs": {
|
"envs": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -38,16 +38,7 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"required": [],
|
"required": [],
|
||||||
"title": "Volumes",
|
"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)"
|
"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"
|
||||||
},
|
|
||||||
"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
|
|
||||||
},
|
},
|
||||||
"envs": {
|
"envs": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -40,16 +40,7 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"required": [],
|
"required": [],
|
||||||
"title": "Volumes",
|
"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)"
|
"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"
|
||||||
},
|
|
||||||
"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
|
|
||||||
},
|
},
|
||||||
"envs": {
|
"envs": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@ -99,16 +90,7 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"required": [],
|
"required": [],
|
||||||
"title": "Volumes",
|
"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)"
|
"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"
|
||||||
},
|
|
||||||
"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
|
|
||||||
},
|
},
|
||||||
"envs": {
|
"envs": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -14,29 +14,6 @@
|
|||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"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": {
|
"definition": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -62,7 +39,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"installation_spells",
|
|
||||||
"timestamp",
|
"timestamp",
|
||||||
"definition",
|
"definition",
|
||||||
"dealId",
|
"dealId",
|
||||||
@ -80,6 +56,13 @@
|
|||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"definition": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "ISO timestamp of the time when the worker was deployed"
|
||||||
|
},
|
||||||
"installation_spells": {
|
"installation_spells": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"description": "A list of installation spells",
|
"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": {
|
"relayId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"installation_spells",
|
|
||||||
"timestamp",
|
"timestamp",
|
||||||
"definition",
|
"definition",
|
||||||
|
"installation_spells",
|
||||||
"relayId"
|
"relayId"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
[[module]]
|
|
||||||
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]]
|
|
||||||
name = "curl_adapter"
|
|
||||||
load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/curl_adapter.wasm"
|
|
||||||
logger_enabled = true
|
|
||||||
|
|
||||||
[module.mounted_binaries]
|
|
||||||
curl = "/usr/bin/curl"
|
|
||||||
|
|
||||||
[[module]]
|
|
||||||
name = "url_downloader"
|
|
||||||
load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/url_downloader.wasm"
|
|
||||||
logger_enabled = true
|
|
@ -5,12 +5,12 @@
|
|||||||
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md
|
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md
|
||||||
|
|
||||||
version: 0
|
version: 0
|
||||||
deals:
|
hosts:
|
||||||
defaultWorker:
|
defaultWorker:
|
||||||
installation_spells: []
|
definition: bafkreic2hb3mqpqoapy6cb3ozzyvknds3jk5rvov5bty6zgdtegwg7j37i
|
||||||
definition: bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy
|
installation_spells:
|
||||||
timestamp: 2023-04-04T00:29:31.854Z
|
- host_id: 12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r
|
||||||
dealIdOriginal: "0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E"
|
spell_id: 05759fa5-5c23-4d1e-9a8f-512e866b363e
|
||||||
dealId: d0c75aeea62bc0abf16f5f01361277cc8287ab0e
|
worker_id: 12D3KooWC99oo2UvyJU8b5oKQsRxBCSs9tbgeCvH9zP4Pt35Twtr
|
||||||
chainNetwork: testnet
|
timestamp: 2023-04-12T17:15:00.700Z
|
||||||
chainNetworkId: 80001
|
relayId: 12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r
|
||||||
|
@ -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
|
|
@ -10,3 +10,5 @@ npm:
|
|||||||
"@fluencelabs/aqua-lib": 0.6.0
|
"@fluencelabs/aqua-lib": 0.6.0
|
||||||
"@fluencelabs/spell": 0.5.7
|
"@fluencelabs/spell": 0.5.7
|
||||||
"@fluencelabs/registry": 0.8.2
|
"@fluencelabs/registry": 0.8.2
|
||||||
|
cargo:
|
||||||
|
marine: 0.14.1
|
||||||
|
@ -6,15 +6,6 @@
|
|||||||
|
|
||||||
version: 2
|
version: 2
|
||||||
aquaInputPath: src/aqua/main.aqua
|
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
|
|
||||||
workers:
|
workers:
|
||||||
defaultWorker:
|
defaultWorker:
|
||||||
services: [ url_downloader ]
|
services: [ url_downloader ]
|
||||||
@ -25,8 +16,9 @@ deals:
|
|||||||
hosts:
|
hosts:
|
||||||
defaultWorker:
|
defaultWorker:
|
||||||
peerIds:
|
peerIds:
|
||||||
- 12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr
|
- 12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r
|
||||||
relays: kras
|
relays:
|
||||||
|
- /dns4/stage.fluence.dev/tcp/19990/wss/p2p/12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r
|
||||||
services:
|
services:
|
||||||
url_downloader:
|
url_downloader:
|
||||||
get: service
|
get: service
|
||||||
|
@ -7,7 +7,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
module_manifest!();
|
module_manifest!();
|
||||||
|
|
||||||
const SITES_DIR: &str = "/sites/";
|
const SITES_DIR: &str = "sites/";
|
||||||
|
|
||||||
/// Log level can be changed by `RUST_LOG` env as well.
|
/// Log level can be changed by `RUST_LOG` env as well.
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
@ -20,9 +20,9 @@ pub fn put(name: String, file_content: Vec<u8>) -> String {
|
|||||||
log::info!("put called with file name {}\n", name);
|
log::info!("put called with file name {}\n", name);
|
||||||
let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name);
|
let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name);
|
||||||
|
|
||||||
let result = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content);
|
let result = fs::write(PathBuf::from(rpc_tmp_filepath), file_content);
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
return format!("file can't be written: {}", e);
|
return format!("WTF WTF WTF: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::from("Ok")
|
String::from("Ok")
|
||||||
|
@ -9,11 +9,12 @@ export get_and_save, put, put_all, get, worker_n
|
|||||||
|
|
||||||
|
|
||||||
func getWorkers() -> []Record:
|
func getWorkers() -> []Record:
|
||||||
workersInfo <- getWorkersInfo()
|
-- workersInfo <- getWorkersInfo()
|
||||||
dealId = workersInfo.deals.defaultWorker.dealId
|
-- dealId = workersInfo.deals.defaultWorker.dealId
|
||||||
on HOST_PEER_ID:
|
-- on HOST_PEER_ID:
|
||||||
workersOp <- resolveSubnetwork(dealId)
|
-- workersOp <- resolveSubnetwork(dealId)
|
||||||
<- workersOp!
|
-- <- workersOp!
|
||||||
|
<- []
|
||||||
|
|
||||||
func worker_n() -> u32:
|
func worker_n() -> u32:
|
||||||
workers <- getWorkers()
|
workers <- getWorkers()
|
||||||
@ -44,6 +45,14 @@ func put(file_name: string, file_content: []u8) -> string:
|
|||||||
res <- UrlDownloader.put(file_name, file_content)
|
res <- UrlDownloader.put(file_name, file_content)
|
||||||
<- res
|
<- res
|
||||||
|
|
||||||
|
func put_workers(file_name: string, file_content: []u8) -> string, []u8:
|
||||||
|
info <- getWorkersInfo()
|
||||||
|
spell = info.hosts.defaultWorker.installationSpells[0]
|
||||||
|
on spell.workerId via spell.hostId:
|
||||||
|
res <- UrlDownloader.put(file_name, file_content)
|
||||||
|
get <- UrlDownloader.get(file_name)
|
||||||
|
<- res, get
|
||||||
|
|
||||||
func get(file_name: string) -> []u8:
|
func get(file_name: string) -> []u8:
|
||||||
workers <- getWorkers()
|
workers <- getWorkers()
|
||||||
w = workers[5]
|
w = workers[5]
|
||||||
|
Loading…
Reference in New Issue
Block a user