From 14666d4e5d81ab6b4069e8262ccf5001f91e32f1 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Mon, 13 Feb 2023 10:07:25 +0100 Subject: [PATCH 1/7] feat: serve the repository as static files --- docs/docusaurus.config.js | 2 ++ metadata/repository/v1/index.toml | 1 + 2 files changed, 3 insertions(+) create mode 100644 metadata/repository/v1/index.toml diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 38bcb346..c1787e90 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -20,6 +20,8 @@ const config = { defaultLocale: 'en', locales: ['en'], }, + // Get the index metadata for `wws` language runtimes + staticDirectories: ["static", "../metadata"], presets: [ [ diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml new file mode 100644 index 00000000..d5671c21 --- /dev/null +++ b/metadata/repository/v1/index.toml @@ -0,0 +1 @@ +version = "1" \ No newline at end of file From 4dbcf06d1d9a65035c9509f942e05cd8439be6de Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Mon, 13 Feb 2023 11:42:53 +0100 Subject: [PATCH 2/7] feat: create the initial repository index --- metadata/repository/v1/files/python/3/poly.py | 25 +++++++ .../repository/v1/files/python/3/wrapper.txt | 6 ++ metadata/repository/v1/files/ruby/3/poly.rb | 66 +++++++++++++++++++ .../repository/v1/files/ruby/3/wrapper.txt | 5 ++ metadata/repository/v1/index.toml | 24 ++++++- src/commands/runtimes.rs | 4 +- 6 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 metadata/repository/v1/files/python/3/poly.py create mode 100644 metadata/repository/v1/files/python/3/wrapper.txt create mode 100644 metadata/repository/v1/files/ruby/3/poly.rb create mode 100644 metadata/repository/v1/files/ruby/3/wrapper.txt diff --git a/metadata/repository/v1/files/python/3/poly.py b/metadata/repository/v1/files/python/3/poly.py new file mode 100644 index 00000000..4475622c --- /dev/null +++ b/metadata/repository/v1/files/python/3/poly.py @@ -0,0 +1,25 @@ +import sys, json; + +class Request: + def __init__(self, input): + self.method = input["method"] + self.url = input["url"] + self.body = input["body"] + self.headers = input["headers"] + self.params = input["params"] + +class Response: + def __init__(self, body): + self.body = body + self.status_code = 200 + self.headers = {} + self.kv = {} + + def to_json(self): + res = { + 'data': self.body, + 'status': self.status_code, + 'headers': self.headers, + 'kv': self.kv + } + return json.dumps(res) diff --git a/metadata/repository/v1/files/python/3/wrapper.txt b/metadata/repository/v1/files/python/3/wrapper.txt new file mode 100644 index 00000000..d7fd2126 --- /dev/null +++ b/metadata/repository/v1/files/python/3/wrapper.txt @@ -0,0 +1,6 @@ +from poly import * + +{source} + +res = worker(Request(json.loads(sys.stdin.read()))) +print(res.to_json()) diff --git a/metadata/repository/v1/files/ruby/3/poly.rb b/metadata/repository/v1/files/ruby/3/poly.rb new file mode 100644 index 00000000..0501a42b --- /dev/null +++ b/metadata/repository/v1/files/ruby/3/poly.rb @@ -0,0 +1,66 @@ +require 'json'; + +def json_to_request(input) + json = JSON.parse(input); + + Request.new( + json['url'], + json['body'], + json['method'], + json['headers'], + json['params'] + ) +end + +class Request + attr_reader :url, :body, :method, :headers, :params + + def initialize(url, body, method, headers, params) + @url = url + @body = body + @method = method + @headers = headers + @params = params + end +end + +class Response + attr_accessor :body, :status_code, :headers + + def initialize(body, status_code = 200, headers = {}) + @body = body + @status_code = status_code + @headers = headers + end + + def self.ok(body) + new(body) + end + + def self.created(body) + new(body, 201) + end + + def self.not_found(body) + new(body, 404) + end + + def print_headers + serialized = "{" + + headers.each do |k, v| + serialized = "#{serialized} \"#{k}\": \"#{v}\"" + end + + "#{serialized} }" + end + + def to_s + JSON.generate({ + data: body, + status: status_code, + headers: headers, + kv: {} + }) + end +end diff --git a/metadata/repository/v1/files/ruby/3/wrapper.txt b/metadata/repository/v1/files/ruby/3/wrapper.txt new file mode 100644 index 00000000..15f2fbff --- /dev/null +++ b/metadata/repository/v1/files/ruby/3/wrapper.txt @@ -0,0 +1,5 @@ +require_relative "./poly"; + +{source} + +puts "#{worker(json_to_request($stdin.gets.to_s))}" diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index d5671c21..4292d594 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -1 +1,23 @@ -version = "1" \ No newline at end of file +version = 1 + +[[runtimes]] +name = "ruby" +version = "3.2.0+TBD" +tags = [ "latest", "3.2.0" ] +status = "active" +args = [ "--", "/src/index.rb" ] +binary = { url = "TBD", filename = "ruby.wasm", checksum = { type = "sha256", value = "TBD" } } +extensions = [ "rb" ] +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "2ba09117ed20a05480615b2aaaf6c7cd7f61fa06f4919777d773df2fcbc736cf" } } +wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } + +[[runtimes]] +name = "python" +version = "3.11.1+TBD" +tags = [ "latest", "3.11.1" ] +status = "active" +args = [ "--", "/src/index.py" ] +binary = { url = "TBD", filename = "python.wasm", checksum = { type = "sha256", value = "TBD" } } +extensions = [ "py" ] +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "ce179a41a02ef4e71f4f6e0c84d06509393b104b3bc3238b4d30fac8d1b6884d" } } +wrapper = { url = "https://workers.wasmlabs.dev/repository/files/python/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "cf1edc5b1427180ec09d18f4d169580379f1b12001f30e330759f9a0f8745357" } } \ No newline at end of file diff --git a/src/commands/runtimes.rs b/src/commands/runtimes.rs index 73581885..bce67615 100644 --- a/src/commands/runtimes.rs +++ b/src/commands/runtimes.rs @@ -16,9 +16,9 @@ use prettytable::{format, Cell, Row, Table}; use std::env; /// Default repository name -pub const DEFAULT_REPO_NAME: &str = "wlr"; +pub const DEFAULT_REPO_NAME: &str = "wasmlabs"; /// Default repository URL -pub const DEFAULT_REPO_URL: &str = "https://assets.wasmlabs.dev/repository/v1/index.toml"; +pub const DEFAULT_REPO_URL: &str = "https://workers.wasmlabs.dev/repository/v1/index.toml"; /// Environment variable to set the repository name pub const WWS_REPO_NAME: &str = "WWS_REPO_NAME"; From 992ae9781b731bb6b6f2df287a26f6de5e3e1417 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Mon, 13 Feb 2023 11:51:19 +0100 Subject: [PATCH 3/7] fix: remove unused ruby method --- metadata/repository/v1/files/ruby/3/poly.rb | 10 ---------- metadata/repository/v1/index.toml | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/metadata/repository/v1/files/ruby/3/poly.rb b/metadata/repository/v1/files/ruby/3/poly.rb index 0501a42b..737aeb4b 100644 --- a/metadata/repository/v1/files/ruby/3/poly.rb +++ b/metadata/repository/v1/files/ruby/3/poly.rb @@ -45,16 +45,6 @@ def self.not_found(body) new(body, 404) end - def print_headers - serialized = "{" - - headers.each do |k, v| - serialized = "#{serialized} \"#{k}\": \"#{v}\"" - end - - "#{serialized} }" - end - def to_s JSON.generate({ data: body, diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index 4292d594..35ca1c56 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -8,7 +8,7 @@ status = "active" args = [ "--", "/src/index.rb" ] binary = { url = "TBD", filename = "ruby.wasm", checksum = { type = "sha256", value = "TBD" } } extensions = [ "rb" ] -polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "2ba09117ed20a05480615b2aaaf6c7cd7f61fa06f4919777d773df2fcbc736cf" } } +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "3987988ae3f4cbdbd3a9f3d68350a2f233316c2ad240843240c231b333943521" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } [[runtimes]] From 9058e5295e2ff81c9a95d1e0bafde82614e6b786 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Wed, 15 Feb 2023 16:19:20 +0100 Subject: [PATCH 4/7] feat: add support for the KV store --- metadata/repository/v1/files/python/3/poly.py | 25 ++++++++++++++-- metadata/repository/v1/files/ruby/3/poly.rb | 30 +++++++++++++++++-- metadata/repository/v1/index.toml | 4 +-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/metadata/repository/v1/files/python/3/poly.py b/metadata/repository/v1/files/python/3/poly.py index 4475622c..7b90b41c 100644 --- a/metadata/repository/v1/files/python/3/poly.py +++ b/metadata/repository/v1/files/python/3/poly.py @@ -1,5 +1,24 @@ import sys, json; +class Cache: + store = {} + + @classmethod + def init(cls, kv): + cls.store = kv + + @classmethod + def dump(cls): + return cls.store + + @classmethod + def get(cls, key): + return cls.store.get(key) + + @classmethod + def set(cls, key, value): + cls.store[key] = str(value) + class Request: def __init__(self, input): self.method = input["method"] @@ -8,18 +27,20 @@ def __init__(self, input): self.headers = input["headers"] self.params = input["params"] + # Init the cache + Cache.init(input["kv"]) + class Response: def __init__(self, body): self.body = body self.status_code = 200 self.headers = {} - self.kv = {} def to_json(self): res = { 'data': self.body, 'status': self.status_code, 'headers': self.headers, - 'kv': self.kv + 'kv': Cache.dump() } return json.dumps(res) diff --git a/metadata/repository/v1/files/ruby/3/poly.rb b/metadata/repository/v1/files/ruby/3/poly.rb index 737aeb4b..dd1879e1 100644 --- a/metadata/repository/v1/files/ruby/3/poly.rb +++ b/metadata/repository/v1/files/ruby/3/poly.rb @@ -8,19 +8,43 @@ def json_to_request(input) json['body'], json['method'], json['headers'], - json['params'] + json['params'], + json['kv'] ) end +class Cache + @@kv = {} + + def self.init(kv) + @@kv = kv + end + + def self.dump + @@kv + end + + def self.get(key) + @@kv[key.to_s] + end + + def self.set(key, value) + @@kv[key.to_s] = value.to_s + end +end + class Request attr_reader :url, :body, :method, :headers, :params - def initialize(url, body, method, headers, params) + def initialize(url, body, method, headers, params, kv) @url = url @body = body @method = method @headers = headers @params = params + + # Initializes the cache + Cache.init(kv) end end @@ -50,7 +74,7 @@ def to_s data: body, status: status_code, headers: headers, - kv: {} + kv: Cache.dump }) end end diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index 35ca1c56..255d65aa 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -8,7 +8,7 @@ status = "active" args = [ "--", "/src/index.rb" ] binary = { url = "TBD", filename = "ruby.wasm", checksum = { type = "sha256", value = "TBD" } } extensions = [ "rb" ] -polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "3987988ae3f4cbdbd3a9f3d68350a2f233316c2ad240843240c231b333943521" } } +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "044b0d4bde7d3a9b0f275821fb5b67cc2e382267904df2516a23dbec1fae6bae" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } [[runtimes]] @@ -19,5 +19,5 @@ status = "active" args = [ "--", "/src/index.py" ] binary = { url = "TBD", filename = "python.wasm", checksum = { type = "sha256", value = "TBD" } } extensions = [ "py" ] -polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "ce179a41a02ef4e71f4f6e0c84d06509393b104b3bc3238b4d30fac8d1b6884d" } } +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "2027b73556ca02155f026cee751ab736985917d2f28bbcad5aac928c719e1112" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/python/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "cf1edc5b1427180ec09d18f4d169580379f1b12001f30e330759f9a0f8745357" } } \ No newline at end of file From 180de48adb424368306b76281bb2fb1b86119cec Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 16 Feb 2023 08:40:21 +0100 Subject: [PATCH 5/7] feat: add the ruby 3.2.0 binary URL --- metadata/repository/v1/index.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index 255d65aa..eb58ae49 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -2,11 +2,11 @@ version = 1 [[runtimes]] name = "ruby" -version = "3.2.0+TBD" +version = "3.2.0+20230215" tags = [ "latest", "3.2.0" ] status = "active" args = [ "--", "/src/index.rb" ] -binary = { url = "TBD", filename = "ruby.wasm", checksum = { type = "sha256", value = "TBD" } } +binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm", filename = "ruby.wasm", checksum = { type = "sha256", value = "1ea101553585a9ec4734ed3774648107ccd7beb6971f9ce687a084d06b8409f9" } } extensions = [ "rb" ] polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "044b0d4bde7d3a9b0f275821fb5b67cc2e382267904df2516a23dbec1fae6bae" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } From dcd9f4e4fc662d4ca9dc57224d853645624f84e7 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 16 Feb 2023 08:43:07 +0100 Subject: [PATCH 6/7] fix: set the right shasum for the ruby binary --- metadata/repository/v1/index.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index eb58ae49..d0943d61 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -6,7 +6,7 @@ version = "3.2.0+20230215" tags = [ "latest", "3.2.0" ] status = "active" args = [ "--", "/src/index.rb" ] -binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm", filename = "ruby.wasm", checksum = { type = "sha256", value = "1ea101553585a9ec4734ed3774648107ccd7beb6971f9ce687a084d06b8409f9" } } +binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm", filename = "ruby.wasm", checksum = { type = "sha256", value = "abe348fba157a756f86194be445c77c99e8ed64ca76495ea07ed984f09eb66ae" } } extensions = [ "rb" ] polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "044b0d4bde7d3a9b0f275821fb5b67cc2e382267904df2516a23dbec1fae6bae" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } From 0f86bd1a73c9eda991b889bb8a0e63a46cfd12f9 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Fri, 17 Feb 2023 17:03:18 +0100 Subject: [PATCH 7/7] feat: add python binary --- metadata/repository/v1/index.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml index d0943d61..c178605b 100644 --- a/metadata/repository/v1/index.toml +++ b/metadata/repository/v1/index.toml @@ -3,7 +3,7 @@ version = 1 [[runtimes]] name = "ruby" version = "3.2.0+20230215" -tags = [ "latest", "3.2.0" ] +tags = [ "latest", "3.2", "3.2.0" ] status = "active" args = [ "--", "/src/index.rb" ] binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm", filename = "ruby.wasm", checksum = { type = "sha256", value = "abe348fba157a756f86194be445c77c99e8ed64ca76495ea07ed984f09eb66ae" } } @@ -13,11 +13,11 @@ wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper. [[runtimes]] name = "python" -version = "3.11.1+TBD" -tags = [ "latest", "3.11.1" ] +version = "3.11.1+20230217" +tags = [ "latest", "3.11", "3.11.1" ] status = "active" args = [ "--", "/src/index.py" ] -binary = { url = "TBD", filename = "python.wasm", checksum = { type = "sha256", value = "TBD" } } +binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/python%2F3.11.1%2B20230217-15dfbed/python-3.11.1.wasm", filename = "python.wasm", checksum = { type = "sha256", value = "66589b289f76bd716120f76f234e4dd663064ed5b6256c92d441d84e51d7585d" } } extensions = [ "py" ] polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "2027b73556ca02155f026cee751ab736985917d2f28bbcad5aac928c719e1112" } } wrapper = { url = "https://workers.wasmlabs.dev/repository/files/python/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "cf1edc5b1427180ec09d18f4d169580379f1b12001f30e330759f9a0f8745357" } } \ No newline at end of file