Plugin entrypoint.sh not executed in kubernetes

Hello there.

I encounter the following problem: My plugin’s docker entrypoint (plugin.sh) is never executed.

Here is my plugin Dockerfile:

FROM alpine
RUN apk add --no-cache curl make git bash
COPY kustomize /usr/bin/
COPY plugin.sh /drone/
RUN curl -Lo /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.18.3/bin/linux/amd64/kubectl && chmod +x /usr/bin/kubectl
ENTRYPOINT [ "/drone/plugin.sh" ]

And here is my plugin.sh:

#!/bin/sh

set -euo pipefail
PLUGIN_DEBUG=true

if [[ -z "${PLUGIN_KUBECONFIG}" ]]; then
  echo "no PLUGIN_KUBECONFIG variable"
else
  mkdir -p $HOME/.kube
  echo "$PLUGIN_KUBECONFIG" > $HOME/.kube/config
  export KUBECONFIG=$HOME/.kube/config
fi

In my case, drone is deployed on Kubernetes. My pipeline looks like this:

kind: pipeline
type: kubernetes
name: default

steps:
  - name: deploy
    image: my/registry/k8s-drone-plugin:v1.0.1
    settings:
      kubeconfig:
        from_secret: kubeconfig
    commands:
      - kubectl version && kustomize version <-- this WORKS
      - echo $PLUGIN_KUBECONFIG   <-- this WORKS
      - echo $KUBECONFIG  <-- This env var is EMPTY (even though it's defined in plugin.sh)!
      - cat ~/.kube/config  <-- This gives an error: "cat: can't open '/root/.kube/config': No such file or directory"
      - kubectl get pods  <-- permission error, that's normal because ./kube/config is missing.

image_pull_secrets:
  - dockerconfig

Also, I can see that the image run in kubernetes is not my/registry/k8s-drone-plugin:v1.0.1 but drone/placeholder:1 (https://hub.docker.com/r/drone/placeholder).

When I test the docker image locally, the script plugin.sh works.

Clearly, my plugin.sh script is never run…Any idea why?

Thanks a lot for you help!

when you declare a commands section, the commands are executed as your container entrypoint and thus override the entrypoint defined in the image.

I see, thanks @bradrydzewski for your answer!

May I know what is the recommended approach if I want to use a plugin and run commands?

I like how plugins can help make the pipeline cleaner, but command give a lot of freedom as well…

Thanks in advance

Plugins are not designed to run user-defined commands. If you want the flexibility to run custom commands, perhaps a plugin is not the right approach. Instead consider invoking the bash script directly.

kind: pipeline
type: kubernetes
name: default

steps:
  - name: deploy
    image: my/registry/k8s-drone-plugin:v1.0.1
-   settings:
-     kubeconfig:
-       from_secret: kubeconfig
+   environment:
+     PLUGIN_KUBECONFIG:
+       from_secret: kubeconfig
    commands:
+     - /drone/plugin.sh
      - kubectl version && kustomize version
      - echo $PLUGIN_KUBECONFIG 
      - echo $KUBECONFIG 
      - cat ~/.kube/config
      - kubectl get pods 

I see, I will try this way. Thanks a lot