Gitea ARM crossbuild (with GoModules)

Upgrading to Gitea 1.13.4 didn’t go as planned and it failed to compile the go-sqlite3 module with my previous setup. While crossbuilding, the CGO parameter is automatically disabled (i.e. compiling is done with CGO_ENABLED=0) but the go-sqlite3 module won’t build anymore if this option is not set (probably require some optimisation in C and a pure Go implementation won’t fit anymore). As a consequence of enabling this option, setting the environment variable CC to the C cross-compiler explicitly is now mandatory to ensure modules don’t target the wrong platform.

A recent Go compiler will also have the Go Modules support enabled, thus we can now simplify the build process with a more usual checkout/make pattern.

Dockerfile sample:

FROM golang:latest

RUN dpkg --add-architecture armhf

RUN apt-get update
RUN apt-get install -y --no-install-recommends curl git build-essential crossbuild-essential-armhf

SHELL [ "/bin/bash", "--login", "-c" ]

ARG NVM_VERSION="0.37.2"
RUN\
  ( export PROFILE=$HOME/.profile;\
    /usr/bin/curl -o- "https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh" | /bin/bash )

ARG NODE_VERSION="14.15.3"
RUN\
  nvm install "${NODE_VERSION}" &&\
  nvm use "v${NODE_VERSION}" &&\
  nvm alias default "v${NODE_VERSION}"

ARG YARN_VERSION="1.22.10"
RUN\
  ( export PROFILE=$HOME/.profile;\
    /usr/bin/curl -o- -L "https:/yarnpkg.com/install.sh" | /bin/bash -s -- --version ${YARN_VERSION})

RUN\
  ( echo ;\
    echo 'source $HOME/.nvm/nvm.sh';\
    echo 'export PATH=/go/bin:/usr/local/go/bin:${PATH}'; ) >> $HOME/.profile

WORKDIR /go

ENV GOARM=7
ENV GOARCH=arm
ENV GOOS=linux
ENV CGO_ENABLED=1
ENV CC=arm-linux-gnueabihf-gcc

ARG GITEA_VERSION="v1.13.4"
RUN git clone --shallow-submodules --recurse-submodules --branch "${GITEA_VERSION}" --depth 1 https://github.com/go-gitea/gitea.git gitea

ENV TAGS="bindata sqlite sqlite_unlock_notify"
RUN cd gitea && make build

Which we can run with (replace the host_output_dir with some folder on the host):

docker build -t gitea-arm-builder .
docker run --rm -v [host_output_dir]:/output gitea-arm-builder cp /go/src/code.gitea.io/gitea/gitea /output/gitea-1.13.4-arm-linux
Cyrille Froehlich
Cyrille Froehlich
Software developer