Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share artifacts between jobs #267

Merged
merged 2 commits into from
Aug 24, 2023
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
39 changes: 38 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
steps:
- name: Free Disk Space (Ubuntu)
uses: insightsengineering/disk-space-reclaimer@v1
if: runner.os == 'Linux'
with:
tools-cache: true
android: true
Expand Down Expand Up @@ -51,6 +52,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-20.04", "ubuntu-22.04", "windows-latest"]
runtime: ["wasmtime", "wasmedge"]
runs-on: ${{ matrix.os }}
steps:
- name: Free Disk Space (Ubuntu)
Expand Down Expand Up @@ -83,12 +85,27 @@ jobs:
echo "WASMEDGE_LIB_DIR=C:\Program Files\WasmEdge\lib" >> $env:GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=C:\Program Files\WasmEdge\include" >> $env:GITHUB_ENV
- name: Build
run: make build
run: make build RUNTIMES=${{ matrix.runtime }}
- name: Validate docs
run: ./scripts/validate-docs.sh
- name: Run tests
run: |
make test
- name: Package artifacts
shell: bash
run: |
make dist RUNTIMES=${{ matrix.runtime }}
# Check if there's any files to archive as tar fails otherwise
if stat dist/bin/* >/dev/null 2>&1; then
tar -czf dist/containerd-shim-${{ matrix.runtime }}-${{ matrix.os }}.tar.gz -C dist/bin .
else
tar -czf dist/containerd-shim-${{ matrix.runtime }}-${{ matrix.os }}.tar.gz -T /dev/null
fi
- name: Upload artifacts
uses: actions/upload-artifact@master
with:
name: containerd-shim-${{ matrix.runtime }}-${{ matrix.os }}
jprendes marked this conversation as resolved.
Show resolved Hide resolved
path: dist/containerd-shim-${{ matrix.runtime }}-${{ matrix.os }}.tar.gz

e2e-wasmtime:
needs: [build]
Expand Down Expand Up @@ -116,6 +133,16 @@ jobs:
- name: Setup build env
run: ./scripts/setup-linux.sh
shell: bash
- name: Download artifacts
uses: actions/download-artifact@master
with:
name: containerd-shim-wasmtime-${{ matrix.os }}
path: dist
- name: Unpack artifats
shell: bash
run: |
mkdir -p dist/bin
tar -xzf dist/containerd-shim-wasmtime-${{ matrix.os }}.tar.gz -C dist/bin
- name: run
run: make test/k8s
# only runs when the previous step fails
Expand Down Expand Up @@ -153,6 +180,16 @@ jobs:
- name: Setup build env
run: ./scripts/setup-linux.sh
shell: bash
- name: Download artifacts
uses: actions/download-artifact@master
with:
name: containerd-shim-wasmedge-${{ matrix.os }}
path: dist
- name: Unpack artifats
shell: bash
run: |
mkdir -p dist/bin
tar -xzf dist/containerd-shim-wasmedge-${{ matrix.os }}.tar.gz -C dist/bin
- name: run
run: make test/k3s
- name: cleanup
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/
/dist/
/test/out/img.tar
/test/k8s/_out
**/target/
Expand Down
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ install:
$(INSTALL) target/$(TARGET)/containerd-$(runtime)d $(PREFIX)/bin/; \
)

dist:
$(MAKE) install PREFIX=$(PWD)/dist RUNTIMES=$(RUNTIMES) TARGET=$(TARGET)

.PHONY: test-image
test-image: target/wasm32-wasi/$(TARGET)/img.tar

Expand All @@ -78,7 +81,7 @@ load: target/wasm32-wasi/$(TARGET)/img.tar
bin/kind: test/k8s/Dockerfile
$(DOCKER_BUILD) --output=bin/ -f test/k8s/Dockerfile --target=kind .

