From decec48293989c4f2e787a1c6a9e199f839fcb19 Mon Sep 17 00:00:00 2001 From: sfeakes Date: Fri, 31 May 2024 16:42:13 -0500 Subject: [PATCH] Update --- docker/Dockerfile | 5 +- docker/Dockerfile.buildx | 105 ++++++++++++++++++++++++++++++++++++++ docker/buildx.sh | 46 +++++++++++++++++ docker/docker-compose.yml | 16 +++--- 4 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 docker/Dockerfile.buildx create mode 100644 docker/buildx.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index ec8594c..15e5dd9 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,10 @@ ##################################### # # Build container -# The most basic build for aqualinkd latest version +# The most basic build for aqualinkd +# +# env AQUALINKD_VERSION must be passed to this +# ##################################### FROM debian:bookworm AS aqualinkd-build diff --git a/docker/Dockerfile.buildx b/docker/Dockerfile.buildx new file mode 100644 index 0000000..4d9e898 --- /dev/null +++ b/docker/Dockerfile.buildx @@ -0,0 +1,105 @@ +##################################### +# +# Create AqualinkD container for release (includes AMD64 and ARM64 for >Pi4 with 64 bit os and Linux PC) +# Build container for buildx +# This should support building on any host platform, but only supports output platform of amd64 & arm64 +# +# Enable multi platform +# docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder +# docker buildx inspect --bootstrap +# +# Build +# docker buildx build --platform=linux/amd64,linux/arm64 --output=./crap --file /Dockerfile.test -t aqualinkd-test . +# docker buildx build --platform=linux/amd64,linux/arm64 --file Dockerfile.test --output type=docker -t aqualinkd-test . +# docker build --file Dockerfile.test --progress=plain -t aqualinkd-test . +# +# adding --progress=plain helps with debug +# +# Clean the build env and start again +# docker buildx prune +# +# +# docker build -f ./Dockerfile.buildrelease . +# +##################################### + + +# Starting with base debian:bookworm and installing build-essential seems to be quicker than starting with gcc:bookworm +#FROM --platform=$BUILDPLATFORM gcc:12-bookworm AS aqualinkd-build +FROM --platform=$BUILDPLATFORM debian:bookworm AS aqualinkd-build + +ARG BUILDARCH +ARG TARGETARCH + +# Print all buildx variables +RUN echo "Build Arch $BUILDARCH" && \ + echo "Tagert OS $TARGETOS" + +# Setup build env, using toolchain for all builds, even native, since make this Dockerfile cleaner +# and no need to use bash if statments. +# Need to be careful on install order, so using two commands + +RUN apt-get update && \ + apt-get install -y \ + make \ + curl \ + gcc-aarch64-linux-gnu \ + gcc-x86-64-linux-gnu + +RUN dpkg --add-architecture arm64 && \ + dpkg --add-architecture amd64 && \ + apt-get update && \ + apt-get install -y \ + libsystemd-dev:arm64 \ + libsystemd-dev:amd64 + + +RUN mkdir /home/AqualinkD +WORKDIR /home/AqualinkD + + +ARG AQUALINKD_VERSION +RUN curl -sL "https://github.com/sfeakes/AqualinkD/archive/refs/tags/$AQUALINKD_VERSION.tar.gz" | tar xz --strip-components=1 +# Get latest release +#RUN curl -sL $(curl -s https://api.github.com/repos/sfeakes/AqualinkD/releases/latest | grep "tarball_url" | cut -d'"' -f4) | tar xz --strip-components=1 + + +# Make AqualinkD +RUN make clean && \ + make container-$TARGETARCH; + +##################################### +# +# Runtime container(s) +# +##################################### + +FROM debian:bookworm-slim AS aqualinkd + +RUN apt-get update \ + && apt-get install -y cron curl socat + +# Set cron to read local.d +RUN sed -i '/EXTRA_OPTS=.-l./s/^#//g' /etc/default/cron + +#Add Open Container Initiative (OCI) annotations. +#See: https://github.com/opencontainers/image-spec/blob/main/annotations.md + +LABEL org.opencontainers.image.title="AqualinkD" +LABEL org.opencontainers.image.url="https://hub.docker.com/repository/docker/sfeakes/aqualinkd/general" +LABEL org.opencontainers.image.source="https://github.com/sfeakes/AqualinkD" +LABEL org.opencontainers.image.documentation="https://github.com/sfeakes/AqualinkD" +LABEL org.opencontainers.image.version=$AQUALINKD_VERSION + +EXPOSE 80/tcp + +COPY --from=aqualinkd-build /home/AqualinkD/release/aqualinkd /usr/local/bin/aqualinkd +COPY --from=aqualinkd-build /home/AqualinkD/release/serial_logger /usr/local/bin/serial_logger +COPY --from=aqualinkd-build /home/AqualinkD/web/ /var/www/aqualinkd/ +COPY --from=aqualinkd-build /home/AqualinkD/release/aqualinkd.conf /etc/aqualinkd.conf + +COPY --from=aqualinkd-build /home/AqualinkD/docker/aqualinkd-docker.cmd /usr/local/bin/aqualinkd-docker + +RUN chmod +x /usr/local/bin/aqualinkd-docker + +CMD ["sh", "-c", "/usr/local/bin/aqualinkd-docker"] diff --git a/docker/buildx.sh b/docker/buildx.sh new file mode 100644 index 0000000..4bf8438 --- /dev/null +++ b/docker/buildx.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# Script to build arm64 & amd64 containers that are published to docker.io +# + +IMAGE=aqualinkd + +if [ $# -eq 0 ] + then + # Below is safer, but not supported on all platforms. + #VERSION=$(curl --silent "https://api.github.com/repos/sfeakes/AqualinkD/releases/latest" | grep -Po '"tag_name": "[^0-9|v|V]*\K.*?(?=")') + VERSION=$(curl --silent "https://api.github.com/repos/sfeakes/AqualinkD/releases/latest" | grep "tag_name" | awk -F'"' '$0=$4') + else + VERSION=$1 +fi + +URL="https://github.com/sfeakes/AqualinkD/archive/refs/tags/"$VERSION".tar.gz" +URL2="https://github.com/sfeakes/AqualinkD/archive/refs/tags/v"$VERSION".tar.gz" +URL3="https://github.com/sfeakes/AqualinkD/archive/refs/tags/V"$VERSION".tar.gz" +#BURL="https://github.com/sfeakes/AqualinkD/archive/refs/heads/"$VERSION".tar.gz" + +# Check version is accurate before running docker build + +if ! curl --output /dev/null --silent --location --head --fail "$URL"; then + # Check if version tag has wrong case + if curl --output /dev/null --silent --location --head --fail "$URL2"; then + VERSION=v$VERSION + else + # Check if it's a branch + if curl --output /dev/null --silent --location --head --fail "$URL3"; then + VERSION=V$VERSION + else + echo "ERROR Can't build Docker container for $IMAGE $VERSION" + echo -e "Neither Version or Branch URLs:- \n $URL \n $URL2 \n $URL3" + exit 1 + fi + fi +fi + +echo "Building Docker container for $IMAGE using branch $VERSION" +docker buildx build --platform=linux/amd64,linux/arm64 \ + --file Dockerfile.buildx \ + -t docker.io/sfeakes/${IMAGE}:${VERSION} \ + -t docker.io/sfeakes/${IMAGE}:latest \ + --build-arg AQUALINKD_VERSION=${VERSION} \ + --push . \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 55d55b6..94448b2 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,13 +1,13 @@ services: aqualinkd: - #image: sfeakes/aqualinkd:latest - build: - context: https://github.com/sfeakes/AqualinkD.git#master:docker - args: - AQUALINKD_VERSION: v2.3.6 # Make sure to change to correct version - tags: - - aqualinkd:v2.3.6 - container_name: aqualinkd + image: sfeakes/aqualinkd:latest + #build: + # context: https://github.com/sfeakes/AqualinkD.git#master:docker + # args: + # AQUALINKD_VERSION: v2.3.6 # Make sure to change to correct version + # tags: + # - aqualinkd:v2.3.6 + container_name: aqualinkd ports: - "6171:80" volumes: