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

Add basic support for RISC-V 64bit architecture #1856

Merged
merged 2 commits into from
Nov 27, 2023
Merged
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
11 changes: 5 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ builds:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X github.com/rancher/elemental-cli/internal/version.version={{.Tag}}
- -X github.com/rancher/elemental-cli/internal/version.gitCommit={{.Commit}}
- -X github.com/rancher/elemental-toolkit/internal/version.version={{.Tag}}
- -X github.com/rancher/elemental-toolkit/internal/version.gitCommit={{.Commit}}
goos:
- linux
goarch:
- amd64
- arm
- arm64
- riscv64
goarm:
- 6
- 7
- 8
signs:
- cmd: cosign
signature: "${artifact}.sig"
Expand Down Expand Up @@ -43,4 +42,4 @@ changelog:
exclude:
- '^docs:'
- '^test:'
- '^Merge pull request'
- '^Merge pull request'
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ARG BASE_OS_IMAGE=opensuse/leap
ARG BASE_OS_VERSION=15.5
ARG GO_VERSION=1.20
ARG LEAP_VERSION=15.5

FROM golang:${GO_VERSION}-alpine as elemental-bin
ldevulder marked this conversation as resolved.
Show resolved Hide resolved
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS elemental-bin

ENV CGO_ENABLED=0
WORKDIR /src/
Expand All @@ -21,25 +22,25 @@ ARG ELEMENTAL_VERSION=0.0.1
ARG ELEMENTAL_COMMIT=""
ENV ELEMENTAL_VERSION=${ELEMENTAL_VERSION}
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}
RUN go build \
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags "-w -s \
-X github.com/rancher/elemental-toolkit/internal/version.version=$ELEMENTAL_VERSION \
-X github.com/rancher/elemental-toolkit/internal/version.gitCommit=$ELEMENTAL_COMMIT" \
-X github.com/rancher/elemental-toolkit/internal/version.version=${ELEMENTAL_VERSION} \
-X github.com/rancher/elemental-toolkit/internal/version.gitCommit=${ELEMENTAL_COMMIT}" \
-o /usr/bin/elemental

FROM opensuse/leap:$LEAP_VERSION AS elemental
FROM ${BASE_OS_IMAGE}:${BASE_OS_VERSION} AS elemental-toolkit
# This helps invalidate the cache on each build so the following steps are really run again getting the latest packages
# versions, as long as the elemental commit has changed
ARG ELEMENTAL_COMMIT=""
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}

RUN ARCH=$(uname -m); \
ldevulder marked this conversation as resolved.
Show resolved Hide resolved
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
zypper --non-interactive removerepo repo-update || true; \
zypper install -y --no-recommends xfsprogs \
parted \
util-linux-systemd \
e2fsprogs \
util-linux \
udev \
rsync \
grub2 \
Expand All @@ -52,10 +53,12 @@ RUN ARCH=$(uname -m); \
gptfdisk \
lvm2

# Copy the built CLI
COPY --from=elemental-bin /usr/bin/elemental /usr/bin/elemental

# Fix for blkid only using udev on opensuse
RUN echo "EVALUATE=scan" >> /etc/blkid.conf

ENTRYPOINT ["/usr/bin/elemental"]

# Add to /system/oem folder so install/upgrade/reset hooks will run when running this container.
Expand Down
51 changes: 32 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ PACKER_TARGET?=qemu.elemental-${ARCH}
REPO?=local/elemental-$(FLAVOR)
TOOLKIT_REPO?=local/elemental-toolkit
DOCKER?=docker

GIT_COMMIT ?= $(shell git rev-parse HEAD)
GIT_COMMIT_SHORT ?= $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
VERSION ?= ${GIT_TAG}-g${GIT_COMMIT_SHORT}

PKG := ./cmd ./pkg/...
LDFLAGS := -w -s
LDFLAGS += -X "github.com/rancher/elemental-toolkit/internal/version.version=${GIT_TAG}"
LDFLAGS += -X "github.com/rancher/elemental-toolkit/internal/version.gitCommit=${GIT_COMMIT}"
BASE_OS_IMAGE?=opensuse/leap
BASE_OS_VERSION?=15.5

GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
VERSION?=${GIT_TAG}-g${GIT_COMMIT_SHORT}

PKG:=./cmd ./pkg/...
LDFLAGS:=-w -s
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/internal/version.version=${GIT_TAG}"
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/internal/version.gitCommit=${GIT_COMMIT}"

