Cross Compile Containers

Note

This only works because we cross compile outside the container and copy the results in (notice the FROM scratch and no RUN commands). Otherwise we would also need an emulator to run commands within the container.

Makefile

VERSION   = $(shell git describe --long --tags)
BUILD     = $(shell date +%FT%T%z)
BUILDSYS  = $(shell . /etc/os-release; echo $$PRETTY_NAME)
LDFLAGS   = -ldflags "-X 'main.Version=${VERSION}' -X 'main.Build=${BUILD}' -X 'main.BuildSys=${BUILDSYS}'"
REPOTAG   = rpicreg.home.arpa:5000/gorepo:$(shell git describe)

.PHONY: gorepo-arm gorepo-amd64 build-arm

# normally we only need the version for the Raspberry Pi. (The programs focus)
all: gorepo-arm gorepo-amd64

gorepo-arm:
        GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo $(LDFLAGS) -o gorepo-arm .

gorepo-amd64:
        GOOS=linux GOARCH=amd64 go build -a -tags netgo $(LDFLAGS) -o gorepo-amd64 .

build-arm: gorepo-arm
        echo "Tagging arm/v7 with: $(REPOTAG)"
        docker buildx build --platform=linux/arm/v7 --provenance=false --load -t $(REPOTAG) .

Dockerfile

BUILDPLATFORM
matches the current machine. (e.g. linux/amd64)
BUILDOS
os component of BUILDPLATFORM, e.g. linux
BUILDARCH
e.g. amd64, arm64, riscv64
BUILDVARIANT
used to set ARM variant, e.g. v7
TARGETPLATFORM
The value set with –platform flag on build
TARGETOS
OS component from –platform, e.g. linux
TARGETARCH
Architecture from –platform, e.g. arm64
TARGETVARIANT
used to set ARM variant, e.g. v7
FROM scratch
ARG TARGETARCH
COPY gorepo-$TARGETARCH /bin/gorepo
ENTRYPOINT ["/bin/gorepo"]
CMD ["-addr=:8080"]
EXPOSE 8080

Defining the repositories

For configuring the chromebook docker to allow insecure repos, use file: /etc/docker/daemon.json

{
    "insecure-registries" : [
           "rpicreg.home.arpa:5000",
           "camus.home.arpa:5000",
           "localhost:5000"
   ]
}

The config for K2s is /etc/rancher/k3s/registries.yaml

mirrors:
  rpicreg:5000:
    endpoint:
      - "http://rpicreg:5000"
  rpicreg.home.arpa:5000:
    endpoint:
      - "http://rpicreg:5000"

s