Skip to content

Commit

Permalink
Worked on build cache and new pgAdmin patches
Browse files Browse the repository at this point in the history
  • Loading branch information
expaso committed Jan 25, 2024
1 parent 8fe46c3 commit 3169ebc
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To build the lastest version using local docker, switch to the folder where the `dockerfile` resides, and run:

```
docker build --plarform linux/aarch64 --tag husselhans/hassos-addon-pgadmin4-aarch64:dev .
./build.sh
```
The dockerfile already contains the default build architecture and the default base image:

Expand Down
157 changes: 84 additions & 73 deletions pgadmin4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG BUILD_FROM=ghcr.io/hassio-addons/base/aarch64:15.0.5
ARG BUILD_ARCH=aarch64

#Source: https://github.com/postgres/pgadmin4/blob/master/Dockerfile
########################################################################
Expand All @@ -11,27 +10,26 @@ ARG BUILD_ARCH=aarch64
#
#########################################################################

FROM alpine:latest as app-builder

RUN apk add --no-cache \
autoconf \
automake \
bash \
g++ \
git \
libc6-compat \
libjpeg-turbo-dev \
libpng-dev \
libtool \
make \
nasm \
nodejs \
npm \
yarn \
zlib-dev \
gcompat
# GCompat only needed for local docker builds instead of building through github-actione CI/CD
FROM --platform=$BUILDPLATFORM alpine:latest as app-builder

RUN \
--mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \
apk add \
autoconf \
automake \
bash \
g++ \
git \
libc6-compat \
libjpeg-turbo-dev \
libpng-dev \
libtool \
make \
nasm \
nodejs \
npm \
yarn \
zlib-dev

# Create the /pgadmin4 directory and copy the source into it. Explicitly
# remove the node_modules directory as we'll recreate a clean version, as well
Expand Down Expand Up @@ -61,20 +59,23 @@ RUN git apply -v pgAdmin.patch
WORKDIR /pgadmin4/web

# Build the JS vendor code in the app-builder, and then remove the vendor source.
RUN export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
yarn set version berry && \
yarn set version 3 && \
yarn install && \
yarn run bundle && \
rm -rf node_modules \
yarn.lock \
package.json \
.[^.]* \
babel.cfg \
webpack.* \
jest.config.js \
babel.* \
./pgadmin/static/js/generated/.cache
RUN \
--mount=type=cache,id=yarn,sharing=locked,target=/root/.yarn \
export YARN_CACHE_FOLDER=/root/.yarn && \
export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
yarn set version berry && \
yarn set version 3 && \
yarn install && \
yarn run bundle && \
rm -rf node_modules \
yarn.lock \
package.json \
.[^.]* \
babel.cfg \
webpack.* \
jest.config.js \
babel.* \
./pgadmin/static/js/generated/.cache

#########################################################################
# Next, create the base environment for Python
Expand All @@ -85,27 +86,31 @@ FROM alpine:latest as env-builder
# Install dependencies
COPY official-pgadmin4/requirements.txt /

RUN apk add --no-cache \
make \
python3 \
py3-pip && \
apk add --no-cache --virtual build-deps \
build-base \
openssl-dev \
libffi-dev \
postgresql-dev \
krb5-dev \
rust \
git \
cargo \
zlib-dev \
libjpeg-turbo-dev \
libpng-dev \
python3-dev && \
python3 -m venv --system-site-packages --without-pip /venv && \
#/venv/bin/python3 -m pip install --no-cache-dir setuptools && \
/venv/bin/python3 -m pip install --no-cache-dir -r requirements.txt && \
apk del --no-cache build-deps
RUN \
--mount=type=cache,id=apk-$TARGETPLATFORM,sharing=locked,target=/var/cache/apk \
apk add \
make \
python3 \
py3-pip && \
apk add --virtual build-deps \
build-base \
openssl-dev \
libffi-dev \
postgresql-dev \
krb5-dev \
rust \
git \
cargo \
zlib-dev \
libjpeg-turbo-dev \
libpng-dev \
python3-dev
RUN \
--mount=type=cache,id=pip-$TARGETPLATFORM,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 && \
apk del build-deps

#########################################################################
# Now, create a documentation build container for the Sphinx docs
Expand All @@ -114,8 +119,10 @@ RUN apk add --no-cache \
FROM env-builder as docs-builder

# Install Sphinx
RUN /venv/bin/python3 -m pip install --no-cache-dir sphinx
RUN /venv/bin/python3 -m pip install --no-cache-dir sphinxcontrib-youtube
RUN \
--mount=type=cache,id=pip-$TARGETPLATFORM,sharing=locked,target=/root/.cache \
/venv/bin/python3 -m pip install sphinx && \
/venv/bin/python3 -m pip install sphinxcontrib-youtube

