|
| 1 | +# WASM Rust Build Base Image |
| 2 | + |
| 3 | +This Docker image provides a base environment for building WebAssembly (WASM) applications with Rust targeting the `wasm32-wasip2` platform. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Based on Alpine Linux with Rust 1.85 |
| 8 | +- Pre-configured for WASM compilation with `wasm32-wasip2` target |
| 9 | +- Required build tools: clang, lld, musl-dev, git, perl, make, cmake |
| 10 | +- Minimal base image - environment variables configured per operator |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +This base image is intended to be used as a build stage in multi-stage Docker builds for WASM operators: |
| 15 | + |
| 16 | +```dockerfile |
| 17 | +ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest |
| 18 | +FROM $IMAGE AS operator-build |
| 19 | + |
| 20 | +ARG APP_NAME |
| 21 | +ARG BUILD_MODE="release" |
| 22 | + |
| 23 | +ENV CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX="sparse+https://pkgs.dev.azure.com/azure-iot-sdks/iot-operations/_packaging/preview/Cargo/index/" |
| 24 | +ENV CARGO_NET_GIT_FETCH_WITH_CLI=true |
| 25 | + |
| 26 | +WORKDIR /src |
| 27 | +COPY ./Cargo.toml ./Cargo.toml |
| 28 | +COPY ./src ./src |
| 29 | + |
| 30 | +RUN if [ "${BUILD_MODE}" = "release" ]; then |
| 31 | + cargo build --release --target wasm32-wasip2; |
| 32 | + else |
| 33 | + cargo build --target wasm32-wasip2; |
| 34 | + fi |
| 35 | + |
| 36 | +FROM scratch |
| 37 | +ARG BUILD_MODE |
| 38 | +ARG APP_NAME |
| 39 | +COPY --from=operator-build "/src/target/wasm32-wasip2/${BUILD_MODE}/${APP_NAME}.wasm" "${APP_NAME}.wasm" |
| 40 | +ENTRYPOINT [ "${APP_NAME}.wasm" ] |
| 41 | +``` |
| 42 | + |
| 43 | +## Build Arguments |
| 44 | + |
| 45 | +- `RUST_VERSION`: Rust version to use (default: 1.85) |
| 46 | +- `ARCH`: Target architecture (default: x86_64) |
| 47 | + |
| 48 | +## Environment Variables |
| 49 | + |
| 50 | +The following environment variables should be set in operator Dockerfiles that use this base image: |
| 51 | + |
| 52 | +- `CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX`: Azure IoT Operations Cargo registry URL |
| 53 | +- `CARGO_NET_GIT_FETCH_WITH_CLI`: Use Git CLI for fetching dependencies |
| 54 | + |
| 55 | +## Publishing |
| 56 | + |
| 57 | +This image is automatically built and published to GitHub Container Registry via GitHub Actions when changes are made to the `samples/wasm/base-image/` directory. |
0 commit comments