CI/CD
Because the DDN CLI plays the central role in controlling and managing metadata builds and connector deployments, it allows developers to easily create effective CI/CD pipelines for managing projects, creating and applying builds or promoting them to another environment.
Generic CI/CD Setup
The user should follow the following generic implementation steps which we will go through below when setting up CI/CD for their Hasura DDN projects.
- Prepare a service account access token.
- Use a linux environment to run the DDN CLI.
- Install and login to the DDN CLI.
- Clone the repo with the DDN supergraph metadata.
- Check context or use flags.
- Run DDN CLI commands.
Step 1: Prepare a service account access token
See the service account access token section to learn how to create a service account access token.
Step 2: Use a Linux environment to run the DDN CLI
Any service which can provide a Linux-like environment will work, eg: GitHub Actions, GitLab CI, CircleCI, etc.
Indeed, a Windows or macOS environment will work and run the DDN CLI but for CI/CD pipelines, we recommend using a Linux environment for speed, availability and convenience.
Step 3: Install and login to the DDN CLI
curl -L https://graphql-engine-cdn.hasura.io/ddn/cli/v4/get.sh | bash
Your environment should already have curl
installed. If not, you can install it using your package manager. eg:
sudo apt update && sudo apt upgrade
sudo apt install curl
curl --version
Step 4: Clone the repo with the DDN supergraph metadata
Clone (or checkout) the repository that contains all of your DDN supergraph metadata. For example, if you have a public GitHub repository, run:
git clone https://github.com/<your-org>/<your-repo>.git
If your repository is private, you may need a GitHub personal access token or similar for your git provider to clone it.
git clone https://username:<pat>@github.com/<your-account-or-org>/<repo>.git
Step 5: Check context or use flags
Make sure your context is set properly to reference the correct projects, subgraphs, etc., or use the correct flags in your DDN CLI commands.
You can set your context using the ddn context set-current-context <context-name>
command. Read more about
contexts.
You can also of course use specific flags in your DDN CLI commands eg: --project
, --supergraph
,
--base-supergraph-version
, --log-level
, --out
to make your commands more explicit.
Step 6: Run DDN CLI commands
You can now run any DDN CLI commands required in the CI/CD workflow. You will likely be creating builds and applying them to projects.
ddn supergraph build create
ddn supergraph build apply <build-id>
GitHub Actions Setup
We have a GitHub Action that you can use to deploy your Hasura DDN projects. See here.