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

feat: Add Xen support #1240

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions .goreleaser-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ builds:
binary: #@ bin
main: #@ "./cmd/{}".format(bin)
env:
#@ if bin == "runu":
- CGO_ENABLED=1
#@ else:
- CGO_ENABLED=0
#@ end
- GOMOD=kraftkit.sh
goos:
- #@ os
Expand All @@ -186,9 +182,20 @@ builds:
- -X {{ .Env.GOMOD }}/internal/version.version={{ .Version }}
- -X {{ .Env.GOMOD }}/internal/version.commit={{ .Commit }}
- -X {{ .Env.GOMOD }}/internal/version.buildTime={{ .Date }}
#@ if bin == "kraft" and os == "linux":
- -linkmode external -extldflags "-static -lyajl -Wl,--whole-archive -llzma -lbz2 -lzstd -llzo2
-lxenguest -Wl,--no-whole-archive -lxenevtchn -lxenlight -lxenstore -lxenctrl
-lxenforeignmemory -lxenforeignmemory -lxencall -lxentoolcore -lxenhypfs
-lxendevicemodel -lxengnttab -lxentoollog -lz -lnl-route-3 -lnl-3 -luuid -lutil"
#@ else:
- -linkmode external -extldflags "-static"
#@
tags:
- containers_image_storage_stub
- containers_image_openpgp
#@ if bin == "kraft" and os == "linux":
- xen
#@ end
#@ end
#@ end
#@ end
Expand Down
15 changes: 11 additions & 4 deletions .goreleaser-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ builds:
binary: #@ bin
main: #@ "./cmd/{}".format(bin)
env:
#@ if bin == "runu":
- CGO_ENABLED=1
#@ else:
- CGO_ENABLED=0
#@ end
- GOMOD=kraftkit.sh
goos:
- #@ os
Expand All @@ -99,9 +95,20 @@ builds:
- -X {{ .Env.GOMOD }}/internal/version.version={{ .Version }}
- -X {{ .Env.GOMOD }}/internal/version.commit={{ .Commit }}
- -X {{ .Env.GOMOD }}/internal/version.buildTime={{ .Date }}
#@ if bin == "kraft" and os == "linux":
- -linkmode external -extldflags "-static -lyajl -Wl,--whole-archive -llzma -lbz2 -lzstd -llzo2
-lxenguest -Wl,--no-whole-archive -lxenevtchn -lxenlight -lxenstore -lxenctrl
-lxenforeignmemory -lxenforeignmemory -lxencall -lxentoolcore -lxenhypfs
-lxendevicemodel -lxengnttab -lxentoollog -lz -lnl-route-3 -lnl-3 -luuid -lutil"
#@ else:
- -linkmode external -extldflags "-static"
#@
tags:
- containers_image_storage_stub
- containers_image_openpgp
#@ if bin == "kraft" and os == "linux":
- xen
#@ end
#@ end
#@ end
#@ end
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,20 @@ $(addprefix $(.PROXY), $(BIN)): GO_GCFLAGS ?= -N -l
else
$(addprefix $(.PROXY), $(BIN)): GO_LDFLAGS ?= -s -w
endif