test/k8s/_out/img: test/k8s/Dockerfile Cargo.toml Cargo.lock $(shell find . -type f -name '*.rs')
test/k8s/_out/img: test/k8s/Dockerfile dist
mkdir -p $(@D) && $(DOCKER_BUILD) -f test/k8s/Dockerfile --iidfile=$(@) --load .

.PHONY: test/nginx
Expand Down Expand Up @@ -110,12 +113,10 @@ bin/k3s/clean:
bin/k3s-runwasi-uninstall.sh

.PHONY: test/k3s
test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/k3s
cargo build $(RELEASE_FLAG) && \
cp target/$(TARGET)/containerd-shim-wasmedge-v1 $(PWD)/bin/ && \
test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/k3s dist
sudo cp /var/lib/rancher/k3s/agent/etc/containerd/config.toml /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo ' runtime_type = "$(PWD)/bin/containerd-shim-wasmedge-v1"' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo ' runtime_type = "$(PWD)/dist/bin/containerd-shim-wasmedge-v1"' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo "CONTAINERD_NAMESPACE='default'" | sudo tee /etc/systemd/system/k3s-runwasi.service.env && \
echo "NO_PROXY=192.168.0.0/16" | sudo tee -a /etc/systemd/system/k3s-runwasi.service.env && \
sudo systemctl daemon-reload && \
Expand All @@ -127,6 +128,4 @@ test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/k3s
sudo bin/k3s kubectl get pods -o wide

.PHONY: test/k3s/clean
test/k3s/clean: bin/k3s/clean
cargo clean
rm $(PWD)/bin/containerd-shim-wasmedge-v1
test/k3s/clean: bin/k3s/clean;
51 changes: 15 additions & 36 deletions test/k8s/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
# syntax=docker/dockerfile:1.4

ARG KIND_NODE_VERSION=v1.23.13

FROM kindest/node:${KIND_NODE_VERSION} AS kind-base

# We need the build to link using against same system libs as the kind image otherwise the shim won't work.
# So use the node image here as a base and install rust on top of it.
FROM kind-base AS shim-build
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup.sh && sh /tmp/rustup.sh -y --profile=minimal
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup install stable
WORKDIR /shim
COPY . .
RUN apt-get update && apt-get install --no-install-recommends -y build-essential git clang wget pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/shim/target \
mkdir -p /opt/shim; make build install PREFIX=/opt/shim

FROM scratch AS shim
COPY --from=shim-build /opt/shim/bin/* /


# Reuse kind-base so we don't have to download other images...
FROM kind-base AS kind-fetch
ARG TARGETARCH
ARG KIND_VERSION=v0.17.0
RUN curl -sSLf https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-${TARGETARCH} > /root/kind && chmod +x /root/kind
ARG KIND_NODE_VERSION=v1.23.13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be a follow up but we maybe should consider bumping this to a newer k8s version

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue to track this

ARG RUNTIME=wasmtime

FROM scratch AS kind
COPY --from=kind-fetch /root/kind /kind
ARG TARGETARCH KIND_VERSION
ADD --chmod=755 https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-${TARGETARCH} /kind

FROM kindest/node:${KIND_NODE_VERSION}
RUN apt-get update -y && \
apt-get install --no-install-recommends -y libdbus-1-3

FROM kind-base
RUN apt-get update && apt-get install --no-install-recommends -y build-essential git clang pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN <<EOF
set -e
echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]' >> /etc/containerd/config.toml
echo 'runtime_type = "io.containerd.wasmtime.v1"' >> /etc/containerd/config.toml
sed -i 's,SystemdCgroup = true,,' /etc/containerd/config.toml
EOF
COPY --link --from=shim /* /usr/local/bin/
ADD dist/bin/* /usr/local/bin/

ARG RUNTIME
RUN sed -i 's,SystemdCgroup = true,,' /etc/containerd/config.toml && \
cat <<EOF >> /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]
runtime_type = "io.containerd.${RUNTIME}.v1"
EOF