Skip to content

Commit

Permalink
Merge pull request #708 from openziti/debug-builder
Browse files Browse the repository at this point in the history
target armhf for arm/v7 32bit build; add armel build instructions
  • Loading branch information
qrkourier authored Jul 25, 2024
2 parents 73c4675 + a60c0bf commit 1927c64
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 115 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
with:
distribution: goreleaser
version: '~> v2'
args: release --skip=publish --config .goreleaser-linux.yml
args: release --skip=publish --config .goreleaser-linux-amd64.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- run: sudo apt update
- run: sudo apt-get install gcc-arm-linux-gnueabi
- run: sudo apt-get install gcc-arm-linux-gnueabihf

- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:
runs-on: macos-latest
steps:
- name: import distribution cert
uses: apple-actions/import-codesign-certs@v1
uses: apple-actions/import-codesign-certs@v3
with:
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-darwin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- id: zrok-amd64
main: ./cmd/zrok
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-linux.yml → .goreleaser-linux-amd64.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- id: zrok-amd64
main: ./cmd/zrok
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-linux-arm64.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- id: zrok-armv8
main: ./cmd/zrok
Expand Down
144 changes: 144 additions & 0 deletions .goreleaser-linux-armel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# this is a DiY build config for the soft-float, armel platform (32bit ARMv7 devices lacking an FPU) see
# instructions to cross-build this binary in ./docker/images/cross-build/README.md or
# https://github.com/openziti/zrok/tree/main/docker/images/cross-build#readme
version: 2
builds:
- id: zrok-armel
main: ./cmd/zrok
binary: zrok
ldflags:
- "-s -w -X github.com/openziti/zrok/build.Version={{.Tag}} -X github.com/openziti/zrok/build.Hash={{.ShortCommit}}"
env:
- CC=arm-linux-gnueabi-gcc
- CGO_ENABLED=1
- CC_FOR_TARGET=gcc-arm-linux-gnueabi
goos:
- linux
goarch:
- arm
goarm:
- 7

nfpms:
- package_name: zrok
id: zrok-cli
vendor: NetFoundry
homepage: https://zrok.io/
maintainer: [email protected]
description: |-
zrok is a next-generation sharing platform, designed to make sharing network and file resources simple and
secure.
license: Apache 2.0

# Build IDs for the builds you want to create NFPM packages for.
builds:
- zrok-armel

# Formats to be generated.
formats:
- deb
- rpm

# {{ .ConventionalFileName }} satisfies the RPM name convention.
file_name_template: "{{ .ConventionalFileName }}"

# Umask to be used on files without explicit mode set. (overridable)
umask: 0o002

# Package version within this release version.
release: 1

# Section.
section: default

# Priority.
priority: optional

# GoReleaser will automatically add the binaries here
bindir: /opt/openziti/bin

# Contents to add to the package.
contents:
- src: /opt/openziti/bin/zrok
dst: /usr/bin/zrok
type: "symlink"

- package_name: zrok-share
id: zrok-share
vendor: NetFoundry
homepage: https://zrok.io/
maintainer: [email protected]
description: |-
This package provides zrok-share.service. To enable, edit the "/opt/openziti/etc/zrok/zrok-share.env" file with the
desired target for sharing, and run "systemctl enable --now zrok-share.service".
license: Apache 2.0

# do not bundle the built binaries, only supporting files
meta: true

# Formats to be generated.
formats:
- deb
- rpm

# {{ .ConventionalFileName }} satisfies the RPM name convention.
file_name_template: "{{ .ConventionalFileName }}"

# Umask to be used on files without explicit mode set. (overridable)
umask: 0o002

# Package version within this release version.
release: 1

# Section.
section: default

# Priority.
priority: optional

# GoReleaser will automatically add the binaries here
dependencies:
- zrok

# this allows users to satisfy the requirement for jq another way, not with the package manager, e.g.
# apt install --no-recommends zrok-share
recommends:
- jq

overrides:
# yum and dnf do not automatically install "weak deps" aka "recommends", so we need to add them as a dependency
rpm:
dependencies:
- zrok
- jq

# Contents to add to the package.
contents:
- dst: /lib/systemd/system/
src: ./nfpm/zrok-share.service

- dst: /etc/systemd/system/zrok-share.service.d/override.conf
src: ./nfpm/zrok-share.service.override.conf

- dst: /opt/openziti/etc/zrok
type: dir
file_info:
mode: 0755

- dst: /opt/openziti/bin/
src: ./nfpm/zrok-share.bash
file_info:
mode: 0755

- dst: /opt/openziti/bin/
src: ./nfpm/zrok-enable.bash
file_info:
mode: 0755

- dst: /opt/openziti/etc/zrok/
src: ./nfpm/zrok-share.env
type: config|noreplace

- dst: /opt/openziti/etc/zrok/
src: ./etc/caddy/multiple_upstream.Caddyfile
type: config|noreplace
13 changes: 8 additions & 5 deletions .goreleaser-linux-armhf.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# this is the release build config for hard-float, arm/v7 platform (32bit ARM devices with a FPU)
version: 2
builds:
- id: zrok-armv7
- id: zrok-armhf
main: ./cmd/zrok
binary: zrok
ldflags: "-s -w -X github.com/openziti/zrok/build.Version={{.Tag}} -X github.com/openziti/zrok/build.Hash={{.ShortCommit}}"
ldflags:
- "-s -w -X github.com/openziti/zrok/build.Version={{.Tag}} -X github.com/openziti/zrok/build.Hash={{.ShortCommit}}"
env:
- CC=arm-linux-gnueabi-gcc
- CC=arm-linux-gnueabihf-gcc
- CGO_ENABLED=1
- CC_FOR_TARGET=gcc-arm-linux-gnueabi
- CC_FOR_TARGET=gcc-arm-linux-gnueabihf
goos:
- linux
goarch:
Expand All @@ -27,7 +30,7 @@ nfpms:

