Skip to content

Commit

Permalink
vm-builder: vm-builder builds arch images
Browse files Browse the repository at this point in the history
Add arm support to vm-builder without cross-compilation
  • Loading branch information
mikhail-sakhnov committed Oct 21, 2024
1 parent e360666 commit 68661df
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GOOS ?= $(shell go env GOOS)
# The target architecture for linux kernel. Possible values: amd64 or arm64.
# Any other supported by linux kernel architecture could be added by introducing new build step into neonvm/hack/kernel/Dockerfile.kernel-builder
KERNEL_TARGET_ARCH ?= amd64

TARGET_ARCH ?= amd64
# Get the currently used golang base path
GOPATH=$(shell go env GOPATH)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -184,6 +184,7 @@ docker-build-controller: docker-build-go-base ## Build docker image for NeonVM c
docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runner
docker build \
--tag $(IMG_RUNNER) \
--build-arg TARGET_ARCH=$(TARGET_ARCH) \
--build-arg GO_BASE_IMG=$(GO_BASE_IMG) \
--file neonvm-runner/Dockerfile \
.
Expand All @@ -192,6 +193,7 @@ docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runne
docker-build-daemon: ## Build docker image for NeonVM daemon.
docker build \
--tag $(IMG_DAEMON) \
--build-arg TARGET_ARCH=$(TARGET_ARCH) \
--file neonvm-daemon/Dockerfile \
.

Expand Down Expand Up @@ -223,11 +225,11 @@ docker-build-scheduler: docker-build-go-base ## Build docker image for (autoscal

.PHONY: docker-build-examples
docker-build-examples: bin/vm-builder ## Build docker images for testing VMs
./bin/vm-builder -src postgres:15-bullseye -dst $(E2E_TESTS_VM_IMG) -spec tests/e2e/image-spec.yaml
./bin/vm-builder -src postgres:15-bullseye -dst $(E2E_TESTS_VM_IMG) -spec tests/e2e/image-spec.yaml -target-arch linux/$(TARGET_ARCH)

.PHONY: docker-build-pg16-disk-test
docker-build-pg16-disk-test: bin/vm-builder ## Build a VM image for testing
./bin/vm-builder -src alpine:3.19 -dst $(PG16_DISK_TEST_IMG) -spec vm-examples/pg16-disk-test/image-spec.yaml
./bin/vm-builder -src alpine:3.19 -dst $(PG16_DISK_TEST_IMG) -spec vm-examples/pg16-disk-test/image-spec.yaml -target-arch linux/$(TARGET_ARCH)

#.PHONY: docker-push
#docker-push: ## Push docker image with the controller.
Expand Down Expand Up @@ -389,6 +391,10 @@ load-example-vms: check-local-context kubectl kind k3d ## Load the testing VM im
.PHONY: example-vms
example-vms: docker-build-examples load-example-vms ## Build and push the testing VM images to the kind/k3d cluster.

.PHONY: example-vms-arm64
example-vms-arm64: TARGET_ARCH=arm64
example-vms-arm64: example-vms

.PHONY: load-pg16-disk-test
load-pg16-disk-test: check-local-context kubectl kind k3d ## Load the pg16-disk-test VM image to the kind/k3d cluster.
@if [ $$($(KUBECTL) config current-context) = k3d-$(CLUSTER_NAME) ]; then $(K3D) image import $(PG16_DISK_TEST_IMG) --cluster $(CLUSTER_NAME) --mode direct; fi
Expand Down Expand Up @@ -487,8 +493,14 @@ CODE_GENERATOR_VERSION ?= v0.28.12

KUTTL ?= $(LOCALBIN)/kuttl
# k8s deps @ 1.28.3
KUTTL_VERSION ?= v0.16.0

KUTTL_VERSION ?= v0.19.0
ifeq ($(GOARCH), arm64)
KUTTL_ARCH = arm64
else ifeq ($(GOARCH), amd64)
KUTTL_ARCH = x86_64
else
$(error Unsupported architecture: $(GOARCH))
endif
KUBECTL ?= $(LOCALBIN)/kubectl
KUBECTL_VERSION ?= v1.28.12

Expand Down Expand Up @@ -530,7 +542,7 @@ $(KUBECTL): $(LOCALBIN)
.PHONY: kuttl
kuttl: $(KUTTL) ## Download kuttl locally if necessary.
$(KUTTL): $(LOCALBIN)
@test -s $(LOCALBIN)/kuttl || { curl -sfSLo $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/$(KUTTL_VERSION)/kubectl-kuttl_$(subst v,,$(KUTTL_VERSION))_$(GOOS)_$(shell uname -m) && chmod +x $(KUTTL); }
test -s $(LOCALBIN)/kuttl || { curl -sfSLo $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/$(KUTTL_VERSION)/kubectl-kuttl_$(subst v,,$(KUTTL_VERSION))_$(GOOS)_$(KUTTL_ARCH) && chmod +x $(KUTTL); }

