Set Up CI/CD
Setting up CI/CD enables the code to be deployed automatically as soon as you merge the code to your branch in your git repository.
Truefoundry itself doesn’t provide CI capabilities - it integrates with other CI/CD systems like Github Actions, Bitbucket Pipelines, Gitlab CI/CD, Jenkins or any other CI/CD provider.
To integrate with your CI/CD pipeline, we use the Deploy Programatically feature. You will just need to install the Truefoundry CLI in your CI/CD pipeline and run the tfy apply
command
A few things that you will need to think about in setting up your CI/CD pipeline are:
1. Do you want to build the docker image in your CI pipeline or inside Truefoundry?
Usually, we recommend to build the docker image in Truefoundry since its much faster and reduces cost in your CI pipeline. However, if you have any custom build requirements, you can build the image in your CI pipeline - you will just need to make a few changes in your CI configuration.
Truefoundry can build images 3-15X faster than your CI pipeline. You can read this blog to know more. This can help make your CI pipeline faster and more cost effective.
2. Do you want to keep the service YAML spec in your git repository?
The complete YAML spec comprises all the configuration about the service like the resources, endpoints, autoscaling, etc. While its recommended to keep the YAML spec in your git repository so that any changes to the configuration can be easily tracked and approved, smaller teams often prefer to not store the complete spec in Git since it might be easier to change the configuration via UI.
Once you keep the YAML spec in Git and deploy it via CI/CD, you shouldn’t change the configuration via UI. If you change the configuration via UI and don’t update in Git, the configuration will be overwritten by the YAML spec in Git on next commit in the Git repository.
If you decide not to keep the YAML spec in Git, the CI/CD pipeline will just patch the commit SHA in your spec on every commit.
Writing the CI/CD configuration file
All CI/CD systems like Github Actions, Gitlab CI/CD, etc. have a way to specify the steps in the pipeline in a configuration file. Truefoundry helps generate the configuration file for most common systems like Github Actions, Gitlab CI/CD, Bitbucket Pipelines, and Jenkins. In case you are using something else, you can write the configuration file manually.
Click on Setup CI/CD Button and choose your CI/CD provider
Decide how you want to setup the CI/CD pipeline
Truefoundry automatically adjusts the CI/CD configuration based on your different scenarios - like if you are deploying the service from Git repository, or local code or from a docker image. So you might see different options for different services.
Here’s the mapping of the different options as descibed above:
Option | Where to build the docker image | Keep the YAML spec in Git |
---|---|---|
Update Code, Build and Deploy Using Truefoundry | Truefoundry | True |
Deploy Docker Image on Truefoundry with spec in Git repository | CI Pipeline | False |
Maintain Spec in Git and build and deploy via Truefoundry | Truefoundry | True |
Build and deploy latest commit without maintaining spec in Git | Truefoundry | False |
Deploy docker image on TrueFoundry without spec in Git repository | CI Pipeline | False |