Skip to content

Commit

Permalink
Integrate with Dapper, cross-compile in Alpine
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Chazapis <[email protected]>
  • Loading branch information
chazapis committed Jun 23, 2023
1 parent 5efec36 commit b6f13bc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ARG SELINUX=true
ENV SELINUX $SELINUX

ENV DAPPER_RUN_ARGS --privileged -v k3s-cache:/go/src/github.com/k3s-io/k3s/.cache -v trivy-cache:/root/.cache/trivy
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER DEBUG
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME ARCH SKIP_VALIDATE SKIP_IMAGE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER DEBUG
ENV DAPPER_SOURCE /go/src/github.com/k3s-io/k3s/
ENV DAPPER_OUTPUT ./bin ./dist ./build/out ./build/static ./pkg/static ./pkg/deploy

Expand Down
4 changes: 2 additions & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ fi
if [ ${ARCH} = riscv64 ]; then
export GOARCH="riscv64"
# These are needed as we are cross-compiling
export CC=riscv64-linux-gnu-gcc
export PKG_CONFIG_PATH=/usr/lib/riscv64-linux-gnu/pkgconfig/
export CC="riscv64-alpine-linux-musl-gcc"
export PKG_CONFIG_PATH=/home/builder/sysroot-riscv64/usr/lib/pkgconfig/
fi

rm -f \
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pushd $SCRIPT_DIR

./download
./validate
if [ ${ARCH} = riscv64 ]; then
./prepare-cross
fi
./build
./package

Expand Down
34 changes: 0 additions & 34 deletions scripts/cross-compile-riscv.sh

This file was deleted.

4 changes: 3 additions & 1 deletion scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ if [ ! -e ../bin/containerd ]; then
fi

./package-cli
./package-image
if [ -z "$SKIP_IMAGE" ]; then
./package-image
fi
if [ -z "$SKIP_AIRGAP" ]; then
./package-airgap
fi
39 changes: 39 additions & 0 deletions scripts/prepare-cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#/bin/bash

# This script prepare a cross-compilation environment for $ARCH

if [ -z "$ARCH" ]; then
echo "Error: ARCH not defined"
exit 1;
fi

if [ "$ARCH" != "riscv64" ]; then
echo "Error: Cross-compilation only available for riscv64"
exit 1;
fi

if [ "$ARCH" = "riscv64" ]; then
ALPINE_APK_REPO=https://dl-cdn.alpinelinux.org/alpine/edge/main
fi

# Build packages for cross-compiling (bootstrap.sh requires a non-root user)
adduser -D builder
addgroup builder abuild

su builder -c "abuild-keygen -an"
cp ~builder/.abuild/builder-*.rsa.pub /etc/apk/keys/

ALPINE_VERSION=$(. /etc/os-release; echo $VERSION_ID | cut -f1,2 -d.)
su builder -c "cd; git clone --single-branch --branch=$ALPINE_VERSION-stable --depth 1 https://github.com/alpinelinux/aports"
sed -i "/Cross building base system/i exit 0\n" /home/builder/aports/scripts/bootstrap.sh
apk update
su builder -c "CBUILDROOT=~/sysroot-$ARCH ~/aports/scripts/bootstrap.sh $ARCH"

# Install the cross-compiler in the host
apk -X /home/builder/packages/main add gcc-$ARCH

# Install headers and libraries in the gcc sysroot (upstream packages)
apk -X $ALPINE_APK_REPO -U --allow-untrusted \
-p /home/builder/sysroot-$ARCH --arch $ARCH add \
musl musl-dev linux-headers libseccomp-dev libseccomp-static sqlite-dev sqlite-static zlib-static libgcc
sed -i "s/^prefix=.*/prefix=\/home\/builder\/sysroot-$ARCH\/usr/g" /home/builder/sysroot-riscv64/usr/lib/pkgconfig/libseccomp.pc

0 comments on commit b6f13bc

Please sign in to comment.