# Copy the docs from the local tree. Explicitly remove any existing builds that
# may be present
Expand Down Expand Up @@ -204,7 +211,9 @@ COPY official-pgadmin4/LICENSE /pgadmin4/LICENSE
COPY official-pgadmin4/DEPENDENCIES /pgadmin4/DEPENDENCIES

# Install runtime dependencies and configure everything in one RUN step
RUN apk add \
RUN \
--mount=type=cache,id=apk-$TARGETPLATFORM,target=/var/cache/apk \
apk add \
python3 \
py3-pip \
postfix \
Expand All @@ -215,20 +224,22 @@ RUN apk add \
tzdata \
libedit \
libldap \
libcap && \
/venv/bin/python3 -m pip install --no-cache-dir gunicorn==20.1.0 && \
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 && \
chmod g=u /var/lib/pgadmin && \
touch /pgadmin4/config_distro.py && \
chown pgadmin:root /pgadmin4/config_distro.py && \
chmod g=u /pgadmin4/config_distro.py && \
chmod g=u /etc/passwd && \
setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python3.11 && \
echo "pgadmin ALL = NOPASSWD: /usr/sbin/postfix start" > /etc/sudoers.d/postfix && \
echo "pgadminr ALL = NOPASSWD: /usr/sbin/postfix start" >> /etc/sudoers.d/postfix
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 {} + && \
useradd -r -u 5050 -g root -s /sbin/nologin pgadmin && \
mkdir -p /var/lib/pgadmin && \
chown pgadmin:root /var/lib/pgadmin && \
chmod g=u /var/lib/pgadmin && \
touch /pgadmin4/config_distro.py && \
chown pgadmin:root /pgadmin4/config_distro.py && \
chmod g=u /pgadmin4/config_distro.py && \
chmod g=u /etc/passwd && \
setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python3.11 && \
echo "pgadmin ALL = NOPASSWD: /usr/sbin/postfix start" > /etc/sudoers.d/postfix && \
echo "pgadminr ALL = NOPASSWD: /usr/sbin/postfix start" >> /etc/sudoers.d/postfix

# --------------------------------------
# Finish image (Different from official pgAdmin)
Expand Down
24 changes: 24 additions & 0 deletions pgadmin4/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

#sudo apt-get install yq jq

archs=linux/$(yq -r '.arch | join(",linux/")' config.yaml)
version=$(yq -r '.version' config.yaml)

if [ -n "$1" ]; then
archs=$1
fi


# Print the result
echo "Building version '$version' for platforms '$archs'"

# Build and Push
# --cache-to type=registry,ref=husselhans/hassos-addon-pgadmin4:cache,mode=max \
docker \
buildx build \
--push \
--platform linux/aarch64 \
--cache-from type=registry,ref=husselhans/hassos-addon-pgadmin4:cache \
--tag husselhans/hassos-addon-pgadmin4:$version \
.
12 changes: 6 additions & 6 deletions pgadmin4/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ slug: pgadmin4
description: A PostgreSQL Management and Query tool
url: https://github.com/Expaso/hassos-addon-pgadmin4
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
- aarch64
# - amd64
# - armhf
# - armv7
# - i386
startup: application
ingress: true
ingress_port: 0
Expand Down Expand Up @@ -47,4 +47,4 @@ schema:
init_commands:
- str
leave_front_door_open: bool?
image: husselhans/hassos-addon-pgadmin4-{arch}
image: husselhans/hassos-addon-pgadmin4
29 changes: 15 additions & 14 deletions pgadmin4/patches/pgAdmin.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py
index 35a04b37d..c3b2bb0b1 100644
--- a/web/pgAdmin4.py
+++ b/web/pgAdmin4.py
@@ -149,8 +149,7 @@ if 'PGADMIN_INT_KEY' in os.environ:
else:
app.PGADMIN_INT_KEY = ''

-if not app.PGADMIN_RUNTIME:
- app.wsgi_app = ReverseProxied(app.wsgi_app)
+app.wsgi_app = ReverseProxied(app.wsgi_app)

app.run_before_app_start()

diff --git a/web/pgadmin/static/js/helpers/Notifier.jsx b/web/pgadmin/static/js/helpers/Notifier.jsx
index 8338dfbdd..ad1591b8f 100644
--- a/web/pgadmin/static/js/helpers/Notifier.jsx
+++ b/web/pgadmin/static/js/helpers/Notifier.jsx
@@ -190,7 +190,9 @@ export function NotifierProvider({ pgAdmin, pgWindow, getInstance, children, onR
useEffect(()=>{
// if open in an iframe then use top pgAdmin
if(window.self != window.top) {
- pgAdmin.Browser.notifier = new Notifier(modal, pgWindow.pgAdmin.Browser.notifier.snackbar);
+ if (pgWindow) {
+ pgAdmin.Browser.notifier = new Notifier(modal, pgWindow.pgAdmin.Browser.notifier.snackbar);
+ }
onReady?.();
getInstance?.(pgAdmin.Browser.notifier);
}

0 comments on commit 3169ebc

Please sign in to comment.