From de2c1e5883b429294822fd1d04474b77548f2e8f Mon Sep 17 00:00:00 2001 From: Hans van Essen Date: Wed, 31 Jan 2024 11:26:37 +0100 Subject: [PATCH] Worked on multiarch build --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ pgadmin4/Dockerfile | 39 ++++++++++++++++++++++++++------------- pgadmin4/build.sh | 40 ++++++++++++++++++++++++++++++++-------- pgadmin4/build.yaml | 2 ++ pgadmin4/config.yaml | 1 - 5 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b43d38b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +ARG BUILD_FROM=ghcr.io/hassio-addons/base/aarch64:15.0.5 + +FROM ${BUILD_FROM} + +ARG TARGETPLATFORM +ARG CACHEBUST +ARG TARGETARCH + +RUN --mount=type=cache,id=test-${TARGETARCH},sharing=locked,target=/root/.cache \ + echo "$CACHEBUST" > /root/.cache/cachebust-${TARGETARCH} && \ + ls -l /root/.cache + +RUN --mount=type=cache,id=test-${TARGETARCH},sharing=locked,target=/root/.cache \ + echo "$CACHEBUST" > /root/.cache/cachebust-${TARGETARCH} && \ + ls -l /root/.cache && \ + echo "$CACHEBUST" > /root/.cache/x-${TARGETARCH}.txt && \ + ls -l /root/.cache + +FROM ${BUILD_FROM} + +ARG TARGETPLATFORM +ARG CACHEBUST +ARG TARGETARCH + +RUN --mount=type=cache,id=test-${TARGETARCH},sharing=locked,target=/root/.cache \ + echo "$CACHEBUST" > /root/.cache/cachebust-${TARGETARCH} && \ + ls -l /root/.cache + +RUN --mount=type=cache,id=test-${TARGETARCH},sharing=locked,target=/root/.cache \ + echo "$CACHEBUST" > /root/.cache/cachebust-${TARGETARCH} && \ + ls -l /root/.cache && \ + echo "$CACHEBUST" > /root/.cache/x-${TARGETARCH}.txt && \ + ls -l /root/.cache + + +#docker buildx build --push --platform linux/aarch64,linux/amd64 --cache-from husselhans/test:cache --cache-to husselhans/test:cache,mode=max --progress=plain . --tag husselhans/test:latest --build-arg CACHEBUST=$(date +%s) \ No newline at end of file diff --git a/pgadmin4/Dockerfile b/pgadmin4/Dockerfile index 334871d..5a62157 100644 --- a/pgadmin4/Dockerfile +++ b/pgadmin4/Dockerfile @@ -81,11 +81,12 @@ RUN \ ######################################################################### FROM alpine:latest as env-builder - +ARG TARGETARCH +ARG TARGETVARIANT # Install dependencies COPY official-pgadmin4/requirements.txt / -RUN --mount=type=cache,id=apk-$TARGETPLATFORM,sharing=locked,target=/var/cache/apk \ +RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk \ apk add \ make \ python3 \ @@ -103,7 +104,8 @@ RUN --mount=type=cache,id=apk-$TARGETPLATFORM,sharing=locked,target=/var/cache/a libjpeg-turbo-dev \ libpng-dev \ python3-dev -RUN --mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache \ + +RUN --mount=type=cache,id=pip-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache \ python3 -m venv --system-site-packages --without-pip /venv && \ #/venv/bin/python3 -m pip install setuptools && \ /venv/bin/python3 -m pip install -r requirements.txt && \ @@ -114,9 +116,10 @@ RUN --mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache ######################################################################### FROM env-builder as docs-builder - +ARG TARGETARCH +ARG TARGETVARIANT # Install Sphinx -RUN --mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache \ +RUN --mount=type=cache,id=pip-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache \ /venv/bin/python3 -m pip install sphinx && \ /venv/bin/python3 -m pip install sphinxcontrib-youtube @@ -176,6 +179,8 @@ COPY --from=pg16-builder /usr/local/bin/psql /usr/local/pgsql/pgsql-16/ # Assemble everything into the final container. ######################################################################### FROM $BUILD_FROM +ARG TARGETARCH +ARG TARGETVARIANT # Copy in the Python packages COPY --from=env-builder /venv /venv @@ -189,8 +194,7 @@ COPY --from=pg16-builder /usr/lib/liblz4.so.1.9.4 /usr/lib/ RUN ln -s libpq.so.5.16 /usr/lib/libpq.so.5 && \ ln -s libpq.so.5.16 /usr/lib/libpq.so && \ ln -s libzstd.so.1.5.5 /usr/lib/libzstd.so.1 && \ - ln -s liblz4.so.1.9.4 /usr/lib/liblz4.so.1 - + ln -s liblz4.so.1.9.4 /usr/lib/liblz4.so.1 && echo jeej WORKDIR /pgadmin4 ENV PYTHONPATH=/pgadmin4 @@ -198,6 +202,10 @@ ENV PYTHONPATH=/pgadmin4 # Copy in the code and docs COPY --from=app-builder /pgadmin4/web /pgadmin4 COPY --from=docs-builder /pgadmin4/docs/en_US/_build/html/ /pgadmin4/docs + +# Dumb fix for a docker build: https://github.com/moby/moby/issues/37965 +RUN true + COPY official-pgadmin4/pkg/docker/run_pgadmin.py /pgadmin4 COPY official-pgadmin4/pkg/docker/gunicorn_config.py /pgadmin4 #COPY official-pgadmin4/pkg/docker/entrypoint.sh /entrypoint.sh @@ -207,8 +215,9 @@ COPY official-pgadmin4/LICENSE /pgadmin4/LICENSE COPY official-pgadmin4/DEPENDENCIES /pgadmin4/DEPENDENCIES # Install runtime dependencies and configure everything in one RUN step -RUN --mount=type=cache,id=apk-$TARGETPLATFORM,target=/var/cache/apk \ - apk --force-broken-world add \ +RUN --mount=type=cache,id=final-apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk \ + apk add \ + apk-tools \ python3 \ py3-pip \ postfix \ @@ -220,9 +229,11 @@ RUN --mount=type=cache,id=apk-$TARGETPLATFORM,target=/var/cache/apk \ libedit \ libldap \ libcap -RUN --mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache \ - /venv/bin/python3 -m pip install --no-cache-dir gunicorn==20.1.0 && \ - find / -type d -name '__pycache__' -exec rm -rf {} + && \ + +RUN --mount=type=cache,id=pip-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache \ + /venv/bin/python3 -m pip install gunicorn==20.1.0 + +RUN find / -type d -name '__pycache__' -exec rm -rf {} + && \ useradd -r -u 5050 -g root -s /sbin/nologin pgadmin && \ mkdir -p /var/lib/pgadmin && \ chown pgadmin:root /var/lib/pgadmin && \ @@ -240,7 +251,8 @@ RUN --mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache # -------------------------------------- # Install NGINX for Ingress support -RUN apk add --no-cache \ +RUN --mount=type=cache,id=final-apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk \ + apk add \ git \ lua-resty-http \ nginx-mod-http-lua \ @@ -266,6 +278,7 @@ RUN chmod +x /etc/cont-init.d/* \ && chmod +x /etc/services.d/nginx/* \ && chmod +x /etc/services.d/pgadmin4/* +#Disabled the special user, because we need to have a lot more in place to move away from ROOT #USER pgadmin WORKDIR / diff --git a/pgadmin4/build.sh b/pgadmin4/build.sh index 395ce39..e8129ef 100755 --- a/pgadmin4/build.sh +++ b/pgadmin4/build.sh @@ -12,12 +12,36 @@ fi # Print the result echo "Building version '$version' for platforms '$archs'" +# error: failed to solve: ghcr.io/hassio-addons/base/armv7:15.0.5: error getting credentials - err: exec: "docker-credential-desktop.exe": executable file not found in $PATH, out: ` +#Solution: +#In ~/.docker/config.json change credsStore to credStore + + +#docker run --rm --privileged \ +# -v ~/.docker:/root/.docker \ +# -v /var/run/docker.sock:/var/run/docker.sock \ +# -v ~/hassos-addon-pgadmin4/pgadmin4:/data homeassistant/amd64-builder \ +# --addon \ +# --target pgadmin4 \ +# --all \ +# --cache-tag cache \ +# -t /data + # Build and Push -# -docker buildx build \ - --push \ - --platform aarch64 \ - --cache-from type=registry,ref=husselhans/hassos-addon-pgadmin4:cache \ - --cache-to type=registry,ref=husselhans/hassos-addon-pgadmin4:cache \ - --tag husselhans/hassos-addon-pgadmin4:$version \ - . + +# For each arch in config.yaml, run the buildx build command + +# Get the archs from the config.yaml file using yq +for arch in $(yq -r '.arch[]' config.yaml); do + echo "Building for: $arch" + # build the image + docker buildx build \ + --push \ + --platform linux/$arch \ + --cache-from type=registry,ref=husselhans/hassos-addon-pgadmin4:cache \ + --cache-to type=registry,ref=husselhans/hassos-addon-pgadmin4:cache,mode=max \ + --tag husselhans/hassos-addon-pgadmin4-$arch:$version \ + --build-arg BUILD_FROM=ghcr.io/hassio-addons/base/$arch:15.0.5 \ + --progress plain \ + . +done diff --git a/pgadmin4/build.yaml b/pgadmin4/build.yaml index 7e41e92..ebc0123 100644 --- a/pgadmin4/build.yaml +++ b/pgadmin4/build.yaml @@ -5,3 +5,5 @@ build_from: armhf: ghcr.io/hassio-addons/base/armhf:15.0.5 armv7: ghcr.io/hassio-addons/base/armv7:15.0.5 i386: ghcr.io/hassio-addons/base/i386:15.0.5 +#args: +# my_build_arg: xy \ No newline at end of file diff --git a/pgadmin4/config.yaml b/pgadmin4/config.yaml index 7f5e4be..f11ba1f 100644 --- a/pgadmin4/config.yaml +++ b/pgadmin4/config.yaml @@ -8,7 +8,6 @@ arch: - aarch64 - amd64 - armhf - - armv7 - i386 startup: application ingress: true