Skip to content

Commit f871d05

Browse files
vm-builder: vm-builder builds arch images
Add arm support to vm-builder without cross-compilation
1 parent f63fdc9 commit f871d05

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

Makefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ GOOS ?= $(shell go env GOOS)
2020
# The target architecture for linux kernel. Possible values: amd64 or arm64.
2121
# Any other supported by linux kernel architecture could be added by introducing new build step into neonvm/hack/kernel/Dockerfile.kernel-builder
2222
KERNEL_TARGET_ARCH ?= amd64
23-
23+
TARGET_ARCH ?= amd64
2424
# Get the currently used golang base path
2525
GOPATH=$(shell go env GOPATH)
2626
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
@@ -184,6 +184,7 @@ docker-build-controller: docker-build-go-base ## Build docker image for NeonVM c
184184
docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runner
185185
docker build \
186186
--tag $(IMG_RUNNER) \
187+
--build-arg TARGET_ARCH=$(TARGET_ARCH) \
187188
--build-arg GO_BASE_IMG=$(GO_BASE_IMG) \
188189
--file neonvm-runner/Dockerfile \
189190
.
@@ -192,6 +193,7 @@ docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runne
192193
docker-build-daemon: ## Build docker image for NeonVM daemon.
193194
docker build \
194195
--tag $(IMG_DAEMON) \
196+
--build-arg TARGET_ARCH=$(TARGET_ARCH) \
195197
--file neonvm-daemon/Dockerfile \
196198
.
197199

@@ -223,7 +225,7 @@ docker-build-scheduler: docker-build-go-base ## Build docker image for (autoscal
223225

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

228230
.PHONY: docker-build-pg16-disk-test
229231
docker-build-pg16-disk-test: bin/vm-builder ## Build a VM image for testing
@@ -487,8 +489,14 @@ CODE_GENERATOR_VERSION ?= v0.28.12
487489

488490
KUTTL ?= $(LOCALBIN)/kuttl
489491
# k8s deps @ 1.28.3
490-
KUTTL_VERSION ?= v0.16.0
491-
492+
KUTTL_VERSION ?= v0.19.0
493+
ifeq ($(GOARCH), arm64)
494+
KUTTL_ARCH = arm64
495+
else ifeq ($(GOARCH), amd64)
496+
KUTTL_ARCH = x86_64
497+
else
498+
$(error Unsupported architecture: $(GOARCH))
499+
endif
492500
KUBECTL ?= $(LOCALBIN)/kubectl
493501
KUBECTL_VERSION ?= v1.28.12
494502

@@ -530,7 +538,7 @@ $(KUBECTL): $(LOCALBIN)
530538
.PHONY: kuttl
531539
kuttl: $(KUTTL) ## Download kuttl locally if necessary.
532540
$(KUTTL): $(LOCALBIN)
533-
@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); }
541+
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); }
534542

535543
.PHONY: k3d
536544
k3d: $(K3D) ## Download k3d locally if necessary.

vm-builder/files/Dockerfile.img

+13-8
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ USER root
99

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

12+
FROM busybox:1.35.0-musl AS busybox-loader
13+
1214
FROM alpine:3.19 AS vm-runtime
15+
ARG TARGET_ARCH
16+
RUN set -e && mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config
1317
# add busybox
14-
ENV BUSYBOX_VERSION 1.35.0
18+
COPY --from=busybox-loader /bin/busybox /neonvm/bin/busybox
19+
1520
RUN set -e \
16-
&& mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config \
17-
&& wget -q https://busybox.net/downloads/binaries/${BUSYBOX_VERSION}-x86_64-linux-musl/busybox -O /neonvm/bin/busybox \
18-
&& chmod +x /neonvm/bin/busybox \
19-
&& /neonvm/bin/busybox --install -s /neonvm/bin
21+
chmod +x /neonvm/bin/busybox \
22+
&& /neonvm/bin/busybox --install -s /neonvm/bin
2023

21-
COPY helper.move-bins.sh /helper.move-bins.sh
24+
COPY helper.move-bins.sh /helper.move-bins.sh
2225

