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
45 changes: 45 additions & 0 deletions .github/scripts/devcontainer/publication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Small GHCR publication contract."""

import argparse
import re


SHA = re.compile(r"[0-9a-f]{40}\Z")


def _identity_tag(prefix, source_sha, run_id, attempt):
if not SHA.fullmatch(source_sha):
raise ValueError("Invalid source SHA")
if type(run_id) is not int or run_id <= 0 or type(attempt) is not int or attempt <= 0:
raise ValueError("Run identity must be positive integers")
tag = f"{prefix}-{source_sha}-run-{run_id}-attempt-{attempt}"
if len(tag + "-stage-amd64") > 128:
raise ValueError("Image staging tag exceeds 128 characters")
return tag


def durable_tag(source_sha, run_id, attempt):
return _identity_tag("build", source_sha, run_id, attempt)


def candidate_tag(pr, source_sha, run_id, attempt):
if type(pr) is not int or pr <= 0:
raise ValueError("PR number must be positive")
return _identity_tag(f"pr-{pr}", source_sha, run_id, attempt)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=("tag", "candidate"))
parser.add_argument("--source-sha")
parser.add_argument("--run-id", type=int)
parser.add_argument("--attempt", type=int)
parser.add_argument("--pr", type=int)
parser.add_argument("--digest")
args = parser.parse_args()
if args.command == "tag":
print(durable_tag(args.source_sha, args.run_id, args.attempt))
elif args.command == "candidate":
print(candidate_tag(args.pr, args.source_sha, args.run_id, args.attempt))
if __name__ == "__main__":
main()
46 changes: 46 additions & 0 deletions .github/tests/devcontainer/test_publication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Small GHCR publication contract tests."""

import importlib.util
from pathlib import Path
import unittest


MODULE = Path(__file__).resolve().parents[3] / ".github/scripts/devcontainer/publication.py"


def load_module():
spec = importlib.util.spec_from_file_location("publication", MODULE)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


class PublicationTests(unittest.TestCase):
def setUp(self):
self.publication = load_module()
self.source = "a" * 40

def test_durable_tag_contains_source_run_and_attempt(self):
self.assertEqual(
self.publication.durable_tag(self.source, 44964975569, 2),
"build-" + self.source + "-run-44964975569-attempt-2",
)

def test_candidate_tag_uses_pr_merge_sha_run_and_attempt(self):
self.assertEqual(
self.publication.candidate_tag(123, self.source, 44964975569, 2),
"pr-123-" + self.source + "-run-44964975569-attempt-2",
)

def test_tags_reject_invalid_identity(self):
for function, args in (
(self.publication.durable_tag, ("bad", 1, 1)),
(self.publication.candidate_tag, (0, self.source, 1, 1)),
(self.publication.candidate_tag, (123, "bad", 1, 1)),
(self.publication.durable_tag, (self.source, 0, 1)),
):
with self.assertRaises(ValueError):
function(*args)

if __name__ == "__main__":
unittest.main()
142 changes: 142 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: devcontainer GHCR publication

on:
workflow_call:
inputs:
candidate:
type: boolean
required: false
default: false
outputs:
image_ref:
description: Immutable image reference.
value: ${{ jobs.publish.outputs.image_ref }}

permissions:
contents: read

jobs:
prepare:
if: github.repository == 'WasmEdge/devcontainer' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || inputs.candidate)
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.identity.outputs.tag }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
- id: identity
env:
SOURCE_SHA: ${{ github.sha }}
RUN_ID: ${{ github.run_id }}
ATTEMPT: ${{ github.run_attempt }}
run: |
if [ '${{ inputs.candidate }}' = true ]; then
tag=$(python3 .github/scripts/devcontainer/publication.py candidate --pr '${{ github.event.number }}' \
--source-sha "$SOURCE_SHA" --run-id "$RUN_ID" --attempt "$ATTEMPT")
else
tag=$(python3 .github/scripts/devcontainer/publication.py tag \
--source-sha "$SOURCE_SHA" --run-id "$RUN_ID" --attempt "$ATTEMPT")
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"

