From 4d21bacd8cde9deddffe42aca06582f889477fcc Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 21 Sep 2020 10:38:10 +0700 Subject: [PATCH 1/9] Add a multiarch docker image --- .github/workflows/docker.yaml | 44 +++++++- Dockerfile => docker/alpine/Dockerfile | 4 +- docker/{ => alpine}/entrypoint.sh | 0 docker/debian/Dockerfile | 134 +++++++++++++++++++++++++ docker/debian/entrypoint.sh | 9 ++ 5 files changed, 184 insertions(+), 7 deletions(-) rename Dockerfile => docker/alpine/Dockerfile (94%) rename docker/{ => alpine}/entrypoint.sh (100%) mode change 100755 => 100644 create mode 100644 docker/debian/Dockerfile create mode 100755 docker/debian/entrypoint.sh diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index a6393157..24bdcf92 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -29,12 +29,46 @@ jobs: uses: ASzc/change-string-case-action@v1 with: string: ${{ github.repository }} - - name: Push to Docker Hub - uses: docker/build-push-action@v1 + - name: Set up QEMU if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/setup-buildx-action@v1 + - name: Login to dockerhub + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/login-action@v1 with: username: ${{ steps.string_user.outputs.lowercase }} password: ${{ secrets.DOCKER_TOKEN }} - registry: docker.io - repository: ${{ steps.string_repo.outputs.lowercase }} - tag_with_ref: true + - name: Get tag name + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + id: tags + run: | + branch="${GITHUB_REF#refs/heads/}" + debtags="${REPO_NAME}:${branch}" + alptags="${REPO_NAME}:${branch}-alpine" + if [ "${branch}" == "master" ]; then + debtags="${debtags},${REPO_NAME}:latest" + alptags="${alptags},${REPO_NAME}:latest-alpine" + fi + echo "::set-output name=DEBTAGS::${debtags}" + echo "::set-output name=ALPTAGS::${alptags}" + env: + REPO_NAME: ${{ steps.string_repo.outputs.lowercase }} + - name: Push to Docker Hub Debian + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/build-push-action@v2 + with: + platforms: linux/arm/v7,linux/arm64,linux/amd64,linux/386 + push: true + file: docker/debian/Dockerfile + tags: ${{ steps.tags.outputs.DEBTAGS }} + - name: Push to Docker Hub Alpine + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + push: true + file: docker/alpine/Dockerfile + tags: ${{ steps.tags.outputs.ALPTAGS }} diff --git a/Dockerfile b/docker/alpine/Dockerfile similarity index 94% rename from Dockerfile rename to docker/alpine/Dockerfile index e59a34a9..de627647 100644 --- a/Dockerfile +++ b/docker/alpine/Dockerfile @@ -33,8 +33,8 @@ RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing libg COPY --from=build \ /usr/local/src/neolink/target/release/neolink \ /usr/local/bin/neolink -COPY docker/entrypoint.sh /entrypoint.sh +COPY docker/alpine/entrypoint.sh /entrypoint.sh CMD ["/usr/local/bin/neolink", "--config", "/etc/neolink.toml"] ENTRYPOINT ["/entrypoint.sh"] -EXPOSE 8554 +EXPOSE 8554 diff --git a/docker/entrypoint.sh b/docker/alpine/entrypoint.sh old mode 100755 new mode 100644 similarity index 100% rename from docker/entrypoint.sh rename to docker/alpine/entrypoint.sh diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile new file mode 100644 index 00000000..73ab840e --- /dev/null +++ b/docker/debian/Dockerfile @@ -0,0 +1,134 @@ +# Neolink Docker image build scripts +# Copyright (c) 2020 George Hilliard +# SPDX-License-Identifier: AGPL-3.0-only + +FROM --platform=$BUILDPLATFORM docker.io/rust:slim-buster AS build +MAINTAINER thirtythreeforty@gmail.com + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +# ORIGINALY I TRIED TO BUILD IN A QEMU CONTAINER. +# THIS WOULD HAVE BEEN IDEAL BECAUSE THEN WE COULD BUILD FOR ALL +# ARCH SUPPORTED BY QEMU, DEBIAN AND RUST WITHOUT ANY COMPICATED CROSS COMPILES. +# HOWEVER I KEPT GETTING THE FOLLOWING ERROR DURING COMPILE +# could not read directory '/usr/local/cargo/registry/index/github.com-1285ae84e5963aae/.git//refs': Value too large for defined data type; class=Os (2) +# Google suggest I should either update the kernel or my fs neither of which I can do on github actions +# SO INSTEAD I CROSS COMPILE USING platform=$BUILDPLATFORM and deploy on platform=$TARGETPLATFORM + +WORKDIR /usr/local/src/neolink + +# Build the main program +COPY . /usr/local/src/neolink + +RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; \ + if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ]; then \ + target="native"; \ + else \ + target="${TARGETPLATFORM}"; \ + fi; \ + case "${target}" in \ + "linux/amd64") \ + echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + rustArch='x86_64-unknown-linux-gnu'; \ + arch="amd64"; \ + gcc="x86_64-linux-gnu-gcc"; \ + export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc && \ + export CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc && \ + export CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ && \ + export PKG_CONFIG_ALLOW_CROSS=1 && \ + export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ + export PKG_CONFIG_LIBDIR=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ + ;; \ + "linux/arm/v7") \ + echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + rustArch='armv7-unknown-linux-gnueabihf'; \ + arch="armhf"; \ + gcc="gcc-arm-linux-gnueabihf"; \ + export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc && \ + export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc && \ + export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ && \ + export PKG_CONFIG_ALLOW_CROSS=1 && \ + export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ && \ + export PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/; \ + ;; \ + "linux/arm64") \ + echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + rustArch='aarch64-unknown-linux-gnu'; \ + arch="arm64"; \ + gcc="gcc-aarch64-linux-gnu"; \ + export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc && \ + export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc && \ + export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ && \ + export PKG_CONFIG_ALLOW_CROSS=1 && \ + export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ + export PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ + ;; \ + "linux/386") \ + echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + rustArch='i686-unknown-linux-gnu'; \ + arch="i386"; \ + gcc="gcc-i686-linux-gnu"; \ + export CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=i686-linux-gnu-gcc && \ + export CC_aarch64_unknown_linux_gnu=i686-linux-gnu-gcc && \ + export CXX_aarch64_unknown_linux_gnu=i686-linux-gnu-g++ && \ + export PKG_CONFIG_ALLOW_CROSS=1 && \ + export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ + export PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ + ;; \ + "native") \ + echo >&2 "\e[0;32mNot cross compiling: ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + dpkgArch="$(dpkg --print-architecture)"; \ + arch="${dpkgArch##*-}"; \ + case "${arch}" in \ + amd64) rustArch='x86_64-unknown-linux-gnu' ;; \ + armhf) rustArch='armv7-unknown-linux-gnueabihf' ;; \ + arm64) rustArch='aarch64-unknown-linux-gnu' ;; \ + i386) rustArch='i686-unknown-linux-gnu' ;; \ + *) echo >&2 "\e[0;31mUnsupported architecture: ${dpkgArch}\e[0m"; exit 1 ;; \ + esac; \ + gcc="gcc" \ + ;; \ + *) echo >&2 "\e[0;31mUnsupported architecture: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; exit 1 ;; \ + esac; \ + dpkg --add-architecture "${arch}" && \ + apt-get update && \ + apt-get install --assume-yes --no-install-recommends \ + build-essential \ + "${gcc}" \ + libgstrtspserver-1.0-dev:${arch} \ + libgstreamer1.0-dev:${arch} \ + libgtk2.0-dev:${arch} && \ + /bin/rm -rf /var/cache/apt && \ + /bin/rm -rf /var/lib/apt/lists/* && \ + rustup target add "${rustArch}" && \ + cargo build --release --all-features --target="${rustArch}" && \ + cp "/usr/local/src/neolink/target/${rustArch}/release/neolink" /neolink + +# Create the release container. +FROM --platform=$TARGETPLATFORM docker.io/debian:buster-slim + +ARG TARGETPLATFORM + +RUN apt-get update && \ + apt-get install --assume-yes --no-install-recommends \ + libgstrtspserver-1.0-0 \ + libgstreamer1.0-0 \ + libgstreamer-plugins-bad1.0-0 \ + gstreamer1.0-plugins-good \ + gstreamer1.0-plugins-bad \ + libglib2.0-0 && \ + /bin/rm -rf /var/cache/apt && \ + /bin/rm -rf /var/lib/apt/lists/* + +COPY --from=build \ + /neolink \ + /usr/local/bin/neolink +COPY docker/debian/entrypoint.sh /entrypoint.sh + +# Check that we can run the binary +# RUN ldd /usr/local/bin/neolink >&2 && /usr/local/bin/neolink --help >&2 + +CMD ["/usr/local/bin/neolink", "--config", "/etc/neolink.toml"] +ENTRYPOINT ["/entrypoint.sh"] +EXPOSE 8554 diff --git a/docker/debian/entrypoint.sh b/docker/debian/entrypoint.sh new file mode 100755 index 00000000..b7a0171c --- /dev/null +++ b/docker/debian/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Allows Ctrl-C, by letting this sh process act as PID 1 +exit_func() { + exit 1 +} +trap exit_func TERM INT + +"$@" From 58d458cac9496e63dd81cd0dd086722bf3c83f5e Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Mon, 21 Sep 2020 13:17:01 +0700 Subject: [PATCH 2/9] Use label rather than deprecated MAINTAINER in docker images --- .github/workflows/docker.yaml | 12 ++++++++++++ docker/alpine/Dockerfile | 17 ++++++++++++++++- docker/debian/Dockerfile | 19 +++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 24bdcf92..1222bc7d 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -56,6 +56,16 @@ jobs: echo "::set-output name=ALPTAGS::${alptags}" env: REPO_NAME: ${{ steps.string_repo.outputs.lowercase }} + - name: Install toml-cli + uses: actions-rs/install@v0.1 + with: + crate: toml-cli + version: latest + - name: Get project version + id: toml + run: | + NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')" + echo "::set-output name=version::${NEOLINK_VERSION}" - name: Push to Docker Hub Debian if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 @@ -64,6 +74,7 @@ jobs: push: true file: docker/debian/Dockerfile tags: ${{ steps.tags.outputs.DEBTAGS }} + build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ github.repository_owner }} - name: Push to Docker Hub Alpine if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 @@ -72,3 +83,4 @@ jobs: push: true file: docker/alpine/Dockerfile tags: ${{ steps.tags.outputs.ALPTAGS }} + build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ github.repository_owner }} diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile index de627647..62bfa4a6 100644 --- a/docker/alpine/Dockerfile +++ b/docker/alpine/Dockerfile @@ -3,7 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only FROM docker.io/rust:1-alpine AS build -MAINTAINER thirtythreeforty@gmail.com +ARG REPO +ARG VERSION +ARG OWNER + +LABEL description="An image for the neolink program which is a reolink camera to rtsp translator" +LABEL repository="$REPO" +LABEL version="$VERSION" +LABEL maintainer="$OWNER" RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ gst-rtsp-server-dev @@ -20,6 +27,14 @@ RUN cargo build --release # Create the release container. Match the base OS used to build FROM docker.io/alpine:latest +ARG REPO +ARG VERSION +ARG OWNER + +LABEL description="An image for the neolink program which is a reolink camera to rtsp translator" +LABEL repository="$REPO" +LABEL version="$VERSION" +LABEL maintainer="$OWNER" RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing libgcc \ tzdata \ diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index 73ab840e..4707e632 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -3,10 +3,17 @@ # SPDX-License-Identifier: AGPL-3.0-only FROM --platform=$BUILDPLATFORM docker.io/rust:slim-buster AS build -MAINTAINER thirtythreeforty@gmail.com - ARG TARGETPLATFORM ARG BUILDPLATFORM +ARG REPO +ARG VERSION +ARG OWNER + +LABEL description="An image for the neolink program which is a reolink camera to rtsp translator" +LABEL repository="$REPO" +LABEL version="$VERSION" +LABEL maintainer="$OWNER" + # ORIGINALY I TRIED TO BUILD IN A QEMU CONTAINER. # THIS WOULD HAVE BEEN IDEAL BECAUSE THEN WE COULD BUILD FOR ALL @@ -109,6 +116,14 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; FROM --platform=$TARGETPLATFORM docker.io/debian:buster-slim ARG TARGETPLATFORM +ARG REPO +ARG VERSION +ARG OWNER + +LABEL description="An image for the neolink program which is a reolink camera to rtsp translator" +LABEL repository="$REPO" +LABEL version="$VERSION" +LABEL maintainer="$OWNER" RUN apt-get update && \ apt-get install --assume-yes --no-install-recommends \ From 923ccaea70a9f3e99bb66e908af92cd3a48d3bb7 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 22 Sep 2020 12:18:29 +0700 Subject: [PATCH 3/9] Use correct env var for i686 cross compile --- docker/debian/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index 4707e632..6dfea12f 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -77,8 +77,8 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; arch="i386"; \ gcc="gcc-i686-linux-gnu"; \ export CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=i686-linux-gnu-gcc && \ - export CC_aarch64_unknown_linux_gnu=i686-linux-gnu-gcc && \ - export CXX_aarch64_unknown_linux_gnu=i686-linux-gnu-g++ && \ + export CC_i686_unknown_linux_gnu=i686-linux-gnu-gcc && \ + export CXX_i686_unknown_linux_gnu=i686-linux-gnu-g++ && \ export PKG_CONFIG_ALLOW_CROSS=1 && \ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ export PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ From a2aff83166ec33cfd0d187a92f12ec74703afbc7 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 25 Sep 2020 16:13:39 +0700 Subject: [PATCH 4/9] Include arm g++ cross compiler on arm build --- .github/workflows/armhf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/armhf.yml b/.github/workflows/armhf.yml index 9df00989..71c31681 100644 --- a/.github/workflows/armhf.yml +++ b/.github/workflows/armhf.yml @@ -19,7 +19,7 @@ jobs: - name: Install cross compile tools run: | sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends gcc-arm-linux-gnueabihf + sudo apt-get install --assume-yes --no-install-recommends gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf - name: Install armhf gstreamer run: | sudo apt-get update From 7aead1f83bd32d6e45c74e4671d80175f66fc050 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 25 Sep 2020 16:19:34 +0700 Subject: [PATCH 5/9] Include gpp cross compilers in docker --- docker/debian/Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index 6dfea12f..f8d23109 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -39,7 +39,8 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ rustArch='x86_64-unknown-linux-gnu'; \ arch="amd64"; \ - gcc="x86_64-linux-gnu-gcc"; \ + gcc=" gcc-x86-64-linux-gnu"; \ + gpp=" g++-x86-64-linux-gnu"; \ export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc && \ export CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc && \ export CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ && \ @@ -52,6 +53,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; rustArch='armv7-unknown-linux-gnueabihf'; \ arch="armhf"; \ gcc="gcc-arm-linux-gnueabihf"; \ + gpp="g++-arm-linux-gnueabihf"; \ export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc && \ export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc && \ export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ && \ @@ -64,6 +66,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; rustArch='aarch64-unknown-linux-gnu'; \ arch="arm64"; \ gcc="gcc-aarch64-linux-gnu"; \ + gpp="g++-aarch64-linux-gnu"; \ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc && \ export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc && \ export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ && \ @@ -76,6 +79,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; rustArch='i686-unknown-linux-gnu'; \ arch="i386"; \ gcc="gcc-i686-linux-gnu"; \ + gpp="g++-i686-linux-gnu"; \ export CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=i686-linux-gnu-gcc && \ export CC_i686_unknown_linux_gnu=i686-linux-gnu-gcc && \ export CXX_i686_unknown_linux_gnu=i686-linux-gnu-g++ && \ @@ -95,6 +99,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; *) echo >&2 "\e[0;31mUnsupported architecture: ${dpkgArch}\e[0m"; exit 1 ;; \ esac; \ gcc="gcc" \ + gpp="g++" \ ;; \ *) echo >&2 "\e[0;31mUnsupported architecture: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; exit 1 ;; \ esac; \ @@ -102,7 +107,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; apt-get update && \ apt-get install --assume-yes --no-install-recommends \ build-essential \ - "${gcc}" \ + "${gcc}" "${gpp}" \ libgstrtspserver-1.0-dev:${arch} \ libgstreamer1.0-dev:${arch} \ libgtk2.0-dev:${arch} && \ From 822e0cae8b30cf170008659bd4c99cafcb9b5668 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 6 Oct 2020 11:50:49 +0700 Subject: [PATCH 6/9] Attempt to add armv6 for those rasppi 1 friends --- .github/workflows/docker.yaml | 2 +- docker/debian/Dockerfile | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 1222bc7d..73542f54 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -70,7 +70,7 @@ jobs: if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 with: - platforms: linux/arm/v7,linux/arm64,linux/amd64,linux/386 + platforms: linux/arm/v7,linux/arm/v6,linux/arm64,linux/amd64,linux/386 push: true file: docker/debian/Dockerfile tags: ${{ steps.tags.outputs.DEBTAGS }} diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index f8d23109..621f7a39 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -15,9 +15,9 @@ LABEL version="$VERSION" LABEL maintainer="$OWNER" -# ORIGINALY I TRIED TO BUILD IN A QEMU CONTAINER. +# ORIGINALLY I TRIED TO BUILD IN A QEMU CONTAINER. # THIS WOULD HAVE BEEN IDEAL BECAUSE THEN WE COULD BUILD FOR ALL -# ARCH SUPPORTED BY QEMU, DEBIAN AND RUST WITHOUT ANY COMPICATED CROSS COMPILES. +# ARCH SUPPORTED BY QEMU, DEBIAN AND RUST WITHOUT ANY COMPLICATED CROSS COMPILES. # HOWEVER I KEPT GETTING THE FOLLOWING ERROR DURING COMPILE # could not read directory '/usr/local/cargo/registry/index/github.com-1285ae84e5963aae/.git//refs': Value too large for defined data type; class=Os (2) # Google suggest I should either update the kernel or my fs neither of which I can do on github actions @@ -61,6 +61,19 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ && \ export PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/; \ ;; \ + "linux/arm/v6") \ + echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ + rustArch='arm-unknown-linux-gnueabi'; \ + arch="armel"; \ + gcc="gcc-arm-linux-gnueabi"; \ + gpp="g++-arm-linux-gnueabi"; \ + export CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc && \ + export CC_arm_unknown_linux_gnueabi=arm-linux-gnueabi-gcc && \ + export CXX_arm_unknown_linux_gnueabi=arm-linux-gnueabi-g++ && \ + export PKG_CONFIG_ALLOW_CROSS=1 && \ + export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabi/pkgconfig:/usr/share/pkgconfig/ && \ + export PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabi/pkgconfig:/usr/share/pkgconfig/; \ + ;; \ "linux/arm64") \ echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ rustArch='aarch64-unknown-linux-gnu'; \ From 0c48fec95aadaa8da1557d77cbec330de1beedf4 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 9 Oct 2020 13:41:03 +0700 Subject: [PATCH 7/9] Trying to build via tmpfs Using buildkit to mount inside docker build --- .github/workflows/docker.yaml | 2 + docker/debian/Dockerfile | 99 +++-------------------------------- 2 files changed, 10 insertions(+), 91 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 73542f54..25bc70aa 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -75,6 +75,8 @@ jobs: file: docker/debian/Dockerfile tags: ${{ steps.tags.outputs.DEBTAGS }} build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ github.repository_owner }} + env: + DOCKER_BUILDKIT: 1 - name: Push to Docker Hub Alpine if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index 621f7a39..ea680c85 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -1,10 +1,10 @@ # Neolink Docker image build scripts # Copyright (c) 2020 George Hilliard # SPDX-License-Identifier: AGPL-3.0-only +# syntax=docker/dockerfile:experimental FROM --platform=$BUILDPLATFORM docker.io/rust:slim-buster AS build ARG TARGETPLATFORM -ARG BUILDPLATFORM ARG REPO ARG VERSION ARG OWNER @@ -28,95 +28,12 @@ WORKDIR /usr/local/src/neolink # Build the main program COPY . /usr/local/src/neolink -RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; \ - if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ]; then \ - target="native"; \ - else \ - target="${TARGETPLATFORM}"; \ - fi; \ - case "${target}" in \ - "linux/amd64") \ - echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - rustArch='x86_64-unknown-linux-gnu'; \ - arch="amd64"; \ - gcc=" gcc-x86-64-linux-gnu"; \ - gpp=" g++-x86-64-linux-gnu"; \ - export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc && \ - export CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc && \ - export CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ && \ - export PKG_CONFIG_ALLOW_CROSS=1 && \ - export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ - export PKG_CONFIG_LIBDIR=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ - ;; \ - "linux/arm/v7") \ - echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - rustArch='armv7-unknown-linux-gnueabihf'; \ - arch="armhf"; \ - gcc="gcc-arm-linux-gnueabihf"; \ - gpp="g++-arm-linux-gnueabihf"; \ - export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc && \ - export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc && \ - export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ && \ - export PKG_CONFIG_ALLOW_CROSS=1 && \ - export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ && \ - export PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/; \ - ;; \ - "linux/arm/v6") \ - echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - rustArch='arm-unknown-linux-gnueabi'; \ - arch="armel"; \ - gcc="gcc-arm-linux-gnueabi"; \ - gpp="g++-arm-linux-gnueabi"; \ - export CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc && \ - export CC_arm_unknown_linux_gnueabi=arm-linux-gnueabi-gcc && \ - export CXX_arm_unknown_linux_gnueabi=arm-linux-gnueabi-g++ && \ - export PKG_CONFIG_ALLOW_CROSS=1 && \ - export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabi/pkgconfig:/usr/share/pkgconfig/ && \ - export PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabi/pkgconfig:/usr/share/pkgconfig/; \ - ;; \ - "linux/arm64") \ - echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - rustArch='aarch64-unknown-linux-gnu'; \ - arch="arm64"; \ - gcc="gcc-aarch64-linux-gnu"; \ - gpp="g++-aarch64-linux-gnu"; \ - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc && \ - export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc && \ - export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ && \ - export PKG_CONFIG_ALLOW_CROSS=1 && \ - export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ - export PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ - ;; \ - "linux/386") \ - echo >&2 "\e[0;32mBUILDING for ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - rustArch='i686-unknown-linux-gnu'; \ - arch="i386"; \ - gcc="gcc-i686-linux-gnu"; \ - gpp="g++-i686-linux-gnu"; \ - export CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=i686-linux-gnu-gcc && \ - export CC_i686_unknown_linux_gnu=i686-linux-gnu-gcc && \ - export CXX_i686_unknown_linux_gnu=i686-linux-gnu-g++ && \ - export PKG_CONFIG_ALLOW_CROSS=1 && \ - export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/ && \ - export PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/; \ - ;; \ - "native") \ - echo >&2 "\e[0;32mNot cross compiling: ${TARGETPLATFORM} on ${BUILDPLATFORM}\e[0m"; \ - dpkgArch="$(dpkg --print-architecture)"; \ - arch="${dpkgArch##*-}"; \ - case "${arch}" in \ - amd64) rustArch='x86_64-unknown-linux-gnu' ;; \ - armhf) rustArch='armv7-unknown-linux-gnueabihf' ;; \ - arm64) rustArch='aarch64-unknown-linux-gnu' ;; \ - i386) rustArch='i686-unknown-linux-gnu' ;; \ - *) echo >&2 "\e[0;31mUnsupported architecture: ${dpkgArch}\e[0m"; exit 1 ;; \ - esac; \ - gcc="gcc" \ - gpp="g++" \ - ;; \ - *) echo >&2 "\e[0;31mUnsupported architecture: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; exit 1 ;; \ - esac; \ - dpkg --add-architecture "${arch}" && \ +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +RUN --mount=type=tmpfs,destination=/usr/local/cargo/ \ + echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; \ apt-get update && \ apt-get install --assume-yes --no-install-recommends \ build-essential \ @@ -127,7 +44,7 @@ RUN echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; /bin/rm -rf /var/cache/apt && \ /bin/rm -rf /var/lib/apt/lists/* && \ rustup target add "${rustArch}" && \ - cargo build --release --all-features --target="${rustArch}" && \ + cargo build --release --all-features && \ cp "/usr/local/src/neolink/target/${rustArch}/release/neolink" /neolink # Create the release container. From cbffebebfbad8b87216d70c73acaeeb6fbddd49b Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 9 Oct 2020 14:00:36 +0700 Subject: [PATCH 8/9] Install rust into the tmpfs --- docker/debian/Dockerfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index ea680c85..5e2351ac 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # syntax=docker/dockerfile:experimental -FROM --platform=$BUILDPLATFORM docker.io/rust:slim-buster AS build +FROM --platform=$BUILDPLATFORM docker.io/debian:buster-slim ARG TARGETPLATFORM ARG REPO ARG VERSION @@ -33,19 +33,25 @@ ENV RUSTUP_HOME=/usr/local/rustup \ PATH=/usr/local/cargo/bin:$PATH RUN --mount=type=tmpfs,destination=/usr/local/cargo/ \ - echo >&2 "\e[0;32mRUNNING: ${TARGETPLATFORM} ${BUILDPLATFORM} ${arch}\e[0m"; \ + echo >&2 "\e[0;32mBUILDING FOR: ${TARGETPLATFORM}\e[0m"; \ + echo >&2 "\e[0;33mUpdating apt\e[0m"; \ apt-get update && \ + echo >&2 "\e[0;33mInstalling packages\e[0m"; \ apt-get install --assume-yes --no-install-recommends \ build-essential \ "${gcc}" "${gpp}" \ - libgstrtspserver-1.0-dev:${arch} \ - libgstreamer1.0-dev:${arch} \ - libgtk2.0-dev:${arch} && \ + curl ca-certificates build-essential \ + libgstrtspserver-1.0-dev \ + libgstreamer1.0-dev \ + libgtk2.0-dev && \ /bin/rm -rf /var/cache/apt && \ /bin/rm -rf /var/lib/apt/lists/* && \ - rustup target add "${rustArch}" && \ + echo >&2 "\e[0;33mInstalling rust\e[0m"; \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustinit.sh && \ + sh rustinit.sh --verbose -y && \ + echo >&2 "\e[0;33mBuilding neolink\e[0m"; \ cargo build --release --all-features && \ - cp "/usr/local/src/neolink/target/${rustArch}/release/neolink" /neolink + cp "/usr/local/src/neolink/target/release/neolink" /neolink # Create the release container. FROM --platform=$TARGETPLATFORM docker.io/debian:buster-slim @@ -72,7 +78,7 @@ RUN apt-get update && \ /bin/rm -rf /var/lib/apt/lists/* COPY --from=build \ - /neolink \ + /usr/local/src/neolink/target/release/neolink \ /usr/local/bin/neolink COPY docker/debian/entrypoint.sh /entrypoint.sh From d95885ac0ab1b5fe6965918aa4515a6d8ca12ea3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 17 Oct 2020 16:48:46 +0700 Subject: [PATCH 9/9] Disable armv6 because there is not debian docker with it Put back in missing AS name Debugging the issue with docker... Explicit cargo path Attempt setting exec on tmpfs Avoid execfs issues Just use the setup path env Typo fix in docker build More debuging of the docker build Just amd64 and arm7 Explicitly set cacert path Add arm v8 Add arm v6 Remove armv6 --- .github/workflows/docker.yaml | 2 +- docker/debian/Dockerfile | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 25bc70aa..240748c5 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -70,7 +70,7 @@ jobs: if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 with: - platforms: linux/arm/v7,linux/arm/v6,linux/arm64,linux/amd64,linux/386 + platforms: linux/arm/v7,linux/arm/v8,linux/amd64 push: true file: docker/debian/Dockerfile tags: ${{ steps.tags.outputs.DEBTAGS }} diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile index 5e2351ac..27eeffce 100644 --- a/docker/debian/Dockerfile +++ b/docker/debian/Dockerfile @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # syntax=docker/dockerfile:experimental -FROM --platform=$BUILDPLATFORM docker.io/debian:buster-slim +FROM docker.io/debian:buster-slim AS build ARG TARGETPLATFORM ARG REPO ARG VERSION @@ -30,26 +30,31 @@ COPY . /usr/local/src/neolink ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH + PATH=/usr/local/cargo/bin:$PATH \ + CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt -RUN --mount=type=tmpfs,destination=/usr/local/cargo/ \ +RUN --mount=type=tmpfs,destination=/usr/local/cargo/registry/ \ + --mount=type=tmpfs,destination=/usr/local/cargo/git/ \ echo >&2 "\e[0;32mBUILDING FOR: ${TARGETPLATFORM}\e[0m"; \ echo >&2 "\e[0;33mUpdating apt\e[0m"; \ apt-get update && \ echo >&2 "\e[0;33mInstalling packages\e[0m"; \ apt-get install --assume-yes --no-install-recommends \ build-essential \ - "${gcc}" "${gpp}" \ curl ca-certificates build-essential \ libgstrtspserver-1.0-dev \ libgstreamer1.0-dev \ libgtk2.0-dev && \ /bin/rm -rf /var/cache/apt && \ /bin/rm -rf /var/lib/apt/lists/* && \ + update-ca-certificates && \ echo >&2 "\e[0;33mInstalling rust\e[0m"; \ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustinit.sh && \ sh rustinit.sh --verbose -y && \ echo >&2 "\e[0;33mBuilding neolink\e[0m"; \ + echo >&2 "\e[0;34mPATH: ${PATH} \e[0m"; \ + echo >&2 "\e[0;35mmount: $(mount | grep tmpfs) \e[0m"; \ + echo >&2 "\e[0;36mls: $(ls -lha /usr/local/cargo/bin) \e[0m"; \ cargo build --release --all-features && \ cp "/usr/local/src/neolink/target/release/neolink" /neolink