5

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
Imtiaz K
  • 38
  • 2
Ali
  • 1,759
  • 2
  • 32
  • 69

1 Answers1

4

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

aaron-prindle
  • 3,077
  • 1
  • 17
  • 15