2326
# add udevd and agetty (with shared libs)
2427
RUN set -e \
@@ -49,8 +52,10 @@ RUN set -e \
4952

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

5560
# chrony
5661
RUN set -e \

vm-builder/files/inittab

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
{{ range .InittabCommands }}
1313
::{{.SysvInitAction}}:su -p {{.CommandUser}} -c {{.ShellEscapedCommand}}
1414
{{ end }}
15-
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
15+
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
1616
::shutdown:/neonvm/bin/vmshutdown

vm-builder/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var (
7272
version = flag.Bool("version", false, `Print vm-builder version`)
7373

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

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

@@ -129,7 +129,6 @@ type inittabCommand struct {
129129
func main() {
130130
flag.Parse()
131131
var dstIm string
132-
133132
if *version {
134133
fmt.Println(Version)
135134
os.Exit(0)
@@ -366,6 +365,7 @@ func main() {
366365

367366
buildArgs := make(map[string]*string)
368367
buildArgs["DISK_SIZE"] = size
368+
buildArgs["TARGET_ARCH"] = targetArch
369369
opt := types.ImageBuildOptions{
370370
AuthConfigs: authConfigs,
371371
Tags: []string{dstIm},
@@ -376,6 +376,7 @@ func main() {
376376
Dockerfile: "Dockerfile",
377377
Remove: true,
378378
ForceRemove: true,
379+
Platform: *targetArch,
379380
}
380381
buildResp, err := cli.ImageBuild(ctx, tarBuffer, opt)
381382
if err != nil {

vm-deploy.yaml

+38-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,34 @@ metadata:
55
name: postgres16-disk-test
66
annotations:
77
# In this example, these bounds aren't necessary. So... here's what they look like :)
8-
autoscaling.neon.tech/bounds: '{ "min": { "cpu": 0.25, "mem": "1Gi" }, "max": { "cpu": 1.25, "mem": "5Gi" } }'
8+
autoscaling.neon.tech/bounds: '{ "min": { "cpu": 0.25, "mem": "1Gi" }, "max": { "cpu": 3, "mem": "5Gi" } }'
99
labels:
1010
autoscaling.neon.tech/enabled: "true"
1111
# Set to "true" to continuously migrate the VM (TESTING ONLY)
1212
autoscaling.neon.tech/testing-only-always-migrate: "false"
1313
spec:
14+
cpuScalingMode: sysfsScaling
15+
terminationGracePeriodSeconds: 300
16+
affinity:
17+
nodeAffinity:
18+
requiredDuringSchedulingIgnoredDuringExecution:
19+
nodeSelectorTerms:
20+
- matchExpressions:
21+
- key: kubernetes.io/arch
22+
operator: In
23+
values:
24+
- amd64
25+
- arm64
26+
- ppc64le
27+
- s390x
28+
- key: kubernetes.io/os
29+
operator: In
30+
values:
31+
- linux
1432
schedulerName: autoscale-scheduler
1533
enableSSH: true
1634
guest:
17-
cpus: { min: 0.25, use: 0.25, max: 3 }
35+
cpus: { min: 1, use: 1, max: 3}
1836
memorySlotSize: 1Gi
1937
memorySlots: { min: 1, use: 1, max: 5 }
2038
rootDisk:
@@ -26,3 +44,21 @@ spec:
2644
- port: 10301 # monitor
2745
settings:
2846
swap: 1Gi
47+
extraNetwork:
48+
enable: true
49+
disks:
50+
- name: pgdata
51+
mountPath: /var/lib/postgresql
52+
emptyDisk:
53+
size: 16Gi
54+
- name: postgres-config
55+
mountPath: /etc/postgresql
56+
configMap:
57+
name: example-config
58+
items:
59+
- key: postgresql.conf
60+
path: postgresql.conf
61+
- name: cache
62+
mountPath: /neonvm/cache
63+
tmpfs:
64+
size: 1Gi

0 commit comments

Comments
 (0)