Skip to content

Commit

Permalink
github: Dockerfile: Fix .plugins copying and usage with test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
illume committed Feb 2, 2024
1 parent c88e642 commit 6c3fb26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]

0 comments on commit 6c3fb26

Please sign in to comment.