Skip to content

Commit

Permalink
Merge pull request #82 from cpuguy83/fixup_for_publishing
Browse files Browse the repository at this point in the history
More publishing cleanup
  • Loading branch information
cpuguy83 authored Mar 6, 2023
2 parents 857623f + 1deaed5 commit 9ef3314
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 169 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ LICENSE
.dockerignore
docs
bin/
Dockerfile
docker-bake.hcl
release/
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
os: ["ubuntu-20.04", "ubuntu-22.04"]
runs-on: ${{ matrix.os }}
steps:
- uses: Swatinem/rust-cache@v2
- name: "check cgroup version"
run: "mount | grep cgroup"
- uses: actions/checkout@v3
Expand Down
156 changes: 51 additions & 105 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,83 @@
name: release

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
group: release-${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

on:
push:
tags:
- 'v[0-9]+.[0-9]+.*'
- '**/v[0-9]+.[0-9]+.*'

env:
CARGO_TERM_COLOR: always
REPO_SLUG: "deislabs/runwasi"

jobs:
hub:
generate:
runs-on: ubuntu-latest
name: Generate
outputs:
crate: ${{ steps.parse-ref.outputs.crate }}
version: ${{ steps.parse-ref.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- id: parse-ref
run: |
echo "CRATE=$(cut -d/ -f1 <<<"${GITHUB_REF#refs/*/}")" >> $GITHUB_OUTPUT
echo "VERSION=$(cut -d/ -f2 <<<"${GITHUB_REF#refs/*/}")" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REPO_SLUG }}
### frontend versioning
### on semver tag:
# deislabs/runwasi:1.2.3
# deislabs/runwasi:1.2
# deislabs/runwasi:1
# deislabs/runwasi:latest
### on pre-release tag:
# deislabs/runwasi:1.1.0-rc.1
### on push default branch (main):
# deislabs/runwasi:main
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=raw,value=latest
type=ref,event=pr
bake-target: meta-helper
flavor: |
latest=false
- name: Login to DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push
uses: docker/bake-action@v2
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image-cross
push: ${{ github.event_name != 'pull_request' }}
build:
runs-on: ubuntu-latest
needs:
- generate
strategy:
matrix:
os: ["ubuntu-20.04", "ubuntu-22.04"]
runs-on: ${{ matrix.os }}
steps:
- uses: Swatinem/rust-cache@v2
- name: "check cgroup version"
run: "mount | grep cgroup"
- uses: actions/checkout@v3
- name: Install rust
run: |
set -e
toolchain="$(grep "ARG RUST_VERSION" Dockerfile | cut -d = -f2)"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${toolchain:-stable}
- name: Setup WasmEdge build env
if: ${{ contains(needs.generate.outputs.crate, 'wasmedge' ) }}
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.11.2
echo "LD_LIBRARY_PATH=$HOME/.wasmedge/lib" >> $GITHUB_ENV
- name: Install deps on arm64
run: |
sudo apt update
sudo apt install -y clang llvm
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo build --verbose --package ${{ needs.generate.outputs.crate }}
- name: Test
run: cargo test --verbose --package ${{ needs.generate.outputs.crate }}

release:
permissions:
contents: write
needs: build
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build
- generate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup WasmEdge build env
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.11.2
echo "LD_LIBRARY_PATH=$HOME/.wasmedge/lib" >> $GITHUB_ENV
- name: Install deps on arm64
run: |
sudo apt update
sudo apt install -y clang llvm
- name: Set RELEASE_VERSION ENV var
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: lowercase the runner OS name
shell: bash
run: |
OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
echo "RUNNER_OS=$OS" >> $GITHUB_ENV
- name: Install latest Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
- name: build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: package release assets
run: |
mkdir _dist
cp target/release/containerd-shim-wasmtime-v1 _dist/
cp target/release/containerd-shim-wasmedge-v1 _dist/
cd _dist
tar czf containerd-shim-v1-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-amd64.tar.gz containerd-shim-wasmtime-v1 containerd-shim-wasmedge-v1
- uses: actions/checkout@v3
- name: Setup buildx
run: docker buildx create --use
- name: build binaries
run: docker buildx bake --set *.cache-from=type=gha --set *.cache-to=type=gha release-tars
env:
CRATE: ${{ needs.generate.outputs.crate }}
- name: upload binary as GitHub artifact
uses: actions/upload-artifact@v3
with:
name: containerd-shim-v1
path: _dist/containerd-shim-v1-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-amd64.tar.gz
- name: upload binary to GitHub release
uses: svenstaro/[email protected]
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: _dist/containerd-shim-v1-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-amd64.tar.gz
asset_name: containerd-shim-v1-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-amd64.tar.gz
overwrite: true
prerelease: true
tag: ${{ github.ref }}
body: |
Release of containerd-shim-v1:${{ env.RELEASE_VERSION }} for amd64
path: release/
name: ${{ needs.generate.outputs.crate }}-${{ needs.generate.outputs.version }}
- name: Create release
run: |
gh release create ${{ github.ref }} --generate-notes --prerelease
for i in release/*/*; do
gh release upload ${RELEASE_NAME} $i
done
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test/out/img.tar
!crates/wasmedge/src/bin/
!crates/wasmtime/src/bin/
test/k8s/_out
release/
88 changes: 44 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ members = [
"crates/containerd-shim-wasm",
"crates/wasi-demo-app",
"crates/oci-tar-builder",
"crates/wasmedge",
"crates/wasmtime",
"crates/containerd-shim-wasmedge",
"crates/containerd-shim-wasmtime",
]

[workspace.package]
Expand Down
49 changes: 37 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# syntax=docker/dockerfile:1

ARG RUST_VERSION=1.63
ARG RUST_VERSION=1.64
ARG XX_VERSION=1.1.0

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION} AS base
COPY --from=xx / /
RUN apt-get update -y && apt-get install --no-install-recommends -y clang
RUN apt-get update -y && apt-get install --no-install-recommends -y clang jq

FROM base AS build
SHELL ["/bin/bash", "-c"]
Expand All @@ -23,22 +23,47 @@ RUN <<EOT
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.11.2 --platform=${os^} --machine=$(xx-info march)
EOT

COPY . .
WORKDIR /

WORKDIR /build/src
COPY --link crates ./crates
COPY --link Cargo.toml ./
COPY --link Cargo.lock ./
ARG CRATE=""
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry/cache \
--mount=type=cache,target=/usr/local/cargo/registry/index <<EOT
--mount=type=cache,target=/usr/local/cargo/registry/index \
--mount=type=cache,target=/build/src/target,id=runwasi-cargo-build-cache-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} <<EOT
set -e
export "CARGO_NET_GIT_FETCH_WITH_CLI=true"
export "CARGO_TARGET_$(xx-info march | tr '[:lower:]' '[:upper:]' | tr - _)_UNKNOWN_$(xx-info os | tr '[:lower:]' '[:upper:]' | tr - _)_$(xx-info libc | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=$(xx-info)-gcc"
export "CC_$(xx-info march | tr '[:lower:]' '[:upper:]' | tr - _)_UNKNOWN_$(xx-info os | tr '[:lower:]' '[:upper:]' | tr - _)_$(xx-info libc | tr '[:lower:]' '[:upper:]' | tr - _)=$(xx-info)-gcc"
cargo build --release --target=$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)
cp target/$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)/release/containerd-shim-wasmedge-v1 /containerd-shim-wasmedge-v1
cp target/$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)/release/containerd-shim-wasmtime-v1 /containerd-shim-wasmtime-v1
if [ -n "${CRATE}" ]; then
package="--package=${CRATE}"
fi
cargo build --release --target=$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc) ${package}
EOT
COPY scripts ./scripts
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry/cache \
--mount=type=cache,target=/usr/local/cargo/registry/index \
--mount=type=cache,target=/build/src/target,id=runwasi-cargo-build-cache-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} <<EOT
set -e
mkdir /build/bin
bins="$(scripts/bins.sh ${CRATE} | jq -r 'join(" ")')"
echo "Copying binaries: ${bins}"
for bin in ${bins}; do
cp target/$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)/release/${bin} /build/bin/${bin}
done
EOT

FROM build AS build-tar
WORKDIR /build/release
ARG CRATE
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN tar -C /build/bin -czf /build/release/${CRATE}-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}.tar.gz .

FROM scratch AS release-tar
COPY --link --from=build-tar /build/release/* /

FROM scratch AS release
COPY --link --from=build /containerd-shim-wasmedge-v1 /containerd-shim-wasmedge-v1
COPY --link --from=build /root/.wasmedge/lib/libwasmedge.so.0.0.1 /libwasmedge.so.0.0.1
COPY --link --from=build /containerd-shim-wasmtime-v1 /containerd-shim-wasmtime-v1
COPY --link --from=build /build/bin/* /
Loading

0 comments on commit 9ef3314

Please sign in to comment.