Adding pre and post build scripts
For a control plane installation, it is possible to add custom scripts which can run before and after your build/push process. This is being used to give more flexibility in terms of modifying the total behaviour of the build process and determining the result of the build pipeline.
Adding script in the build pipeline
-
A script can be added before the build and post the build-and-push process.
-
To do this edit your
truefoundry
helm chart and configure the section of thetfyBuild.truefoundryWorkflows.preBuild
andtfyBuild.truefoundryWorkflows.postBuild
-
Following is an example
tfyBuild: truefoundryWorkflows: preBuild: image: tag: latest repository: ubuntu script: | #!/bin/bash echo "Running pre-build script..." # your steps can come here echo "Finishing pre-build script." command: - /bin/bash enabled: true postBuild: image: tag: latest repository: ubuntu script: | #!/bin/bash echo "Running post-build script..." # your steps can come here echo "Finishing post-build script." command: - /bin/bash enabled: true
Running time-intensive task
Each build pipeline is allowed to run for max 14400 seconds post which the build will be declared as failed. User needs to ensure that the pre-build and post-build steps don't exceed the given time. Each step in itself is allowed to run for max 5400 seconds.
-
Each step can refer to few inputs -
- Build Source -
{{inputs.parameters.buildSource}}
- Build config -
{{inputs.parameters.buildConfig}}
- Docker registry URL -
{{inputs.parameters.dockerRegistryURL}}
- Docker registry username -
{{inputs.parameters.dockerRegistryUsername}}
- Docker registry password -
{{inputs.parameters.dockerRegistryPassword}}
- Docker image repository -
{{inputs.parameters.dockerRepo}}
- Docker image tag -
{{inputs.parameters.dockerTag}}
- Build Source -
-
An example of using this -
postBuild: image: tag: latest repository: ubuntu script: > #!/bin/bash REGISTRY="{{inputs.parameters.dockerRegistryURL}}" REPOSITORY="{{inputs.parameters.dockerRepo}}" TAG="{{inputs.parameters.dockerTag}}" IMAGE=$REGISTRY/$REPOSITORY:$TAG echo "Registry URL is "$REGISTRY command: - /bin/bash enabled: true
Docker cli isn't supported
Currently docker CLI is not supported in the pre-build script as it can't connect to any daemon.
Updated 2 months ago