Skip to content

Commit 8a0d20e

Browse files
authored
Rust build image
1 parent 727c57b commit 8a0d20e

File tree

12 files changed

+185
-7
lines changed

12 files changed

+185
-7
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build and Push WASM Rust Base Image
2+
3+
on:
4+
push:
5+
branches: [ main, wasm ]
6+
paths:
7+
- 'samples/wasm/base-image/**'
8+
pull_request:
9+
branches: [ main ]
10+
paths:
11+
- 'samples/wasm/base-image/**'
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
shell: bash
20+
steps:
21+
- name: "Checkout GitHub Action"
22+
uses: actions/checkout@main
23+
24+
- name: "Login to GitHub Container Registry"
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{github.actor}}
29+
password: ${{secrets.GITHUB_TOKEN}}
30+
31+
- name: Extract metadata
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ghcr.io/${{github.repository_owner}}/explore-iot-operations/wasm-rust-build
36+
tags: |
37+
type=ref,event=branch
38+
type=ref,event=pr
39+
type=sha,prefix={{branch}}-
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
42+
- name: "Build and Push Base Image"
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: samples/wasm/base-image
46+
file: samples/wasm/base-image/Dockerfile
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

docker/wasm-rust-build/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARG RUST_VERSION=1.85
2+
FROM rust:${RUST_VERSION}-alpine
3+
4+
ARG ARCH="x86_64"
5+
6+
RUN apk add --no-cache clang lld musl-dev git perl make cmake
7+
RUN rustup target add wasm32-wasip2 ${ARCH}-unknown-linux-gnu
8+
9+
# Set up environment for Cargo registry
10+
ENV CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX="sparse+https://pkgs.dev.azure.com/azure-iot-sdks/iot-operations/_packaging/preview/Cargo/index/"
11+
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
12+
13+
WORKDIR /src

docker/wasm-rust-build/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
- Environment variables for Azure IoT Operations Cargo registry
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+
WORKDIR /src
24+
COPY ./Cargo.toml ./Cargo.toml
25+
COPY ./src ./src
26+
27+
RUN if [ "${BUILD_MODE}" = "release" ]; then \
28+
cargo build --release --target wasm32-wasip2; \
29+
else \
30+
cargo build --target wasm32-wasip2; \
31+
fi
32+
33+
FROM scratch
34+
ARG BUILD_MODE
35+
ARG APP_NAME
36+
COPY --from=operator-build "/src/target/wasm32-wasip2/${BUILD_MODE}/${APP_NAME}.wasm" "${APP_NAME}.wasm"
37+
ENTRYPOINT [ "${APP_NAME}.wasm" ]
38+
```
39+
40+
## Build Arguments
41+
42+
- `RUST_VERSION`: Rust version to use (default: 1.85)
43+
- `ARCH`: Target architecture (default: x86_64)
44+
45+
## Environment Variables
46+
47+
- `CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX`: Azure IoT Operations Cargo registry URL
48+
- `CARGO_NET_GIT_FETCH_WITH_CLI`: Use Git CLI for fetching dependencies
49+
50+
## Publishing
51+
52+
This image is automatically built and published to GitHub Container Registry via GitHub Actions when changes are made to the `docker/wasm-rust-build/` directory.

samples/wasm/base-image/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG RUST_VERSION=1.85
2+
FROM rust:${RUST_VERSION}-alpine
3+
4+
ARG ARCH="x86_64"
5+
6+
RUN apk add --no-cache clang lld musl-dev git perl make cmake
7+
RUN rustup target add wasm32-wasip2 ${ARCH}-unknown-linux-gnu

samples/wasm/base-image/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.

samples/wasm/operators/collection/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG IMAGE=tinykube-wasm-rust-build
1+
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
22
FROM $IMAGE AS operator-build
33

44
ARG APP_NAME

samples/wasm/operators/enrichment/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG IMAGE=tinykube-wasm-rust-build
1+
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
22
FROM $IMAGE AS operator-build
33

44
ARG APP_NAME

samples/wasm/operators/format/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG IMAGE=tinykube-wasm-rust-build
1+
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
22
FROM $IMAGE AS operator-build
33

44
ARG APP_NAME

samples/wasm/operators/humidity/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG IMAGE=tinykube-wasm-rust-build
1+
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
22
FROM $IMAGE AS operator-build
33

44
ARG APP_NAME

samples/wasm/operators/snapshot/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG IMAGE=tinykube-wasm-rust-build
1+
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
22
FROM $IMAGE AS operator-build
33

44
ARG APP_NAME

0 commit comments

Comments
 (0)