Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the initial repository index #88

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const config = {
defaultLocale: 'en',
locales: ['en'],
},
// Get the index metadata for `wws` language runtimes
staticDirectories: ["static", "../metadata"],

presets: [
[
Expand Down
46 changes: 46 additions & 0 deletions metadata/repository/v1/files/python/3/poly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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"]
self.url = input["url"]
self.body = input["body"]
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 = {}

def to_json(self):
res = {
'data': self.body,
'status': self.status_code,
'headers': self.headers,
'kv': Cache.dump()
}
return json.dumps(res)
6 changes: 6 additions & 0 deletions metadata/repository/v1/files/python/3/wrapper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from poly import *

{source}

res = worker(Request(json.loads(sys.stdin.read())))
print(res.to_json())
80 changes: 80 additions & 0 deletions metadata/repository/v1/files/ruby/3/poly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'json';

def json_to_request(input)
json = JSON.parse(input);

Request.new(
json['url'],
json['body'],
json['method'],
json['headers'],
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, kv)
@url = url
@body = body
@method = method
@headers = headers
@params = params

# Initializes the cache
Cache.init(kv)
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 to_s
JSON.generate({
data: body,
status: status_code,
headers: headers,
kv: Cache.dump
})
end
end
5 changes: 5 additions & 0 deletions metadata/repository/v1/files/ruby/3/wrapper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "./poly";

{source}

puts "#{worker(json_to_request($stdin.gets.to_s))}"
23 changes: 23 additions & 0 deletions metadata/repository/v1/index.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 1

[[runtimes]]
name = "ruby"
version = "3.2.0+20230215"
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" } }
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" } }

[[runtimes]]
name = "python"
version = "3.11.1+20230217"
tags = [ "latest", "3.11", "3.11.1" ]
status = "active"
args = [ "--", "/src/index.py" ]
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" } }
4 changes: 2 additions & 2 deletions src/commands/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down