-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from vdice/ci/kwasm-node-installer
feat(*): add node installer dir and workflow
- Loading branch information
Showing
8 changed files
with
196 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Publish node-installer image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
ref: | ||
description: 'the git ref for the associated workflow' | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
# Note: assumes being called in a workflow where build has already run and | ||
# required artifacts have been uploaded | ||
publish: | ||
permissions: | ||
contents: read | ||
packages: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set RELEASE_VERSION env var | ||
run: | | ||
if [[ "${{ startsWith(inputs.ref, 'refs/tags/v')}}" == "true" ]]; then | ||
echo "RELEASE_VERSION=$(echo -n ${{ inputs.ref }} | cut -d '/' -f 3)" >> $GITHUB_ENV | ||
else | ||
echo "RELEASE_VERSION=$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD)" >> $GITHUB_ENV | ||
fi | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
path: _artifacts | ||
|
||
# Setup buildx to build multiarch image: https://github.com/docker/build-push-action/blob/master/docs/advanced/multi-platform.md | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: setup buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: login to GitHub container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Build and push node-installer image | ||
# TODO: remove once https://github.com/spinkube/runtime-class-manager handles this | ||
- name: untar musl artifacts into ./node-installer/.tmp/linux/(amd64|arm64) dir | ||
run: | | ||
mkdir -p ./node-installer/.tmp/linux/amd64 | ||
mkdir -p ./node-installer/.tmp/linux/arm64 | ||
for f in ./_artifacts/*/*-x86_64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/amd64; done | ||
for f in ./_artifacts/*/*-aarch64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/arm64; done | ||
- name: build and push node-installer image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
tags: | | ||
ghcr.io/${{ github.repository }}/node-installer:${{ env.RELEASE_VERSION }} | ||
context: node-installer | ||
platforms: linux/amd64,linux/arm64 | ||
|
||
- name: clear | ||
if: always() | ||
run: | | ||
rm -f ${HOME}/.docker/config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM busybox | ||
ARG TARGETPLATFORM | ||
COPY script/installer.sh /script/installer.sh | ||
COPY ./.tmp/${TARGETPLATFORM} /assets | ||
CMD sh /script/installer.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
SPIN_VERSION = v2 | ||
IMAGE_NAME ?= ghcr.io/spinkube/containerd-shim-spin/node-installer | ||
PLATFORM ?= linux/amd64 | ||
ARCH ?= x86_64 | ||
TARGET ?= $(ARCH)-unknown-linux-musl | ||
|
||
compile-musl: | ||
make build-spin-cross-$(TARGET) -C ../ | ||
|
||
move-musl-to-tmp: compile-musl | ||
mkdir -p ./.tmp | ||
cp ../../containerd-shim-spin/target/$(TARGET)/release/containerd-shim-spin-$(SPIN_VERSION) ./.tmp/ | ||
|
||
build-multi-installer-image: move-musl-to-tmp | ||
docker buildx build -t $(IMAGE_NAME) --platform linux/amd64,linux/arm64 . | ||
|
||
build-dev-installer-image: move-musl-to-tmp | ||
docker buildx build -t $(IMAGE_NAME) --load --platform $(PLATFORM) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This directory contains resources for a custom node-installer image | ||
intended to be used in conjunction with the [Kwasm Operator](https://github.com/KWasm/kwasm-operator). | ||
|
||
This version of the image only contains the containerd-shim-spin-v2 shim, as | ||
opposed to the default [kwasm-node-installer image](https://github.com/KWasm/kwasm-node-installer) | ||
which also bundles other shims. | ||
|
||
The intention is for the [spinkube/runtime-class-manager](https://github.com/spinkube/runtime-class-manager) | ||
project to handle this concern in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env sh | ||
set -euo pipefail | ||
|
||
# Based on https://github.com/KWasm/kwasm-node-installer/blob/main/script/installer.sh | ||
# Distilled to only configuring the Spin shim | ||
|
||
KWASM_DIR=/opt/kwasm | ||
|
||
CONTAINERD_CONF=/etc/containerd/config.toml | ||
IS_MICROK8S=false | ||
IS_K3S=false | ||
IS_RKE2_AGENT=false | ||
if ps aux | grep kubelet | grep -q snap/microk8s; then | ||
CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml | ||
IS_MICROK8S=true | ||
if nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- ls /var/snap/microk8s/current/args/containerd-template.toml > /dev/null 2>&1 ;then | ||
KWASM_DIR=/var/snap/microk8s/common/kwasm | ||
else | ||
echo "Installer seems to run on microk8s but 'containerd-template.toml' not found." | ||
exit 1 | ||
fi | ||
elif ls $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml > /dev/null 2>&1 ; then | ||
IS_RKE2_AGENT=true | ||
cp $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl | ||
CONTAINERD_CONF=/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl | ||
elif ls $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml > /dev/null 2>&1 ; then | ||
IS_K3S=true | ||
cp $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl | ||
CONTAINERD_CONF=/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl | ||
fi | ||
|
||
mkdir -p $NODE_ROOT$KWASM_DIR/bin/ | ||
|
||
cp /assets/containerd-shim-spin-v2 $NODE_ROOT$KWASM_DIR/bin/ | ||
|
||
if ! grep -q spin $NODE_ROOT$CONTAINERD_CONF; then | ||
echo ' | ||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] | ||
runtime_type = "'$KWASM_DIR'/bin/containerd-shim-spin-v2" | ||
' >> $NODE_ROOT$CONTAINERD_CONF | ||
rm -Rf $NODE_ROOT$KWASM_DIR/active | ||
fi | ||
|
||
if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then | ||
touch $NODE_ROOT$KWASM_DIR/active | ||
if $IS_MICROK8S; then | ||
nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd | ||
elif ls $NODE_ROOT/etc/init.d/containerd > /dev/null 2>&1 ; then | ||
nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/containerd restart | ||
elif ls $NODE_ROOT/etc/init.d/k3s > /dev/null 2>&1 ; then | ||
nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/k3s restart | ||
elif $IS_RKE2_AGENT; then | ||
nsenter --target 1 --mount --uts --ipc --net -- /bin/systemctl restart rke2-agent | ||
else | ||
nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd | ||
fi | ||
else | ||
echo "No change in containerd/config.toml" | ||
fi |