ifeq ($(XEN), y)
$(addprefix $.PROXY), $(BIN)): TAGS ?= xen,
endif
$(addprefix $(.PROXY), $(BIN)): TAGS += containers_image_storage_stub,containers_image_openpgp
$(addprefix $(.PROXY), $(BIN)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.version=$(VERSION)"
$(addprefix $(.PROXY), $(BIN)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.commit=$(GIT_SHA)"
$(addprefix $(.PROXY), $(BIN)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.buildTime=$(shell date)"
$(addprefix $(.PROXY), $(BIN)): tidy
$(addprefix $(.PROXY), $(BIN)):
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
$(GO) build \
-v \
-tags "containers_image_storage_stub,containers_image_openpgp" \
-tags '$(TAGS)' \
-buildmode=pie \
-gcflags=all='$(GO_GCFLAGS)' \
-ldflags='$(GO_LDFLAGS)' \
Expand All @@ -164,6 +168,10 @@ $(addprefix $(.PROXY), $(TOOLS)): GO_GCFLAGS ?= -N -l
else
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS ?= -s -w
endif
ifeq ($(XEN), y)
$(addprefix $.PROXY), $(TOOLS)): TAGS ?= xen,
endif
$(addprefix $(.PROXY), $(TOOLS)): TAGS += containers_image_storage_stub,containers_image_openpgp
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.version=$(VERSION)"
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.commit=$(GIT_SHA)"
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.buildTime=$(shell date)"
Expand Down Expand Up @@ -264,6 +272,7 @@ buildenv-myself-full: ## OCI image containing the build environment for KraftKit
buildenv-myself: ## OCI image containing KraftKit binaries.
buildenv-qemu: ## OCI image containing a Unikraft-centric build of QEMU.
buildenv-github-action: ## OCI image used when building Unikraft unikernels in GitHub Actions.
buildenv-xen: ## OCI image containing a Unikraft-centric build of Xen.
tools: ## Build all tools.
kraft: ## The kraft binary.
runu: ## The runu binary.
26 changes: 26 additions & 0 deletions buildenvs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ PLATFORM ?= linux/x86_64

WITH_CACHE ?= y

.PHONY: xen
xen: XEN_VERSION ?= 4.18
xen: MAKE_NPROC ?= $(shell nproc)
xen: ENVIRONMENT ?= xen
xen: IMAGE ?= $(REGISTRY)/xen:$(XEN_VERSION)
ifeq ($(WITH_CACHE),y)
xen: _WITH_CACHE := --cache-from $(IMAGE)
else
xen: _WITH_CACHE := --no-cache
endif
xen:
$(DOCKER) build \
--platform $(PLATFORM) \
--build-arg XEN_VERSION=$(XEN_VERSION) \
--build-arg MAKE_NPROC=$(MAKE_NPROC) \
--tag $(IMAGE) \
$(_WITH_CACHE) \
--file $(BUILDENVSDIR)/xen.Dockerfile \
$(DOCKER_BUILD_EXTRA) $(WORKDIR)

.PHONY: qemu
qemu: QEMU_VERSION ?= 8.2.4
qemu: MAKE_NPROC ?= $(shell nproc)
Expand All @@ -47,6 +67,7 @@ myself: GO_VERSION ?= 1.22.3
myself: ENVIRONMENT ?= myself
myself: IMAGE ?= $(REGISTRY)/myself:$(IMAGE_TAG)
myself: TARGET ?= kraftkit
myself: XEN_VERSION ?= 4.18
ifeq ($(WITH_CACHE),y)
myself: _WITH_CACHE := --cache-from $(IMAGE)
else
Expand All @@ -56,6 +77,7 @@ myself:
$(DOCKER) build \
--platform $(PLATFORM) \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg XEN_VERSION=$(XEN_VERSION) \
--tag $(IMAGE) \
--target $(TARGET) \
$(_WITH_CACHE) \
Expand All @@ -72,6 +94,7 @@ base: GO_VERSION ?= 1.22.3
base: IMAGE ?= $(REGISTRY)/base:$(IMAGE_TAG)
base: KRAFTKIT_VERSION ?= latest
base: QEMU_VERSION ?= 8.2.4
base: XEN_VERSION ?= 4.18
ifeq ($(WITH_CACHE),y)
base: _WITH_CACHE := --cache-from $(IMAGE)
else
Expand All @@ -82,6 +105,7 @@ base:
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg KRAFTKIT_VERSION=$(KRAFTKIT_VERSION) \
--build-arg QEMU_VERSION=$(QEMU_VERSION) \
--build-arg XEN_VERSION=$(XEN_VERSION) \
--build-arg REGISTRY=$(REGISTRY) \
--tag $(IMAGE) \
$(_WITH_CACHE) \
Expand All @@ -94,6 +118,7 @@ base-golang: GO_VERSION ?= 1.22.3
base-golang: IMAGE ?= $(REGISTRY)/base-golang:$(IMAGE_TAG)
base-golang: KRAFTKIT_VERSION ?= latest
base-golang: QEMU_VERSION ?= 8.2.4
base-golang: XEN_VERSION ?= 4.18
ifeq ($(WITH_CACHE),y)
base-golang: _WITH_CACHE := --cache-from $(IMAGE)
else
Expand All @@ -105,6 +130,7 @@ base-golang:
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg KRAFTKIT_VERSION=$(KRAFTKIT_VERSION) \
--build-arg QEMU_VERSION=$(QEMU_VERSION) \
--build-arg XEN_VERSION=$(XEN_VERSION) \
--build-arg REGISTRY=$(REGISTRY) \
--tag $(IMAGE) \
$(_WITH_CACHE) \
Expand Down
5 changes: 5 additions & 0 deletions buildenvs/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ ARG DEBIAN_VERSION=bookworm-20240513
ARG KRAFTKIT_VERSION=latest
ARG QEMU_VERSION=8.2.4
ARG REGISTRY=kraftkit.sh
ARG XEN_VERSION=4.18

FROM ${REGISTRY}/qemu:${QEMU_VERSION} AS qemu
FROM ${REGISTRY}/xen:${XEN_VERSION} AS xen
FROM ${REGISTRY}/myself:${KRAFTKIT_VERSION} AS kraftkit
FROM debian:${DEBIAN_VERSION} AS base

COPY --from=qemu /bin/ /usr/local/bin
COPY --from=qemu /share/qemu/ /share/qemu
COPY --from=qemu /lib/x86_64-linux-gnu/ /lib/x86_64-linux-gnu
COPY --from=kraftkit /kraft /usr/local/bin
COPY --from=xen /usr/lib/x86_64-linux-gnu/*.a /lib/x86_64-linux-gnu
COPY --from=xen /usr/local/lib/libxen*.a /usr/local/lib/libxen*.so* /usr/local/lib
COPY --from=xen /usr/local/include/* /usr/local/include

# Install unikraft dependencies
RUN set -xe; \
Expand Down
21 changes: 19 additions & 2 deletions buildenvs/myself.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# You may not use this file except in compliance with the License.

ARG GO_VERSION=1.22.3
ARG XEN_VERSION=4.18
ARG REGISTRY=kraftkit.sh

FROM golang:${GO_VERSION}-bookworm AS kraftkit-full
FROM ${REGISTRY}/xen:${XEN_VERSION} AS xen
FROM golang:${GO_VERSION}-bookworm AS kraftkit-full

# Install build dependencies
RUN set -xe; \
Expand All @@ -32,6 +35,20 @@ RUN set -xe; \
mv cosign-linux-amd64 /usr/local/bin/cosign; \
chmod +x /usr/local/bin/cosign;

COPY --from=xen /usr/local/lib/libxen*.a /usr/local/lib/libxen*.so* /usr/local/lib
COPY --from=xen /usr/local/include/* /usr/local/include/
COPY --from=xen /usr/lib/x86_64-linux-gnu/liblzma.a \
/usr/lib/x86_64-linux-gnu/libbz2.a \
/usr/lib/x86_64-linux-gnu/libzstd.a \
/usr/lib/x86_64-linux-gnu/liblzo2.a \
/usr/lib/x86_64-linux-gnu/libyajl.a \
/usr/lib/x86_64-linux-gnu/libz.a \
/usr/lib/x86_64-linux-gnu/libnl-route-3.a \
/usr/lib/x86_64-linux-gnu/libnl-3.a \
/usr/lib/x86_64-linux-gnu/libuuid.a \
/usr/lib/x86_64-linux-gnu/libutil.a \
/usr/lib/x86_64-linux-gnu

WORKDIR /go/src/kraftkit.sh

COPY --from=ghcr.io/goreleaser/goreleaser-cross:v1.22.3 /usr/bin/goreleaser /usr/bin/
Expand All @@ -56,4 +73,4 @@ FROM scratch AS kraftkit

COPY --from=kraftkit-build /go/src/kraftkit.sh/dist/kraft /kraft

ENTRYPOINT [ "/kraft" ]
ENTRYPOINT [ "/kraft" ]
76 changes: 76 additions & 0 deletions buildenvs/xen.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024, Unikraft GmbH and The KraftKit Authors.
# Licensed under the BSD-3-Clause License (the "License").
# You may not use this file except in compliance with the License.

ARG DEBIAN_VERSION=bookworm-20240513

FROM debian:${DEBIAN_VERSION} AS xenbuild

ARG XEN_VERSION=4.18
ARG MAKE_NPROC=1

# The sed line should stay here until [1] is merged or forever if it's not
# [1]: https://lists.xenproject.org/archives/html/xen-devel/2024-07/msg00295.html

RUN set -xe; \
apt-get update; \
apt-get install -y \
binutils \
bison \
build-essential \
cmake \
flex \
gcc \
git \
iasl \
libbz2-dev \
libglib2.0-dev \
liblzo2-dev \
liblz-dev \
liblzma-dev \
libnl-3-dev \
libnl-route-3-dev \
libncurses5-dev \
libpixman-1-dev \
libslirp-dev \
libssh2-1-dev \
libssl-dev \
libuuid1 \
libyajl-dev \
libz3-dev \
libzstd-dev \
make \
ninja-build \
perl \
pkg-config \
python3 \
python3-pip \
python3-setuptools \
python3-wheel \
uuid-dev; \
pip3 install python-config --break-system-packages; \
git clone -b stable-${XEN_VERSION} https://xenbits.xen.org/git-http/xen.git /xen; \
sed '/xs.opic: CFLAGS += -DUSE_PTHREAD/a xs.o: CFLAGS += -DUSE_PTHREAD' /xen/tools/libs/store/Makefile; \
cd /xen; \
./configure --enable-virtfs; \
make -j ${MAKE_NPROC} build-tools; \
make -j ${MAKE_NPROC} install-tools; \
cp /usr/lib/x86_64-linux-gnu/libyajl_s.a /usr/lib/x86_64-linux-gnu/libyajl.a

FROM scratch AS xen

COPY --from=xenbuild /usr/lib/x86_64-linux-gnu/liblzma.a \
/usr/lib/x86_64-linux-gnu/libbz2.a \
/usr/lib/x86_64-linux-gnu/libzstd.a \
/usr/lib/x86_64-linux-gnu/liblzo2.a \
/usr/lib/x86_64-linux-gnu/libyajl.a \
/usr/lib/x86_64-linux-gnu/libz.a \
/usr/lib/x86_64-linux-gnu/libnl-route-3.a \
/usr/lib/x86_64-linux-gnu/libnl-3.a \
/usr/lib/x86_64-linux-gnu/libuuid.a \
/usr/lib/x86_64-linux-gnu/libutil.a \
/usr/lib/x86_64-linux-gnu/
COPY --from=xenbuild /usr/local/lib/libxen*.a /usr/local/lib/
COPY --from=xenbuild /usr/local/lib/libxen*.so* /usr/local/lib/
COPY --from=xenbuild /usr/local/include/*.h /usr/local/include/
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ require (
oras.land/oras-go/v2 v2.5.0
sdk.kraft.cloud v0.5.10-0.20240627124920-7a485e75d7b4
sigs.k8s.io/kustomize/kyaml v0.17.1
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1800,3 +1800,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2 h1:f3OAMM0NgzlqWqZnuTIz6B6HPK1pGGfgKH6S94kYEWY=
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2/go.mod h1:tbZ4iMnk8RWkXPxTiCGdAw3hCOa3feShlf3sBh50uIc=
4 changes: 3 additions & 1 deletion internal/cli/kraft/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (opts *LogOptions) Run(ctx context.Context, args []string) error {
if err != nil {
errGroup = append(errGroup, err)
}
if opts.Follow && machine.Status.State == machineapi.MachineStateRunning {

// Sometimes the kernel can boot and exit faster than we can start tailing the logs
if opts.Follow && (machine.Status.State == machineapi.MachineStateRunning || machine.Status.State == machineapi.MachineStateExited) {
andreistan26 marked this conversation as resolved.
Show resolved Hide resolved
observations.Add(machine)
go func(machine *machineapi.Machine) {
defer func() {
Expand Down
6 changes: 5 additions & 1 deletion internal/logtail/logtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func NewLogTail(ctx context.Context, logFile string) (chan string, chan error, e

switch event.Op {
case fsnotify.Write:
peekAndRead(f, reader, &logs, &errs)
for {
if peekAndRead(f, reader, &logs, &errs) {
break
}
}
Comment on lines +67 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can get multi-line writes with one event triggered.
IMO something better would be for peekAndRead to look ahead for the last newline so we end up with a single write.

}
}
}
Expand Down
Loading
Loading