.PHONY: k3d
k3d: $(K3D) ## Download k3d locally if necessary.
Expand Down
21 changes: 13 additions & 8 deletions vm-builder/files/Dockerfile.img
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ USER root

FROM {{.NeonvmDaemonImage}} AS neonvm-daemon-loader

FROM busybox:1.35.0-musl AS busybox-loader

FROM alpine:3.19 AS vm-runtime
ARG TARGET_ARCH
RUN set -e && mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config
# add busybox
ENV BUSYBOX_VERSION 1.35.0
COPY --from=busybox-loader /bin/busybox /neonvm/bin/busybox

RUN set -e \
&& mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config \
&& wget -q https://busybox.net/downloads/binaries/${BUSYBOX_VERSION}-x86_64-linux-musl/busybox -O /neonvm/bin/busybox \
&& chmod +x /neonvm/bin/busybox \
&& /neonvm/bin/busybox --install -s /neonvm/bin
chmod +x /neonvm/bin/busybox \
&& /neonvm/bin/busybox --install -s /neonvm/bin

COPY helper.move-bins.sh /helper.move-bins.sh
COPY helper.move-bins.sh /helper.move-bins.sh

# add udevd and agetty (with shared libs)
RUN set -e \
Expand Down Expand Up @@ -49,8 +52,10 @@ RUN set -e \

# Install vector.dev binary
RUN set -e \
&& wget https://packages.timber.io/vector/0.26.0/vector-0.26.0-x86_64-unknown-linux-musl.tar.gz -O - \
| tar xzvf - --strip-components 3 -C /neonvm/bin/ ./vector-x86_64-unknown-linux-musl/bin/vector
&& ARCH=$( [ "$TARGET_ARCH" = "linux/arm64" ] && echo "aarch64" || echo "x86_64") \
&& wget https://packages.timber.io/vector/0.26.0/vector-${ARCH}-unknown-linux-musl.tar.gz -O - \
| tar xzvf - --strip-components 3 -C /neonvm/bin/ ./vector-${ARCH}-unknown-linux-musl/bin/vector


# chrony
RUN set -e \
Expand Down
2 changes: 1 addition & 1 deletion vm-builder/files/inittab
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
{{ range .InittabCommands }}
::{{.SysvInitAction}}:su -p {{.CommandUser}} -c {{.ShellEscapedCommand}}
{{ end }}
ttyS0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyS0 linux
ttyAMA0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyAMA0 linux
::shutdown:/neonvm/bin/vmshutdown
5 changes: 3 additions & 2 deletions vm-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var (
version = flag.Bool("version", false, `Print vm-builder version`)

daemonImageFlag = flag.String("daemon-image", "", `Specify the neonvm-daemon image: --daemon-image=neonvm-daemon:dev`)
targetArch = flag.String("target-arch", "linux/amd64", `Target architecture: --arch linux/amd64`)
)

func AddTemplatedFileToTar(tw *tar.Writer, tmplArgs any, filename string, tmplString string) error {
Expand All @@ -84,7 +85,6 @@ func AddTemplatedFileToTar(tw *tar.Writer, tmplArgs any, filename string, tmplSt
if err = tmpl.Execute(&buf, tmplArgs); err != nil {
return fmt.Errorf("failed to execute template for %q: %w", filename, err)
}

return addFileToTar(tw, filename, buf.Bytes())
}

Expand Down Expand Up @@ -129,7 +129,6 @@ type inittabCommand struct {
func main() {
flag.Parse()
var dstIm string

if *version {
fmt.Println(Version)
os.Exit(0)
Expand Down Expand Up @@ -366,6 +365,7 @@ func main() {

buildArgs := make(map[string]*string)
buildArgs["DISK_SIZE"] = size
buildArgs["TARGET_ARCH"] = targetArch
opt := types.ImageBuildOptions{
AuthConfigs: authConfigs,
Tags: []string{dstIm},
Expand All @@ -376,6 +376,7 @@ func main() {
Dockerfile: "Dockerfile",
Remove: true,
ForceRemove: true,
Platform: *targetArch,
}
buildResp, err := cli.ImageBuild(ctx, tarBuffer, opt)
if err != nil {
Expand Down

0 comments on commit 68661df

Please sign in to comment.