Skip to content

Commit

Permalink
reuse artifacts
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Aug 24, 2023
1 parent 8321dd8 commit f18d9d7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
35 changes: 31 additions & 4 deletions .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 @@ -93,12 +94,18 @@ jobs:
- name: Package artifacts
shell: bash
run: |
mkdir -p artifacts
make install PREFIX=${{ github.workspace }} RUNTIMES=${{ matrix.runtime }}
- uses: actions/upload-artifact@master
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 }}
path: ${{ github.workspace }}/bin
path: dist/containerd-shim-${{ matrix.runtime }}-${{ matrix.os }}.tar.gz

e2e-wasmtime:
needs: [build]
Expand Down Expand Up @@ -126,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 @@ -163,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
11 changes: 6 additions & 5 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 Down
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
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

0 comments on commit f18d9d7

Please sign in to comment.