# For RISC-V 64bit support
ifeq ($(PLATFORM),linux/riscv64)
BASE_OS_IMAGE=registry.opensuse.org/opensuse/factory/riscv/images/opensuse/tumbleweed
BASE_OS_VERSION=latest
endif

# default target
.PHONY: all
Expand All @@ -35,7 +43,12 @@ include make/Makefile.test

.PHONY: build
build:
$(DOCKER) build --platform ${PLATFORM} ${DOCKER_ARGS} --build-arg ELEMENTAL_VERSION=${GIT_TAG} --build-arg ELEMENTAL_COMMIT=${GIT_COMMIT} --target elemental -t ${TOOLKIT_REPO}:${VERSION} .
$(DOCKER) build --platform $(PLATFORM) ${DOCKER_ARGS} \
--build-arg ELEMENTAL_VERSION=${GIT_TAG} \
--build-arg ELEMENTAL_COMMIT=${GIT_COMMIT} \
--build-arg BASE_OS_IMAGE=$(BASE_OS_IMAGE) \
--build-arg BASE_OS_VERSION=$(BASE_OS_VERSION) \
--target elemental-toolkit -t $(TOOLKIT_REPO):$(VERSION) .

.PHONY: push-toolkit
push-toolkit:
Expand All @@ -47,7 +60,11 @@ build-cli:

.PHONY: build-os
build-os: build
$(DOCKER) build examples/$(FLAVOR) --platform ${PLATFORM} ${DOCKER_ARGS} --build-arg TOOLKIT_REPO=$(TOOLKIT_REPO) --build-arg VERSION=$(VERSION) --build-arg REPO=$(REPO) -t $(REPO):$(VERSION)
$(DOCKER) build --platform ${PLATFORM} ${DOCKER_ARGS} \
--build-arg TOOLKIT_REPO=$(TOOLKIT_REPO) \
--build-arg VERSION=$(VERSION) \
--build-arg REPO=$(REPO) -t $(REPO):$(VERSION) \
examples/$(FLAVOR)

.PHONY: push-os
push-os:
Expand All @@ -61,10 +78,6 @@ build-iso: build-os
--entrypoint /usr/bin/elemental ${TOOLKIT_REPO}:${VERSION} --debug build-iso --bootloader-in-rootfs -n elemental-$(FLAVOR).$(ARCH) \
--local --platform $(PLATFORM) --squash-no-compression -o /build $(REPO):$(VERSION)

.PHONY: clean-iso
clean-iso: build-os
$(DOCKER) run --rm -v $(ROOT_DIR)/build:/build --entrypoint /bin/bash $(REPO):$(VERSION) -c "rm -v /build/*.iso /build/*.iso.sha256 || true"

.PHONY: build-disk
build-disk: build-os
@echo Building ${ARCH} disk
Expand All @@ -77,9 +90,9 @@ build-disk: build-os
qemu-img convert -O qcow2 $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).img $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2
qemu-img resize $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2 $(DISKSIZE)

.PHONY: clean-disk
clean-disk:
rm $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).{raw,img,qcow2}
.PHONY: clean
clean:
rm -fv $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).{raw,img,qcow2,iso,iso.sha256}

.PHONY: vet
vet:
Expand Down
11 changes: 5 additions & 6 deletions examples/green/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# run `make build` to build local/elemental-toolkit image
ARG TOOLKIT_REPO
ARG VERSION
FROM ${TOOLKIT_REPO}:${VERSION} as TOOLKIT
FROM ${TOOLKIT_REPO}:${VERSION} AS TOOLKIT

# OS base image of our choice
FROM opensuse/leap:15.5 as OS
FROM opensuse/leap:15.5 AS OS
ARG REPO
ARG VERSION
ENV VERSION=${VERSION}

# install kernel, systemd, dracut, grub2 and other required tools
RUN ARCH=$(uname -m); \
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
zypper --non-interactive install --no-recommends -- \
kernel-default \
device-mapper \
Expand Down Expand Up @@ -42,6 +42,7 @@ RUN ARCH=$(uname -m); \
less \
sudo \
curl \
iproute2 \
sed

# Just add the elemental cli
Expand All @@ -55,7 +56,7 @@ RUN cp /usr/share/systemd/tmp.mount /etc/systemd/system