# Build IDs for the builds you want to create NFPM packages for.
builds:
- zrok-armv7
- zrok-armhf

# Formats to be generated.
formats:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- skip: true
release:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-windows.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
builds:
- main: ./cmd/zrok
binary: zrok
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FEATURE: New interstitial pages that can be enabled per-frontend, and disabled p

CHANGE: Enable `"declaration": true` in `tsconfig.json` for Node SDK.

FIX: Statically link arm 32bit build for broader compatibility.

## v0.4.35

FEATURE: Added import for `github.com/greenpau/caddy-security` to include that Caddy plugin to enable authentication, authorization, and credentials extensions for the `caddy` backend (https://github.com/openziti/zrok/issues/506)
Expand Down
34 changes: 19 additions & 15 deletions docker/images/cross-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
# Stage 1: Install Node.js with nvm
FROM debian:bullseye-slim
FROM goreleaser/goreleaser AS goreleaser

FROM golang:1.21 AS golang

FROM debian:bookworm-slim
#
# this file mirrors the build params used in the GitHub Actions and enables
# reproducible builds for downstream forks for Ziti contributors
#

ARG TARGETARCH
ARG golang_version=1.21.3
ARG go_distribution_file=go${golang_version}.linux-${TARGETARCH}.tar.gz
ARG go_path=/usr/share/go
ARG go_root=/usr/local/go
ARG go_cache=/usr/share/go_cache
ARG uid=1000
ARG gid=1000
ARG go_cache=/usr/share/go

RUN apt-get -y update \
&& apt-get -y install \
gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc-aarch64-linux-gnu \
wget build-essential
gcc-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu \
wget \
git \
build-essential

RUN wget -q https://go.dev/dl/${go_distribution_file}
RUN tar -xzf ${go_distribution_file} -C /usr/local/

RUN wget -qO- https://deb.nodesource.com/setup_18.x | bash \
&& apt-get -y update \
&& apt-get -y install \
nodejs

RUN mkdir ${go_path} ${go_cache}
RUN chown -R ${uid}:${gid} ${go_path} ${go_cache}

COPY ./linux-build.sh /usr/local/bin/
COPY --from=golang /usr/local/go /usr/local/go
# RUN chmod -R go+rX ${go_path} ${go_cache}

COPY --from=goreleaser /usr/bin/goreleaser /usr/local/bin/goreleaser

COPY ./linux-build.sh /usr/local/bin/linux-build.sh

USER ${uid}:${gid}
ENV TARGETARCH=${TARGETARCH}
ENV GOPATH=${go_path}
ENV GOROOT=${go_root}
ENV GOCACHE=${go_cache}
ENV PATH=${go_path}/bin:${go_root}/bin:$PATH

RUN go install github.com/mitchellh/gox@latest
WORKDIR /mnt
ENTRYPOINT ["linux-build.sh"]

30 changes: 6 additions & 24 deletions docker/images/cross-build/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@

# Cross-build Container for Building the Linux Executables for this zrok Project

Running this container produces three executables for zrok, one for each platform architecture: amd64, arm, arm64. You may specify the target CPU architecture as a parameter to the `docker run` command.
Running this container produces one snapshot executable for zrok from the current checkout, even if dirty. Platform choices are: `amd64`, `arm64`, `arm` (the arm/v7 "armhf" ABI target), and `armel` (the arm/v7 "armel" ABI). You may specify the target architecture as a parameter to the `docker run` command.

## Build the Container Image

You only need to build the container image once unless you change the Dockerfile or `./linux-build.sh`.

```bash
# build a container image named "zrok-builder" with the same version of Go that's declared in go.mod
docker buildx build \
--tag=zrok-builder \
--build-arg uid=$UID \
--build-arg gid=$GID \
--build-arg golang_version=$(grep -Po '^go\s+\K\d+\.\d+(\.\d+)?$' go.mod) \
--load \
./docker/images/cross-build/
# build a container image named "zrok-builder"
docker buildx build -t zrok-builder ./docker/images/cross-build --load;
```

## Run the Container to Build Executables for the Desired Architectures
Expand All @@ -24,23 +18,11 @@ Executing the following `docker run` command will:

1. Mount the top-level of this repo on the container's `/mnt`
2. Run `linux-build.sh ${@}` inside the container
3. Deposit built executables in `./dist/`
3. Deposit built executable in `./dist/`

```bash
# build for all three architectures: amd64 arm arm64
docker run \
--rm \
--name=zrok-builder \
--volume=$PWD:/mnt \
zrok-builder

# build only amd64
docker run \
--rm \
--name=zrok-builder \
--volume=$PWD:/mnt \
zrok-builder \
amd64
# cross-build for arm64/aarch64 architecture on Linux
docker run --user "${UID}" --rm --volume=${HOME}/.cache/go-build:/usr/share/go --volume "${PWD}:/mnt" zrok-builder arm64
```

You will find the built artifacts in `./dist/`.
Loading

0 comments on commit 1927c64

Please sign in to comment.