You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: component-model/src/creating-and-consuming/distributing.md
+66-42
Original file line number
Diff line number
Diff line change
@@ -6,86 +6,110 @@ Publishing and distribution are not defined by the core component model, but for
6
6
7
7
You can get involved with improving the packaging and hosting of Wasm components by joining the [Bytecode Alliance Packaging Special Interest Group (SIG)](https://github.com/bytecodealliance/governance/blob/main/SIGs/sig-packaging/proposal.md).
8
8
9
-
## Registry Tooling
9
+
## The `wkg`Registry Tool
10
10
11
-
The [`wasm-pkg-tools` project](https://github.com/bytecodealliance/wasm-pkg-tools) enables fetching and publishing Wasm Components to OCI or Warg registries. It contains a `wkg` CLI tool that eases distributing and fetching components and WIT packages. The following examples walk through using `wkg`.
11
+
The [`wasm-pkg-tools` project](https://github.com/bytecodealliance/wasm-pkg-tools) enables fetching and publishing Wasm components to OCI registries. It contains a `wkg` CLI tool that eases distributing and fetching components and WIT packages. `wkg` contains several subcommand:
12
12
13
-
## Distributing Components Using `wkg`
13
+
-`wkg oci` - is a CLI wrapper around the [oci-wasm](https://github.com/bytecodealliance/rust-oci-wasm) crate which enables pushing/pulling Wasm artifacts to/from any OCI registry
14
+
-`wkg publish` - pushes *library* components or WIT packages
15
+
-`wkg get` - pulls *library* components or WIT packages
16
+
-`wkg wit` - commands for interacting with WIT files and dependencies
17
+
-`wkg config` - interact with the `wkg` configuration
14
18
15
-
A component is pushed to an OCI registry using `wkg oci push`. The example below pushes to a GHCR:
19
+
The following sections detail a subset of actions that can be performed with `wkg`.
16
20
17
-
```sh
18
-
wkg oci push ghcr.io/user/hello:0.1.0 hello.wasm
19
-
```
21
+
## `wkg` Configuration Files
20
22
21
-
## Fetching Components Using `wkg`
23
+
The `wkg` tool uses a configuration file to understand where to publish and fetch specific packages to and from. It provides the ability to configure:
22
24
23
-
A component is pulled from a OCI registry using `wkg oci pull`. The example below pulls a component from GHCR:
- a default registry for all packages at the top level of the file
26
+
- a default registry for all packages of a specific namespace under `[namespace_registries]`. This section can be used to configure the registry of all `wasi` namespaced packages, such as `wasi:clocks` and `wasi:http`.
27
+
- an override for package of a specific namespace under `[package_registry_overrides]`. This section can be used to fetch/publish a specific package of a namespace from/to a different location than all other packages of that namespace. For example, maybe you want to fetch `wasi:http` from a different registry.
28
+
- credentials for a registry under `[registry."<registry-name>".oci]`
29
+
- and more! See the [`wkg` docs for more configuration options](https://github.com/bytecodealliance/wasm-pkg-tools?tab=readme-ov-file#configuration).
28
30
29
-
## Configuring `wkg` to Fetch WASI Packages
31
+
For example, to fetch WASI packages, such as `wasi:clocks` and `wasi:http`, a line can be added under the `namespace_registries` section for the `wasi` namespace. Specifically, the example below configures `wkg` to fetch WASI packages from the [WebAssembly OCI GitHub Container Registry](https://github.com/orgs/WebAssembly/packages), where the latest interfaces are published upon WASI releases. To edit your `wkg` config file, simply run `wkg config --edit`.
30
32
31
-
The `wkg` tool uses a configuration file to store settings with a default location of `$XDG_CONFIG_HOME/wasm-pkg/config.toml`. It must be configured to know which registry to use for which package namespaces. The following is a convenient configuration to ensure you can fetch WASI packages from the [WebAssembly OCI registry](https://github.com/WebAssembly/WASI/pkgs/container/wasi), where the latest interfaces are published upon WASI releases.
33
+
> Remember, all package names consist of the a namespace field followed by the package field. The package name `wasi:clocks` has a namespace of `wasi` and package field of `clocks`. In this way, the following configuration ensures that `wkg` will know to route fetches and publishes of any `wasi:x` to the configured location.
32
34
33
35
```toml
34
36
# $XDG_CONFIG_HOME/wasm-pkg/config.toml
35
37
default_registry = "ghcr.io"
36
38
37
39
[namespace_registries]
40
+
# Instruct wkg to use the OCI protocol to fetch packages with the `wasi` namespace from ghcr.io/webassembly
The `wkg` tool uses a [configuration file](https://github.com/bytecodealliance/wasm-pkg-tools?tab=readme-ov-file#configuration) to store settings with a default location of `$XDG_CONFIG_HOME/wasm-pkg/config.toml`. It must be configured to know which registry to use for which package namespaces. The following configuration, instructs `wkg` to use [ttl.sh](https://ttl.sh/) OCI registry for all packages with the `foo` namespace.
44
+
As a more generic example, The following configuration, instructs `wkg` to use [ttl.sh](https://ttl.sh/) OCI registry for all packages with the `docs` namespace.
## Distributing WIT and Library Components using `wkg publish`
57
56
58
-
[registry]
59
-
```
57
+
Once you've [configured `wkg`](#wkg-configuration-files) to know where to publish packages to, you can use the `wkg publish` command to publish library *components* or *interfaces* to be consumed by others.
60
58
61
-
Now, `foo` packages can be built and published using `wkg`.
59
+
Imagine you have defined the following `adder` world in WIT:
You can publish this *WIT* using `wkg` by wrapping it up as a Wasm component. Yes, you heard that right! We are packaging WIT as Wasm.
74
+
75
+
```sh
76
76
77
77
wkg wit build
78
-
wkg publish foo:bar@0.1.0.wasm
78
+
wkg publish docs:adder@0.1.0.wasm
79
79
```
80
80
81
-
This will publish the component to `ttl.sh/wasm-components/foo/bar:0.1.0`
81
+
If you had configured `wkg` as described in the [`wkg` configuration section](#wkg-configuration-files), this would publish the component to `ttl.sh/wasm-components/docs/adder:0.1.0`. This WIT can then be fetched using `wkg get`, specifying the format `wit`:
The `wkg oci` subcommand is a CLI wrapper around the [oci-wasm](https://github.com/bytecodealliance/rust-oci-wasm) crate which enables pushing/pulling Wasm artifacts to/from any OCI registry. Unlike `wkg publish` and `wkg get` it is not limited to library components, as providing the WIT package is not required.
102
+
103
+
A component is pushed to an OCI registry using `wkg oci pull`. The example below pulls a component from a GitHub Container Registry.
One may be tempted to simply get the `wasi:http` package with `wkg get --format wit wasi:[email protected] -o wit/deps/http/`. However, `wasi:http` depends on other WASI packages such as `wasi:clocks` and `wasi:io`. To make sure to fetch a package and all its dependencies, use `wkg fetch`, which will read the package containing the world(s) you have defined in the given wit directory (`wit` by default). It will then fetch the
127
+
You may be tempted to simply get the `wasi:http` package with `wkg get --format wit wasi:[email protected] -o wit/deps/http/`. However, `wasi:http` depends on other WASI packages such as `wasi:clocks` and `wasi:io`. To make sure to fetch a package and all its dependencies, use `wkg wit fetch`, which will read the package containing the world(s) you have defined in the given wit directory (`wit` by default). It will then fetch the
104
128
dependencies and write them to the `deps` directory along with a lock file.
105
129
106
130
After placing the above file in `./wit`, run the following to fetch the dependencies:
0 commit comments