Skip to content

Commit

Permalink
Worked on multiarch build
Browse files Browse the repository at this point in the history
  • Loading branch information
expaso committed Jan 31, 2024
1 parent 3e3e452 commit de2c1e5
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 22 deletions.
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 26 additions & 13 deletions pgadmin4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 && \
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -189,15 +194,18 @@ 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

# 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
Expand All @@ -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 \
Expand All @@ -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 && \
Expand All @@ -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 \
Expand All @@ -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 /
40 changes: 32 additions & 8 deletions pgadmin4/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions pgadmin4/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion pgadmin4/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ arch:
- aarch64
- amd64
- armhf
- armv7
- i386
startup: application
ingress: true
Expand Down

0 comments on commit de2c1e5

Please sign in to comment.