Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/wasm-python-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and Publish WASM Python Builder Image

on:
workflow_dispatch:
push:
branches: [ main, wasm ]
paths:
- 'samples/wasm/python/Dockerfile'
- 'samples/wasm/python/schema/**'
- 'samples/wasm/python/inject_pdb.py'
pull_request:
branches: [ main ]
paths:
- 'samples/wasm/python/Dockerfile'
- 'samples/wasm/python/schema/**'
- 'samples/wasm/python/inject_pdb.py'

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/azure-samples/explore-iot-operations/python-wasm-builder
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: samples/wasm/python
file: samples/wasm/python/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
52 changes: 52 additions & 0 deletions .github/workflows/wasm-rust-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Push WASM Rust Builder Image

on:
workflow_dispatch:
push:
branches: [ main, wasm ]
paths:
- 'samples/wasm/rust/Dockerfile'
pull_request:
branches: [ main ]
paths:
- 'samples/wasm/rust/Dockerfile'

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
defaults:
run:
shell: bash
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@main

- name: "Login to GitHub Container Registry"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/azure-samples/explore-iot-operations/rust-wasm-builder
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
type=raw,value=latest

- name: "Build and Push Rust Builder Image"
uses: docker/build-push-action@v5
with:
context: samples/wasm/rust
file: samples/wasm/rust/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
13 changes: 13 additions & 0 deletions docker/wasm-rust-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG RUST_VERSION=1.85
FROM rust:${RUST_VERSION}-alpine

ARG ARCH="x86_64"

RUN apk add --no-cache clang lld musl-dev git perl make cmake
RUN rustup target add wasm32-wasip2 ${ARCH}-unknown-linux-gnu

# Set up environment for Cargo registry
ENV CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX="sparse+https://pkgs.dev.azure.com/azure-iot-sdks/iot-operations/_packaging/preview/Cargo/index/"
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true

WORKDIR /src
52 changes: 52 additions & 0 deletions docker/wasm-rust-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# WASM Rust Build Base Image

This Docker image provides a base environment for building WebAssembly (WASM) applications with Rust targeting the `wasm32-wasip2` platform.

## Features

- Based on Alpine Linux with Rust 1.85
- Pre-configured for WASM compilation with `wasm32-wasip2` target
- Required build tools: clang, lld, musl-dev, git, perl, make, cmake
- Environment variables for Azure IoT Operations Cargo registry

## Usage

This base image is intended to be used as a build stage in multi-stage Docker builds for WASM operators:

```dockerfile
ARG IMAGE=ghcr.io/azure-samples/explore-iot-operations/wasm-rust-build:latest
FROM $IMAGE AS operator-build

ARG APP_NAME
ARG BUILD_MODE="release"

WORKDIR /src
COPY ./Cargo.toml ./Cargo.toml
COPY ./src ./src

RUN if [ "${BUILD_MODE}" = "release" ]; then \
cargo build --release --target wasm32-wasip2; \
else \
cargo build --target wasm32-wasip2; \
fi

FROM scratch
ARG BUILD_MODE
ARG APP_NAME
COPY --from=operator-build "/src/target/wasm32-wasip2/${BUILD_MODE}/${APP_NAME}.wasm" "${APP_NAME}.wasm"
ENTRYPOINT [ "${APP_NAME}.wasm" ]
```

## Build Arguments

- `RUST_VERSION`: Rust version to use (default: 1.85)
- `ARCH`: Target architecture (default: x86_64)

## Environment Variables

- `CARGO_REGISTRIES_AZURE_VSCODE_TINYKUBE_INDEX`: Azure IoT Operations Cargo registry URL
- `CARGO_NET_GIT_FETCH_WITH_CLI`: Use Git CLI for fetching dependencies

## Publishing

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.
Loading