From 6c3fb2682492d9c523c4f19e589d5fdfc096528f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Fri, 2 Feb 2024 20:23:01 +0100 Subject: [PATCH] github: Dockerfile: Fix .plugins copying and usage with test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At some point the .plugins package copying stopped working. It's documented that a .plugins folder will be copied and used by the container. Signed-off-by: René Dudfield --- .github/workflows/build-container.yml | 16 ++++++++++++++++ Dockerfile | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 8b913eded34..a7cd27f6fc3 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -28,6 +28,17 @@ jobs: # now you can run kubectl to see the pods in the cluster - name: Try the cluster! run: kubectl get pods -A + - name: Test .plugins folder is copied in the right place + run: | + echo "extract pod-counter plugin into .plugins folder" + cd plugins/examples/pod-counter + npm install + npm run build + cd ../../../ + cd plugins/headlamp-plugin + npm install + node bin/headlamp-plugin.js extract ../examples/pod-counter ../../.plugins/ + cd ../../ - name: Build image run: | export SHELL=/bin/bash @@ -36,6 +47,11 @@ jobs: DOCKER_IMAGE_VERSION=latest DOCKER_PLUGINS_IMAGE_NAME=headlamp-plugins-test make build-plugins-container echo -n "verifying images:" docker images + echo "--- Files in the image /headlamp/ folder: ---" + docker run --rm --entrypoint=/bin/sh ghcr.io/headlamp-k8s/headlamp:latest -c "cd /headlamp/ && find ." + echo "----- Checking if the .plugins/ are copied to the right place in the image -----" + docker run --rm --entrypoint=/bin/sh ghcr.io/headlamp-k8s/headlamp:latest -c "set -e; (cd /headlamp/plugins && [ -e pod-counter/package.json ] && [ -e pod-counter/main.js ]) || exit 1" + - name: Deploy to cluster run: kubectl apply -f e2e-tests/kubernetes-headlamp-ci.yaml diff --git a/Dockerfile b/Dockerfile index 87350e8fed4..89849f49e11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,13 +53,14 @@ RUN cat ./frontend/.env # Backwards compatibility, move plugin folder to only copy matching plugins. RUN mv plugins plugins-old || true +# Copy a .plugins folder if it is there to ./plugins, otherwise create an empty one. +COPY ./.plugi*s ./plugins RUN mkdir -p ./plugins # Backwards compatibility, copy any matching plugins found inside "./plugins-old" into "./plugins". # They should match plugins-old/MyFolder/main.js, otherwise they are not copied. RUN for i in $(find ./plugins-old/*/main.js); do plugin_name=$(echo $i|cut -d'/' -f3); mkdir -p plugins/$plugin_name; cp $i plugins/$plugin_name; done - -RUN for i in $(find ./.plugins/*/main.js); do plugin_name=$(echo $i|cut -d'/' -f3); mkdir -p plugins/$plugin_name; cp $i plugins/$plugin_name; done +RUN for i in $(find ./plugins-old/*/package.json); do plugin_name=$(echo $i|cut -d'/' -f3); mkdir -p plugins/$plugin_name; cp $i plugins/$plugin_name; done # Static (officially shipped) plugins FROM --platform=${BUILDPLATFORM} frontend-build as static-plugins @@ -93,4 +94,4 @@ USER headlamp EXPOSE 4466 ENV HEADLAMP_STATIC_PLUGINS_DIR=/headlamp/static-plugins -ENTRYPOINT ["/headlamp/headlamp-server", "-html-static-dir", "/headlamp/frontend"] +ENTRYPOINT ["/headlamp/headlamp-server", "-html-static-dir", "/headlamp/frontend", "-plugin-dir", "/headlamp/plugins"]