Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a script or a command to run with Skaffold dev deployment to a Kubernetes cluster

I would like to run a command to clone a script from a remote repository before running skaffold dev I need to either somehow inject a git clone command or put the git clone command and the corresponding arguments in a shell script and run the shell script with Skaffold.

From the Skaffold workflow point of view, this step should be run before build. I am using Jib for the build phase and it appears that Jib state does not give me any ability to run a script before the actual build. I don't know if I can add a new phase to the Skaffold life cycle like pre-build. One solution came to my mind is to use custom build instead of Jib and put all pre-build commands as well as the jib related commands in a single script to run. This approach probably works, but won't be very convenient. I was wondering if there is a better approach to do this with Skaffold.

build:
  artifacts:
    - image: gcr.io/k8s-skaffold/example
      custom:
        buildCommand: ./prebuild-and-build.sh
like image 223
Ali Avatar asked Nov 06 '22 10:11

Ali


1 Answers

skaffold supports lifecycle hooks which allow running custom scripts before/after a build - https://skaffold.dev/docs/pipeline-stages/lifecycle-hooks/

With this, you should be able to add a stanza in your skaffold.yaml similar to this:

build:
  artifacts:
  - image: gcr.io/k8s-skaffold/example
    hooks:
      before:
        - command: ["sh", "-c", "./prebuild-and-build.sh"]
          os: [darwin, linux]
        # - command: # ...TODO
        #   os: [windows]

NOTE: This feature is relatively new, be sure to use the latest skaffold version (v1.33.0 at the time of this writing) for this feature

like image 51
aaron-prindle Avatar answered Nov 15 '22 10:11

aaron-prindle