From 560e61b6efee685f80ee00e2101ec689aa356db9 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Mon, 23 Dec 2019 23:39:22 +0300 Subject: [PATCH 01/10] Build tiny `ubxtool` docker image and a binary depending on just glibc That's useful to avoid native compilation on a Raspberry Pi itself while running a galmon probe. --- .gitignore | 2 ++ Dockerfile.ubxtool | 30 ++++++++++++++++++++++++++++++ Makefile | 9 +++++++-- README.md | 17 +++++++++++++++++ build-ubxtool | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.ubxtool create mode 100755 build-ubxtool diff --git a/.gitignore b/.gitignore index f1e53ef..0045686 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ navrecv testrunner tlecatch ubxtool +ubxtool.nodeps +ubxtool.nodeps.* # - created by update-tles active.txt beidou.txt diff --git a/Dockerfile.ubxtool b/Dockerfile.ubxtool new file mode 100644 index 0000000..645ce12 --- /dev/null +++ b/Dockerfile.ubxtool @@ -0,0 +1,30 @@ +# See `build-ubxtool` script for cross-compilation options. +FROM ubuntu:bionic AS build-env + +ENV DEBIAN_FRONTEND noninteractive +ENV LC_ALL C.UTF-8 + +# This allows you to use a local Ubuntu mirror +ARG APT_URL= +ENV APT_URL ${APT_URL:-mirror://mirrors.ubuntu.com/mirrors.txt} +RUN set -ex && \ + sed -i "s%http://archive.ubuntu.com/ubuntu/%${APT_URL}%" /etc/apt/sources.list && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + build-essential \ + g++ \ + libprotobuf-dev \ + make \ + protobuf-compiler \ + && \ + apt-get -y clean && \ + : + +ADD . /galmon/ +WORKDIR /galmon +RUN make ubxtool.nodeps + +FROM busybox:glibc +COPY --from=build-env /galmon/ubxtool.nodeps /opt/ubxtool +ENTRYPOINT ["/opt/ubxtool"] diff --git a/Makefile b/Makefile index 6bfceb4..93bbbf0 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ H2OPP=ext/powerblog/h2o-pp.o SIMPLESOCKETS=ext/powerblog/ext/simplesocket/swrappers.o ext/powerblog/ext/simplesocket/sclasses.o ext/powerblog/ext/simplesocket/comboaddress.o clean: - rm -f *~ *.o *.d ext/*/*.o $(PROGRAMS) navmon.pb.h navmon.pb.cc $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) $(H2OPP) $(SIMPLESOCKETS) + rm -f *~ *.o *.d ext/*/*.o $(PROGRAMS) ubxtool.nodeps* navmon.pb.h navmon.pb.cc $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) $(H2OPP) $(SIMPLESOCKETS) rm -f ext/fmt-5.2.1/src/format.o @@ -52,8 +52,13 @@ tlecatch: tlecatch.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) navmon.pb.cc: navmon.proto protoc --cpp_out=./ navmon.proto -ubxtool: navmon.pb.o ubxtool.o ubx.o bits.o ext/fmt-5.2.1/src/format.o galileo.o gps.o beidou.o navmon.o ephemeris.o $(SIMPLESOCKETS) osen.o +UBXTOOL_DEPS = navmon.pb.o ubxtool.o ubx.o bits.o ext/fmt-5.2.1/src/format.o galileo.o gps.o beidou.o navmon.o ephemeris.o $(SIMPLESOCKETS) osen.o + +ubxtool: $(UBXTOOL_DEPS) $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -lprotobuf -pthread +# Static linking of `glibc` is non-trivial, so glibc is kept dynamically linked +ubxtool.nodeps: $(UBXTOOL_DEPS) + $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib /usr/lib/*-linux-*/libprotobuf.a -pthread -static-libgcc -static-libstdc++ testrunner: navmon.pb.o testrunner.o ubx.o bits.o ext/fmt-5.2.1/src/format.o galileo.o gps.o beidou.o ephemeris.o sp3.o osen.o $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -lprotobuf diff --git a/README.md b/README.md index 2d5699d..f075588 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,23 @@ To run a container with a shell in there: docker run -it --rm galmon ``` +Build `ubxtool` in Docker +------------------------- + +To build a minimal `ubxtool` docker image: + +``` +git clone https://github.com/ahupowerdns/galmon.git --recursive +./build-ubxtool native +``` + +It may also cross-compile a binary and an image for a Raspberry Pi: + +``` +git clone https://github.com/ahupowerdns/galmon.git --recursive +docker run -it --rm --privileged multiarch/qemu-user-static:register --reset +./build-ubxtool armhf +``` Running ------- diff --git a/build-ubxtool b/build-ubxtool new file mode 100755 index 0000000..5f4ae80 --- /dev/null +++ b/build-ubxtool @@ -0,0 +1,33 @@ +#!/bin/bash +# +# The script relies on the following project: +# - https://github.com/multiarch/qemu-user-static +# - https://github.com/multiarch/ubuntu-core +# +# Another easy cross-compilation option is to use https://github.com/docker/binfmt +# +# Register qemu-user-static before building +# $ docker run --rm --privileged multiarch/qemu-user-static:register --reset + +set -e + +arch=${1:-native} + +case "$arch" in + native) + tag=latest + from=ubuntu:bionic + ;; + x86|x86_64|arm64|armhf) + tag=${arch} + from=multiarch/ubuntu-core:${arch}-bionic + ;; + *) + echo "$0: unknown arch <$arch>, known are: (native|x86|x86_64|arm64|armhf)" 1>&2 + exit 1 +esac + +sed "s,^FROM ubuntu:bionic AS,FROM ${from} AS," Dockerfile.ubxtool | docker build -f - --tag ubxtool:${tag} . +cntr=$(docker create ubxtool:${tag}) +docker cp ${cntr}:/opt/ubxtool ./ubxtool.nodeps.${tag} +docker rm ${cntr} From f3d3284e3552d41de1abb315b705909fc0b9c825 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sat, 1 Feb 2020 23:28:22 +0300 Subject: [PATCH 02/10] Fix build for Raspberry Pi 1 B+ and Zero --- .dockerignore | 1 + .gitignore | 4 +- ...erfile.ubxtool => Dockerfile.ubxtool.glibc | 1 + Dockerfile.ubxtool.static | 33 +++++++ Makefile | 5 +- README.md | 4 +- bin/.keep | 0 build-ubxtool | 86 +++++++++++++++---- ubxtool.cc | 1 + 9 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 .dockerignore rename Dockerfile.ubxtool => Dockerfile.ubxtool.glibc (98%) create mode 100644 Dockerfile.ubxtool.static create mode 100644 bin/.keep diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5cd7ec7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/bin/ubxtool.* diff --git a/.gitignore b/.gitignore index 3b952bb..e5885c3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,9 @@ testrunner tlecatch ubxtool ubxtool.nodeps -ubxtool.nodeps.* +ubxtool.static +# - created by build-ubxtool +/bin/ubxtool.* # - created by update-tles active.txt beidou.txt diff --git a/Dockerfile.ubxtool b/Dockerfile.ubxtool.glibc similarity index 98% rename from Dockerfile.ubxtool rename to Dockerfile.ubxtool.glibc index 645ce12..053c26d 100644 --- a/Dockerfile.ubxtool +++ b/Dockerfile.ubxtool.glibc @@ -14,6 +14,7 @@ RUN set -ex && \ apt-get install -y \ build-essential \ g++ \ + git \ libprotobuf-dev \ make \ protobuf-compiler \ diff --git a/Dockerfile.ubxtool.static b/Dockerfile.ubxtool.static new file mode 100644 index 0000000..eb140d4 --- /dev/null +++ b/Dockerfile.ubxtool.static @@ -0,0 +1,33 @@ +# See `build-ubxtool` script for cross-compilation options. + +# 1. GCC has issues with exception unwinding with static build of libmusl. +# The bug is fixed for gcc-10, but alpine:3.11 has 9.2.0-r3 and alpine:3.10 has 8.3.0-r0. +# Both are affected per test and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91737 +# +# 2. clang-9.0.0-r1 from alpine:3.11 generates wrong FPU instructions for Raspberry Pi 1 B+ and Zero. +# It uses d{16..31} registers for a VFPv2 FPU and that leads to SIGILL. +# The bug is described at https://reviews.llvm.org/D67375 +# The bug is fixed in clang-10: https://reviews.llvm.org/rGddf5e86c222c6b5226be53e1250421fe608bb4d0 +# +# 3. clang-8.0.0-r0 from alpine:3.10 is not affected by the bug, so we use it. +FROM alpine:3.10 AS build-env + +# g++ is still installed to bring C++ headers like , , etc. +# See https://pkgs.alpinelinux.org/contents?file=iostream&branch=v3.10&arch=armhf +RUN set -ex && \ + apk add --no-cache \ + clang \ + g++ \ + git \ + make \ + protobuf-dev \ + && \ + : + +ADD . /galmon/ +WORKDIR /galmon/ +RUN CXX=clang make ubxtool.static + +FROM scratch +COPY --from=build-env /galmon/ubxtool.static /opt/ubxtool +ENTRYPOINT ["/opt/ubxtool"] diff --git a/Makefile b/Makefile index 04a2b1a..d29dd0d 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ H2OPP=ext/powerblog/h2o-pp.o SIMPLESOCKETS=ext/powerblog/ext/simplesocket/swrappers.o ext/powerblog/ext/simplesocket/sclasses.o ext/powerblog/ext/simplesocket/comboaddress.o clean: - rm -f *~ *.o *.d ext/*/*.o $(PROGRAMS) ubxtool.nodeps* navmon.pb.h navmon.pb.cc $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) $(H2OPP) $(SIMPLESOCKETS) + rm -f *~ *.o *.d ext/*/*.o $(PROGRAMS) ubxtool.nodeps ubxtool.static navmon.pb.h navmon.pb.cc $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) $(H2OPP) $(SIMPLESOCKETS) rm -f ext/fmt-5.2.1/src/format.o decrypt: decrypt.o bits.o ext/fmt-5.2.1/src/format.o @@ -73,6 +73,9 @@ UBXTOOL_DEPS = navmon.pb.o ubxtool.o ubx.o bits.o ext/fmt-5.2.1/src/format.o gal ubxtool: $(UBXTOOL_DEPS) $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -lprotobuf -pthread +# Static build with musl on alpine and clang +ubxtool.static: $(UBXTOOL_DEPS) + $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -lprotobuf -pthread -lstdc++ -static # Static linking of `glibc` is non-trivial, so glibc is kept dynamically linked ubxtool.nodeps: $(UBXTOOL_DEPS) $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib /usr/lib/*-linux-*/libprotobuf.a -pthread -static-libgcc -static-libstdc++ diff --git a/README.md b/README.md index 0226e86..874ac43 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ To build a minimal `ubxtool` docker image: ``` git clone https://github.com/ahupowerdns/galmon.git --recursive -./build-ubxtool native +./build-ubxtool ``` It may also cross-compile a binary and an image for a Raspberry Pi: @@ -123,7 +123,7 @@ It may also cross-compile a binary and an image for a Raspberry Pi: ``` git clone https://github.com/ahupowerdns/galmon.git --recursive docker run -it --rm --privileged multiarch/qemu-user-static:register --reset -./build-ubxtool armhf +./build-ubxtool armv6l ``` Running diff --git a/bin/.keep b/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/build-ubxtool b/build-ubxtool index 5f4ae80..8afebca 100755 --- a/build-ubxtool +++ b/build-ubxtool @@ -3,31 +3,87 @@ # The script relies on the following project: # - https://github.com/multiarch/qemu-user-static # - https://github.com/multiarch/ubuntu-core +# - https://github.com/multiarch/alpine # -# Another easy cross-compilation option is to use https://github.com/docker/binfmt +# It's also probably possible to use more official {i386,amd64,arm32v6,arm32v7,arm64v8}/alpine +# images adding qemu binary from multiarch/qemu-user-static:{arm,arm64} to them. # # Register qemu-user-static before building # $ docker run --rm --privileged multiarch/qemu-user-static:register --reset set -e -arch=${1:-native} - -case "$arch" in - native) - tag=latest - from=ubuntu:bionic - ;; - x86|x86_64|arm64|armhf) - tag=${arch} - from=multiarch/ubuntu-core:${arch}-bionic - ;; +this_mach=$(uname --machine) + +if [ "$this_mach" != "x86_64" ]; then + echo "$0: build was tested on x86_64, not on this <$this_mach>" 1>&2 +fi + +mach=${1:-${this_mach}} +libc=${2:-static} + +case "$mach" in + i686) + alpine=x86 # official: i386/alpine + ubuntu=x86 + busybox=i386 + ;; + x86_64) + alpine=x86_64 # official: amd64/alpine + ubuntu=x86_64 + busybox=amd64 + ;; + armv6l) + # For Raspberry 1 and Zero. + # Tested on Raspberry 1 B+ (BCM2835 rev. 0010). + alpine=armhf # official: arm32v6/alpine + ubuntu=* + busybox=arm32v6 + ;; + armv7l) + # For Raspberry 2 and 3. + # Tested on Raspberry 3 Model B (BCM2835 revision a02082). + # Tested on Raspberry 3 Model B+ (BCM2835 revision a020d3). + alpine=armv7 # official: arm32v7/alpine + ubuntu=armhf + busybox=arm32v7 + ;; + aarch64) + # For Raspberry 4? + alpine=arm64 # official: arm64v8/alpine + ubuntu=arm64 # or aarch64? See https://wiki.ubuntu.com/ARM/RaspberryPi#Ubuntu_arm64.2FAArch64 + busybox=arm64v8 + ;; *) - echo "$0: unknown arch <$arch>, known are: (native|x86|x86_64|arm64|armhf)" 1>&2 + echo "$0: unknown machine hardware name <$mach>, known are: {i686,x86_64,armv6l,armv7l,aarch64}" 1>&2 exit 1 esac -sed "s,^FROM ubuntu:bionic AS,FROM ${from} AS," Dockerfile.ubxtool | docker build -f - --tag ubxtool:${tag} . +case "$libc" in + static) + from="alpine:3.10" + to="multiarch/alpine:${alpine}-v3.10" + ;; + glibc) + if [ "$ubuntu" = "*" ]; then + echo "$0: unsupported combination of machine <$mach> and libc <$libc>" 1>&2 + exit 1 + fi + from="ubuntu:bionic" + to="multiarch/ubuntu-core:${ubuntu}-bionic" + ;; + *) + echo "$0: unknown libc <$libc>, known are: {static,glibc}" 1>&2 + exit 1 +esac + +tag="${mach}-${libc}" + +sed -e "s,^FROM ${from} AS ,FROM ${to} AS ," \ + -e "s,^FROM busybox:glibc,FROM ${busybox}/busybox:glibc," \ + Dockerfile.ubxtool.${libc} \ + | docker build -f - --tag ubxtool:${tag} . + cntr=$(docker create ubxtool:${tag}) -docker cp ${cntr}:/opt/ubxtool ./ubxtool.nodeps.${tag} +docker cp ${cntr}:/opt/ubxtool bin/ubxtool.${tag} docker rm ${cntr} diff --git a/ubxtool.cc b/ubxtool.cc index f9770b1..59d152e 100644 --- a/ubxtool.cc +++ b/ubxtool.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include "fmt/format.h" #include "fmt/printf.h" #include "bits.hh" From b750ff8129487bda42af03c4944e9836663aab33 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sat, 8 Feb 2020 20:59:13 +0300 Subject: [PATCH 03/10] Add ubxtool-static github workflow --- .github/workflows/ubxtool.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/ubxtool.yml diff --git a/.github/workflows/ubxtool.yml b/.github/workflows/ubxtool.yml new file mode 100644 index 0000000..d955e8e --- /dev/null +++ b/.github/workflows/ubxtool.yml @@ -0,0 +1,19 @@ +name: static ubxtool binaries +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + mach: [i686, x86_64, armv6l, armv7l, aarch64] + steps: + - uses: actions/checkout@v2 + - name: submodules + run: git submodule update --init --recursive --depth=1 + - name: build-ubxtool + run: ./build-ubxtool ${{ matrix.mach }} static + - uses: actions/upload-artifact@v1 + with: + name: ubxtool + path: bin From 6416df1af1ed6395d66261ab1d71fdb9420066af Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sat, 8 Feb 2020 21:07:53 +0300 Subject: [PATCH 04/10] CI: register qemu-user-static to compile static ubxtool binaries --- .github/workflows/ubxtool.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ubxtool.yml b/.github/workflows/ubxtool.yml index d955e8e..bc0e34e 100644 --- a/.github/workflows/ubxtool.yml +++ b/.github/workflows/ubxtool.yml @@ -11,6 +11,8 @@ jobs: - uses: actions/checkout@v2 - name: submodules run: git submodule update --init --recursive --depth=1 + - name: register qemu-user-static + run: sudo docker run --rm --interactive --privileged multiarch/qemu-user-static:register --reset - name: build-ubxtool run: ./build-ubxtool ${{ matrix.mach }} static - uses: actions/upload-artifact@v1 From c6cb96f7340696e86ecedd6629c8768c10ad6c4b Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sat, 8 Feb 2020 21:33:35 +0300 Subject: [PATCH 05/10] build-ubxtool: use all CPUs --- Dockerfile.ubxtool.glibc | 3 ++- Dockerfile.ubxtool.static | 3 ++- build-ubxtool | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile.ubxtool.glibc b/Dockerfile.ubxtool.glibc index 053c26d..2760ea8 100644 --- a/Dockerfile.ubxtool.glibc +++ b/Dockerfile.ubxtool.glibc @@ -22,9 +22,10 @@ RUN set -ex && \ apt-get -y clean && \ : +ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon -RUN make ubxtool.nodeps +RUN make -j$NCPU ubxtool.nodeps FROM busybox:glibc COPY --from=build-env /galmon/ubxtool.nodeps /opt/ubxtool diff --git a/Dockerfile.ubxtool.static b/Dockerfile.ubxtool.static index eb140d4..68b8ec9 100644 --- a/Dockerfile.ubxtool.static +++ b/Dockerfile.ubxtool.static @@ -24,9 +24,10 @@ RUN set -ex && \ && \ : +ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon/ -RUN CXX=clang make ubxtool.static +RUN CXX=clang make -j$NCPU ubxtool.static FROM scratch COPY --from=build-env /galmon/ubxtool.static /opt/ubxtool diff --git a/build-ubxtool b/build-ubxtool index 8afebca..4a3e108 100755 --- a/build-ubxtool +++ b/build-ubxtool @@ -14,6 +14,7 @@ set -e this_mach=$(uname --machine) +ncpu=$(grep -c ^processor /proc/cpuinfo) if [ "$this_mach" != "x86_64" ]; then echo "$0: build was tested on x86_64, not on this <$this_mach>" 1>&2 @@ -82,7 +83,7 @@ tag="${mach}-${libc}" sed -e "s,^FROM ${from} AS ,FROM ${to} AS ," \ -e "s,^FROM busybox:glibc,FROM ${busybox}/busybox:glibc," \ Dockerfile.ubxtool.${libc} \ - | docker build -f - --tag ubxtool:${tag} . + | docker build -f - --build-arg=NCPU=${ncpu} --tag ubxtool:${tag} . cntr=$(docker create ubxtool:${tag}) docker cp ${cntr}:/opt/ubxtool bin/ubxtool.${tag} From 420708ed6baaaf176b16d2061e1c7505baddb57d Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Tue, 11 Feb 2020 22:02:08 +0300 Subject: [PATCH 06/10] CI: make public ubxtool release on tag --- .github/workflows/ubxtool.yml | 88 +++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ubxtool.yml b/.github/workflows/ubxtool.yml index bc0e34e..e8e4978 100644 --- a/.github/workflows/ubxtool.yml +++ b/.github/workflows/ubxtool.yml @@ -1,5 +1,9 @@ -name: static ubxtool binaries -on: [push] +name: Release static ubxtool binaries + +on: + push: + tags: + - 'ubxtool-v*' jobs: build: @@ -14,8 +18,84 @@ jobs: - name: register qemu-user-static run: sudo docker run --rm --interactive --privileged multiarch/qemu-user-static:register --reset - name: build-ubxtool - run: ./build-ubxtool ${{ matrix.mach }} static + run: ./build-ubxtool ${{ matrix.mach }} static && rm -f bin/.keep + - name: xz + run: xz -8 bin/ubxtool.${{ matrix.mach }}-static - uses: actions/upload-artifact@v1 with: name: ubxtool - path: bin + path: bin/ubxtool.${{ matrix.mach }}-static.xz + # All binaries are uploaded to the same artifact archive. It may + # eventually change: https://github.com/actions/upload-artifact/issues/24 + + # release does not need 5 parallel running VMs, so it's a separate job + release: + needs: [build] + runs-on: ubuntu-latest + env: + # All the steps but download-artifact and sha256sum need it. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/download-artifact@v1 + with: + name: ubxtool + + - name: sha256sum + run: sha256sum ubxtool.*.xz >SHA256SUMS + + - uses: actions/create-release@v1 + id: create_release + with: + tag_name: ${{ github.ref }} + draft: false + prerelease: true + + # That's a copy-pasta instead of a matrix job to avoid spawing a VM for each upload. + - name: upload i686 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ubxtool.i686-static.xz + asset_name: ubxtool.i686-static.xz + asset_content_type: application/x-xz + + - name: upload x86_64 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ubxtool.x86_64-static.xz + asset_name: ubxtool.x86_64-static.xz + asset_content_type: application/x-xz + + - name: upload armv6l + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ubxtool.armv6l-static.xz + asset_name: ubxtool.armv6l-static.xz + asset_content_type: application/x-xz + + - name: upload armv7l + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ubxtool.armv7l-static.xz + asset_name: ubxtool.armv7l-static.xz + asset_content_type: application/x-xz + + - name: upload aarch64 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./ubxtool.aarch64-static.xz + asset_name: ubxtool.aarch64-static.xz + asset_content_type: application/x-xz + + # The last one. + - name: upload SHA256SUMS + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SHA256SUMS + asset_name: SHA256SUMS + asset_content_type: text/plain From dcffe7144b22ac5b92b46c928bb806404e53107b Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Tue, 11 Feb 2020 22:18:07 +0300 Subject: [PATCH 07/10] CI: fix paths --- .github/workflows/ubxtool.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ubxtool.yml b/.github/workflows/ubxtool.yml index e8e4978..0a1e174 100644 --- a/.github/workflows/ubxtool.yml +++ b/.github/workflows/ubxtool.yml @@ -41,6 +41,7 @@ jobs: name: ubxtool - name: sha256sum + working-directory: ubxtool run: sha256sum ubxtool.*.xz >SHA256SUMS - uses: actions/create-release@v1 @@ -55,7 +56,7 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ubxtool.i686-static.xz + asset_path: ubxtool/ubxtool.i686-static.xz asset_name: ubxtool.i686-static.xz asset_content_type: application/x-xz @@ -63,7 +64,7 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ubxtool.x86_64-static.xz + asset_path: ubxtool/ubxtool.x86_64-static.xz asset_name: ubxtool.x86_64-static.xz asset_content_type: application/x-xz @@ -71,7 +72,7 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ubxtool.armv6l-static.xz + asset_path: ubxtool/ubxtool.armv6l-static.xz asset_name: ubxtool.armv6l-static.xz asset_content_type: application/x-xz @@ -79,7 +80,7 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ubxtool.armv7l-static.xz + asset_path: ubxtool/ubxtool.armv7l-static.xz asset_name: ubxtool.armv7l-static.xz asset_content_type: application/x-xz @@ -87,7 +88,7 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ubxtool.aarch64-static.xz + asset_path: ubxtool/ubxtool.aarch64-static.xz asset_name: ubxtool.aarch64-static.xz asset_content_type: application/x-xz @@ -96,6 +97,6 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./SHA256SUMS + asset_path: ubxtool/SHA256SUMS asset_name: SHA256SUMS asset_content_type: text/plain From 4219d2dfd8fd0b165d87d8e798badceabdf46c38 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Tue, 11 Feb 2020 22:31:58 +0300 Subject: [PATCH 08/10] CI: make actions/create-release happy --- .github/workflows/ubxtool.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ubxtool.yml b/.github/workflows/ubxtool.yml index 0a1e174..415b655 100644 --- a/.github/workflows/ubxtool.yml +++ b/.github/workflows/ubxtool.yml @@ -48,6 +48,8 @@ jobs: id: create_release with: tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: GitHub-built release draft: false prerelease: true From a479acb6eeebe68301fb3cb60b10a73d24109a34 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Wed, 12 Feb 2020 01:22:32 +0300 Subject: [PATCH 09/10] CI: revert modified .dockerignore in Dockerfile to have clean githash.h --- Dockerfile.ubxtool.glibc | 6 +++++- Dockerfile.ubxtool.static | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile.ubxtool.glibc b/Dockerfile.ubxtool.glibc index 2760ea8..fb10bbd 100644 --- a/Dockerfile.ubxtool.glibc +++ b/Dockerfile.ubxtool.glibc @@ -25,7 +25,11 @@ RUN set -ex && \ ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon -RUN make -j$NCPU ubxtool.nodeps +# .dockerignore has to be reset to make `git status` happy as docker-build +# appends a line like ".dockerfile.8a2b17b1408769bf5047" to .dockerignore. +RUN set -ex && \ + git checkout HEAD -- .dockerignore && \ + make -j$NCPU ubxtool.nodeps FROM busybox:glibc COPY --from=build-env /galmon/ubxtool.nodeps /opt/ubxtool diff --git a/Dockerfile.ubxtool.static b/Dockerfile.ubxtool.static index 68b8ec9..fa98374 100644 --- a/Dockerfile.ubxtool.static +++ b/Dockerfile.ubxtool.static @@ -27,7 +27,11 @@ RUN set -ex && \ ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon/ -RUN CXX=clang make -j$NCPU ubxtool.static +# .dockerignore has to be reset to make `git status` happy as docker-build +# appends a line like ".dockerfile.8a2b17b1408769bf5047" to .dockerignore. +RUN set -ex && \ + git checkout HEAD -- .dockerignore && \ + CXX=clang make -j$NCPU ubxtool.static FROM scratch COPY --from=build-env /galmon/ubxtool.static /opt/ubxtool From 14d683c221604901ba076b4072aff8361e6c36da Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Wed, 12 Feb 2020 14:34:45 +0300 Subject: [PATCH 10/10] CI: fix the root cause of .dockerignore modification during docker-build --- Dockerfile.ubxtool.glibc | 16 +++++++++------- Dockerfile.ubxtool.static | 10 ++++------ build-ubxtool | 25 +++++++++++++++---------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Dockerfile.ubxtool.glibc b/Dockerfile.ubxtool.glibc index fb10bbd..f3685aa 100644 --- a/Dockerfile.ubxtool.glibc +++ b/Dockerfile.ubxtool.glibc @@ -1,5 +1,11 @@ # See `build-ubxtool` script for cross-compilation options. -FROM ubuntu:bionic AS build-env + +# `FROM` needs `ARG`s to be specified before the very first `FROM` instruction. +# See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact +ARG UBUNTU=ubuntu: +ARG BUSYBOX=busybox: + +FROM ${UBUNTU}bionic AS build-env ENV DEBIAN_FRONTEND noninteractive ENV LC_ALL C.UTF-8 @@ -25,12 +31,8 @@ RUN set -ex && \ ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon -# .dockerignore has to be reset to make `git status` happy as docker-build -# appends a line like ".dockerfile.8a2b17b1408769bf5047" to .dockerignore. -RUN set -ex && \ - git checkout HEAD -- .dockerignore && \ - make -j$NCPU ubxtool.nodeps +RUN make -j$NCPU ubxtool.nodeps -FROM busybox:glibc +FROM ${BUSYBOX}glibc COPY --from=build-env /galmon/ubxtool.nodeps /opt/ubxtool ENTRYPOINT ["/opt/ubxtool"] diff --git a/Dockerfile.ubxtool.static b/Dockerfile.ubxtool.static index fa98374..f14b697 100644 --- a/Dockerfile.ubxtool.static +++ b/Dockerfile.ubxtool.static @@ -1,5 +1,7 @@ # See `build-ubxtool` script for cross-compilation options. +ARG ALPINE=alpine: + # 1. GCC has issues with exception unwinding with static build of libmusl. # The bug is fixed for gcc-10, but alpine:3.11 has 9.2.0-r3 and alpine:3.10 has 8.3.0-r0. # Both are affected per test and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91737 @@ -10,7 +12,7 @@ # The bug is fixed in clang-10: https://reviews.llvm.org/rGddf5e86c222c6b5226be53e1250421fe608bb4d0 # # 3. clang-8.0.0-r0 from alpine:3.10 is not affected by the bug, so we use it. -FROM alpine:3.10 AS build-env +FROM ${ALPINE}3.10 AS build-env # g++ is still installed to bring C++ headers like , , etc. # See https://pkgs.alpinelinux.org/contents?file=iostream&branch=v3.10&arch=armhf @@ -27,11 +29,7 @@ RUN set -ex && \ ARG NCPU=1 ADD . /galmon/ WORKDIR /galmon/ -# .dockerignore has to be reset to make `git status` happy as docker-build -# appends a line like ".dockerfile.8a2b17b1408769bf5047" to .dockerignore. -RUN set -ex && \ - git checkout HEAD -- .dockerignore && \ - CXX=clang make -j$NCPU ubxtool.static +RUN CXX=clang make -j$NCPU ubxtool.static FROM scratch COPY --from=build-env /galmon/ubxtool.static /opt/ubxtool diff --git a/build-ubxtool b/build-ubxtool index 4a3e108..36ce13b 100755 --- a/build-ubxtool +++ b/build-ubxtool @@ -62,28 +62,33 @@ esac case "$libc" in static) - from="alpine:3.10" - to="multiarch/alpine:${alpine}-v3.10" + img="--build-arg ALPINE=multiarch/alpine:${alpine}-v" ;; glibc) if [ "$ubuntu" = "*" ]; then echo "$0: unsupported combination of machine <$mach> and libc <$libc>" 1>&2 exit 1 fi - from="ubuntu:bionic" - to="multiarch/ubuntu-core:${ubuntu}-bionic" + img="--build-arg UBUNTU=multiarch/ubuntu-core:${ubuntu}- --build-arg BUSYBOX=${busybox}/busybox:" ;; *) - echo "$0: unknown libc <$libc>, known are: {static,glibc}" 1>&2 - exit 1 + echo "$0: unknown libc <$libc>, known are: {static,glibc}" 1>&2 + exit 1 esac +# Base image is set with `ARG` and not with `sed Dockerfile | docker build -f -` +# as streaming Dockerfile to stdin actually saves it to a file and adds a line +# like ".dockerfile.8a2b17b1408769bf5047" to .dockerignore. And .dockerignore +# should not be touched to make reasonable `githash.h`. + tag="${mach}-${libc}" -sed -e "s,^FROM ${from} AS ,FROM ${to} AS ," \ - -e "s,^FROM busybox:glibc,FROM ${busybox}/busybox:glibc," \ - Dockerfile.ubxtool.${libc} \ - | docker build -f - --build-arg=NCPU=${ncpu} --tag ubxtool:${tag} . +docker build \ + --build-arg NCPU=${ncpu} \ + ${img} \ + -f Dockerfile.ubxtool.${libc} \ + --tag ubxtool:${tag} \ + . cntr=$(docker create ubxtool:${tag}) docker cp ${cntr}:/opt/ubxtool bin/ubxtool.${tag}