# Generate initrd with required elemental services
RUN elemental init -f && \
kernel=$(ls /boot/Image-* | head -n1) && \
kernel=$(ls /boot/Image-* 2>/dev/null | head -n1) && \
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi && \
rm -rf /var/log/update* && \
>/var/log/lastlog && \
Expand All @@ -70,5 +71,3 @@ RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \

# Good for validation after the build
CMD /bin/bash


42 changes: 32 additions & 10 deletions examples/tumbleweed/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
# run `make build` to build local/elemental-toolkit image
ARG TOOLKIT_REPO
ARG VERSION
FROM ${TOOLKIT_REPO}:${VERSION} as TOOLKIT
ARG OS_IMAGE=opensuse/tumbleweed
ARG OS_VERSION=latest

FROM ${TOOLKIT_REPO}:${VERSION} AS TOOLKIT

# OS base image of our choice
FROM opensuse/tumbleweed:latest as OS
FROM ${OS_IMAGE}:${OS_VERSION} AS OS
ARG REPO
ARG VERSION
ENV REPO=${REPO}
ENV VERSION=${VERSION}

# install kernel, systemd, dracut, grub2 and other required tools
# Workaround for RISC-V, specific kernel might be needed for some boards
ARG ADD_REPO
ENV ADD_REPO=${ADD_REPO}

# Install kernel, systemd, dracut, grub2 and other required tools
RUN ARCH=$(uname -m); \
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
zypper --non-interactive install --no-recommends -- \
zypper --non-interactive removerepo repo-update || true; \
if [[ -n "${ADD_REPO}" ]]; then \
zypper --non-interactive addrepo --enable --refresh ${ADD_REPO} added-repo; \
fi; \
if [[ "${ARCH}" != "riscv64" ]]; then \
ADD_PKGS+=" shim"; \
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
fi; \
zypper --non-interactive --gpg-auto-import-keys install --no-recommends -- \
kernel-default \
device-mapper \
dracut \
grub2 \
grub2-${ARCH}-efi \
shim \
haveged \
systemd \
NetworkManager \
Expand All @@ -42,7 +56,10 @@ RUN ARCH=$(uname -m); \
less \
sudo \
curl \
sed
sed \
patch \
iproute2 \
${ADD_PKGS}

# Just add the elemental cli
COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
Expand All @@ -53,9 +70,16 @@ RUN systemctl enable NetworkManager.service
# This is for automatic testing purposes, do not do this in production.
RUN echo "PermitRootLogin yes" > /etc/ssh/sshd_config.d/rootlogin.conf

# This is patches are fix upstream dracut, see https://github.com/dracutdevs/dracut/pull/2525
ADD patches /
RUN cd /usr/lib/dracut && \
patch -p 1 -f -i /0001-fix-dmsquash-live-restore-compatibility-with-earlier.patch && \
patch -p 1 -f -i /0001-fix-overlayfs-split-overlayfs-mount-in-two-steps.patch && \
rm /*.patch

# Generate initrd with required elemental services
RUN elemental init -f && \
kernel=$(ls /boot/Image-* | head -n1) && \
kernel=$(ls /boot/Image-* 2>/dev/null | head -n1) && \
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi && \
rm -rf /var/log/update* && \
>/var/log/lastlog && \
Expand All @@ -70,5 +94,3 @@ RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \

# Good for validation after the build
CMD /bin/bash


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 0e780720efe6488c4e07af39926575ee12f40339 Mon Sep 17 00:00:00 2001
From: Laszlo Gombos <[email protected]>
Date: Fri, 24 Feb 2023 01:57:19 +0000
Subject: [PATCH] fix(dmsquash-live): restore compatibility with earlier
releases

Follow-up to 40dd5c90e0efcb9ebaa9abb42a38c7316e9706bd .
---
modules.d/90dmsquash-live/dmsquash-live-root.sh | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
index 62d1b5e7..a98e258c 100755
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
@@ -403,6 +403,10 @@ fi

ROOTFLAGS="$(getarg rootflags)"

+if [ "$overlayfs" = required ]; then
+ echo "rd.live.overlay.overlayfs=1" > /etc/cmdline.d/dmsquash-need-overlay.conf
+fi
+
if [ -n "$overlayfs" ]; then
if [ -n "$FSIMG" ]; then
mkdir -m 0755 -p /run/rootfsbase
--
2.35.3
Loading