build:
needs: prepare
if: github.repository == 'WasmEdge/devcontainer' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || inputs.candidate)
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
target: x86_64
arch: amd64
- runner: ubuntu-24.04-arm
target: aarch64
arch: arm64
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push native platform
uses: docker/bake-action@59cb1203cd42bcefd40a1b6d73b589e48c86040e # v7.5.0
with:
source: .
files: docker-bake.ci-image-base.hcl
targets: ${{ matrix.target }}
push: true
set: |
${{ matrix.target }}.tags=ghcr.io/wasmedge/devcontainer:${{ needs.prepare.outputs.tag }}-stage-${{ matrix.arch }}
${{ matrix.target }}.labels.org.opencontainers.image.source=https://github.com/WasmEdge/devcontainer
${{ matrix.target }}.labels.org.opencontainers.image.revision=${{ github.sha }}

publish:
needs:
- prepare
- build
if: needs.build.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image_ref: ${{ steps.publish.outputs.image_ref }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Assemble multi-platform index
id: publish
env:
TAG: ${{ needs.prepare.outputs.tag }}
run: |
image=ghcr.io/wasmedge/devcontainer
docker buildx imagetools create --tag "$image:$TAG" \
"$image:$TAG-stage-amd64" "$image:$TAG-stage-arm64"
digest=$(docker buildx imagetools inspect "$image:$TAG" \
--format '{{json .Manifest.Digest}}' | tr -d '"')
if [ -z "$digest" ] || [ "$digest" = "null" ]; then
echo "Failed to obtain image digest" >&2
exit 1
fi
if [ '${{ inputs.candidate }}' != true ]; then
docker buildx imagetools create --tag "$image:latest" "$image@$digest"
fi
echo "image_ref=$image@$digest" >> "$GITHUB_OUTPUT"

summarize-publication:
needs:
- prepare
- publish
if: needs.publish.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Report published image
env:
IMAGE_REF: ${{ needs.publish.outputs.image_ref }}
TAG: ${{ needs.prepare.outputs.tag }}
run: |
image=ghcr.io/wasmedge/devcontainer
{
echo "## Published GHCR image"
echo
echo "- Immutable reference: \`$image:$TAG@${IMAGE_REF#*@}\`"
} >> "$GITHUB_STEP_SUMMARY"
38 changes: 28 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- main
paths:
- '.github/workflows/docker.yml'
- '.github/workflows/devcontainer.yml'
- 'Dockerfile.*'
- 'docker-bake.*.hcl'
- 'SHA256SUM.*'
Expand All @@ -29,8 +30,6 @@ on:
- 'scripts/opencvmini/**'
- 'scripts/wasi-crypto/**'
- 'scripts/wasi-nn/**'
schedule:
- cron: "0 0 */7 * *"

permissions:
contents: read
Expand All @@ -54,9 +53,7 @@ jobs:
run: |
DOCKER_IMAGE=wasmedge/wasmedge
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(printf '%s\n' "${GITHUB_REF#refs/heads/}" | sed -r 's#/+#-#g')
Expand Down Expand Up @@ -98,6 +95,7 @@ jobs:
filters: |
ci-image-base:
- '.github/workflows/docker.yml'
- '.github/workflows/devcontainer.yml'
- 'docker-bake.ci-image-base.hcl'
- 'Dockerfile.ci-image-base'
alpine-base:
Expand Down Expand Up @@ -153,11 +151,23 @@ jobs:
files: docker-bake.ci-image-base.hcl
push: ${{ github.event_name != 'pull_request' }}

devcontainer-ghcr:
needs: [prep, paths-filter]
name: devcontainer GHCR publication
permissions:
contents: read
packages: write
# Fork-origin PR package permissions remain a rollout decision; keep this
# path free of fork-specific handling until that behavior is verified.
uses: ./.github/workflows/devcontainer.yml
with:
candidate: ${{ github.event_name == 'pull_request' && needs.paths-filter.outputs.ci-image-base == 'true' }}

build-alpine-base-images:
needs:
- prep
- paths-filter
# Only run if files changed or if it's a scheduled/merge build
# Only run if files changed or if it's a merge build
if: ${{ needs.paths-filter.outputs.alpine-base == 'true' }}

name: Alpine Base (3.23)
Expand Down Expand Up @@ -199,7 +209,8 @@ jobs:
- prep
- paths-filter
- bake-base-images
if: ${{ needs.paths-filter.outputs.ubuntu == 'true' }}
- devcontainer-ghcr
if: ${{ !cancelled() && needs.prep.result == 'success' && needs.paths-filter.result == 'success' && needs.paths-filter.outputs.ubuntu == 'true' && (needs.paths-filter.outputs.ci-image-base != 'true' || needs.devcontainer-ghcr.result == 'success' || needs.devcontainer-ghcr.result == 'skipped') }}

strategy:
fail-fast: false
Expand All @@ -210,8 +221,11 @@ jobs:

name: Ubuntu
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
container:
image: wasmedge/wasmedge:ci-image-base
image: ${{ needs.devcontainer-ghcr.result == 'success' && needs.devcontainer-ghcr.outputs.image_ref || 'wasmedge/wasmedge:ci-image-base' }}

steps:
- name: Harden the runner (Audit all outbound calls)
Expand Down Expand Up @@ -249,7 +263,8 @@ jobs:
- prep
- paths-filter
- bake-base-images
if: ${{ needs.paths-filter.outputs.manylinux == 'true' }}
- devcontainer-ghcr
if: ${{ !cancelled() && needs.prep.result == 'success' && needs.paths-filter.result == 'success' && needs.paths-filter.outputs.manylinux == 'true' && (needs.paths-filter.outputs.ci-image-base != 'true' || needs.devcontainer-ghcr.result == 'success' || needs.devcontainer-ghcr.result == 'skipped') }}

strategy:
fail-fast: false
Expand All @@ -268,8 +283,11 @@ jobs:

name: ${{ matrix.name }}
runs-on: ${{ matrix.host_runner }}
permissions:
contents: read
packages: read
container:
image: ${{ matrix.host_container }}
image: ${{ needs.devcontainer-ghcr.result == 'success' && needs.devcontainer-ghcr.outputs.image_ref || matrix.host_container }}

steps:
- name: Harden the runner (Audit all outbound calls)
Expand Down
14 changes: 13 additions & 1 deletion Dockerfile.debian-static
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY --from=xx / /
# Install host dependencies
RUN apt-get update -y && apt-get install --no-install-recommends -y \
lsb-release ca-certificates curl wget gnupg \
cmake ninja-build git clang xz-utils
cmake ninja-build git clang xz-utils file

# Set up llvm's apt repo
ARG LLVM_VERSION
Expand Down Expand Up @@ -85,6 +85,18 @@ RUN cmake -S /src -B /build -G Ninja \
-DWASMEDGE_USE_LLVM=ON

RUN cmake --build /build -- install

# Link a consumer against the installed static library
RUN /bin/bash <<EOT
set -ex
cat <<EOF > /smoke.c
#include <wasmedge/wasmedge.h>
int main(void) { return WasmEdge_VersionGet() == 0; }
EOF
xx-clang /smoke.c -I/install/include -L/install/lib -lwasmedge -lstdc++ -lm -lrt -ldl -lpthread -o /smoke
xx-verify /smoke
EOT

RUN cmake --build /build -- package
RUN mv /build/WasmEdge-*-Linux.tar.gz $(echo build/WasmEdge-*-Linux.tar.gz | sed 's|WasmEdge-\(.*\)-Linux.tar.gz|WasmEdge-\1-debian'$(lsb_release -sr)'_'$(xx-info march)'_static.tar.gz|')

Expand Down
7 changes: 0 additions & 7 deletions Dockerfile.manylinux_2_28-plugins-deps
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ RUN cd && (yum check-update || true) && \
### deps for all ###
FROM deps-${TARGETARCH} AS final

COPY scripts/opencvmini/install-opencvmini.sh .
ENV OPENCV_VERSION="4.8.0"
RUN [ "/bin/bash", "install-opencvmini.sh" ]

COPY scripts/wasi-crypto/build-openssl.sh .
ENV OpenSSL_DIR="/root/openssl-1.1.1n/openssl"
RUN [ "/bin/bash", "build-openssl.sh" ]
Expand All @@ -43,9 +39,6 @@ ENV LD_LIBRARY_PATH=/root/FFmpeg-n7.1.1/output/lib${LD_LIBRARY_PATH:+:${LD_LIBRA
ENV OPENVINO_VERSION="2025.0.0"
ENV OPENVINO_YEAR="2025"

COPY scripts/wasi-nn/install-onnxruntime.sh .
RUN [ "/bin/bash", "install-onnxruntime.sh" ]

COPY scripts/wasi-nn/libpiper.patch .
COPY scripts/wasi-nn/install-libpiper.sh .
RUN [ "/bin/bash", "install-libpiper.sh" ]
Expand Down
Loading
Loading