Meet Sat [Part 2]: Take care of your Runnables with the GitLab Package Registry
This blog post is the second part of a set of posts on the Sat project. You need to read the first part before: Meet Sat, the tiny wasm function server.
I was looking for a way to store the wasm files of my Runnables properly when I read this sentence in the Sat's documentation:
"If you provide a URL as the path argument to Sat, it will download the module from that URL, write it to a temp directory, and use it for execution:
.bin/sat "https://github.com/suborbital/reactr/blob/main/rwasm/testdata/hello-echo/hello-echo.wasm?raw=true"
" (ref: https://github.com/suborbital/sat#run-from-url)
"With the GitLab Package Registry, you can use GitLab as a private or public registry for a variety of supported package managers. You can publish and share packages, which can be consumed as a dependency in downstream projects."
Create a Runnable
So, we'll create (and build) a new Runnable project with the subo cli (for more details, have a look at the previous post):
# create the Runnable project
subo create runnable hello
# build the hello.wasm file
subo build ./hello
hello.wasm
to the GitLab Package Registry
Publish Every project on GitLab.com (and on the self-hosted version) can host a package registry, and you can push files, packages,... on it. To push the wasm Runnable file to the registry, we need:
- The id of the GitLab project that hosts the registry
- The path to the Runnable (
/hello
, it's the directory of the Runnable project) - The file name (
hello.wasm
) - A version number (
0.0.0
or what you want, it's a tag) - A package name (
hello-sat
) - A GitLab Personal Access Token with the appropriate scope (
write_registry
&read_registry
), (see: https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html)
With all this information, you will be able to run the following command:
# Change the GitLab project ID
project_id="33178966"
wasmpath="hello" # Runnable project path
wasmfile="hello.wasm"
version="0.0.0"
package_name="hello-sat"
curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_ADMIN}" \
--upload-file ${wasmpath}/${wasmfile} \
"https://gitlab.com/api/v4/projects/${project_id}/packages/generic/${package_name}/${version}/${wasmfile}"
You should get this response: {"message":"201 Created"}
, and if you select the package registry menu of the project, you'll be able to check that your package was published:
And, now we can run the wasm Runnable from the package registry.
Serve the Runnable
Now, we can serve the Runnable from everywhere (tomorrow, I will explain how I'm doing this with a Raspberry Pi4) like this:
#!/bin/bash
# Change the GitLab project ID
project_id="33178966"
wasmfile="hello.wasm"
version="0.0.0"
package_name="hello-sat"
SAT_HTTP_PORT=8080 sat https://gitlab.com/api/v4/projects/${project_id}/packages/generic/${package_name}/${version}/${wasmfile}
Then you can call the function:
curl localhost:8080 -d 'Bob Morane'
# response: Hello Bob Morane
🥰 Easy
I prepared a "ready to use" project. If you open it with Gitpod, all the needed tools will be installed at startup (so be patient, but it's not so long): 02-take-care-of-the-runnables
Enjoy playing with Sat
👋
- If you loved this "post" (or not), don't forget to use the emojis reactions
- Don't hesitate to add comments and/or ask questions
- You can subscribe to the Rss feed