-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathDockerfile.guest_and_host
More file actions
77 lines (65 loc) · 3.13 KB
/
Dockerfile.guest_and_host
File metadata and controls
77 lines (65 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
FROM ubuntu:24.04 AS build
ARG WASMTIME_VERSION=42.0.1
ARG WASI_SDK_VERSION=27
ARG TARGETARCH
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc libc6-dev curl xz-utils ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install wasmtime C API
RUN set -eux; \
case "${TARGETARCH}" in \
amd64) WASMTIME_ARCH=x86_64 ;; \
arm64) WASMTIME_ARCH=aarch64 ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac; \
curl -sL "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-${WASMTIME_ARCH}-linux-c-api.tar.xz" \
| tar xJ --strip-components=1 -C /usr/local; \
ldconfig
# Install wasi-sdk (for building the guest component)
RUN set -eux; \
case "${TARGETARCH}" in \
amd64) WASI_SDK_ARCH=amd64 ;; \
arm64) WASI_SDK_ARCH=arm64 ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac; \
curl -sLO "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-${WASI_SDK_ARCH}-linux.deb"; \
dpkg -i "wasi-sdk-${WASI_SDK_VERSION}.0-${WASI_SDK_ARCH}-linux.deb"; \
rm "wasi-sdk-${WASI_SDK_VERSION}.0-${WASI_SDK_ARCH}-linux.deb"
# Install wit-bindgen and wasm-tools (pin versions)
ARG WIT_BINDGEN_VERSION=0.53.1
ARG WASM_TOOLS_VERSION=1.245.1
RUN set -eux; \
case "${TARGETARCH}" in \
amd64) TOOL_ARCH=x86_64 ;; \
arm64) TOOL_ARCH=aarch64 ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac; \
curl -sL "https://github.com/bytecodealliance/wit-bindgen/releases/download/v${WIT_BINDGEN_VERSION}/wit-bindgen-${WIT_BINDGEN_VERSION}-${TOOL_ARCH}-linux.tar.gz" \
| tar xz --strip-components=1 -C /usr/local/bin --wildcards '*/wit-bindgen'; \
curl -sL "https://github.com/bytecodealliance/wasm-tools/releases/download/v${WASM_TOOLS_VERSION}/wasm-tools-${WASM_TOOLS_VERSION}-${TOOL_ARCH}-linux.tar.gz" \
| tar xz --strip-components=1 -C /usr/local/bin --wildcards '*/wasm-tools'
WORKDIR /src
# Fetch guest source from upstream component-docs
ARG COMPONENT_DOCS_REV=7c1b5a9
RUN curl -sL -o world.wit \
https://raw.githubusercontent.com/bytecodealliance/component-docs/${COMPONENT_DOCS_REV}/component-model/examples/tutorial/wit/adder/world.wit \
&& mkdir -p wit/adder && mv world.wit wit/adder/world.wit
RUN curl -sL -o component.c \
https://raw.githubusercontent.com/bytecodealliance/component-docs/${COMPONENT_DOCS_REV}/component-model/examples/tutorial/c/adder/component.c
# Build the guest component
RUN wit-bindgen c wit/adder/world.wit
RUN /opt/wasi-sdk/bin/wasm32-wasip2-clang \
-o adder.wasm \
-mexec-model=reactor \
component.c adder.c adder_component_type.o
# Build the host
COPY host.c .
RUN gcc -o /usr/local/bin/adder-host host.c -lwasmtime
# Runtime image
FROM ubuntu:24.04
COPY --from=build /usr/local/lib/libwasmtime.so /usr/local/lib/
RUN ldconfig
COPY --from=build /usr/local/bin/adder-host /usr/local/bin/adder-host
COPY --from=build /src/adder.wasm /opt/adder.wasm
ENTRYPOINT ["adder-host"]
CMD ["1", "2", "/opt/adder.wasm"]