You can build a continuous integration and continuous deployment (CI/CD) pipeline to automate deployments to production. You can also use these pipelines to run automated tests before deploying.
You can use any CI/CD platform to build a pipeline, such as GitHub Actions, CircleCI, GitLab, or Jenkins.
Using ggt in a CI/CD pipeline
To set up a CI/CD pipeline for your Gadget app, you need to:
ggt deploy will automatically run ggt push under the hood if the local filesystem, which is your test runner and git branch, does not
match the hosted environment. This is so the latest code and configuration on your specified git branch will always be deployed to
production.
Once the CLI token has been generated, it needs to be stored as a secret in the CI platform you are using. After storing your CLI token as a secret, the token can be safely used in your pipeline to run authenticated ggt commands.
Here is how you can pass a CLI token to ggt in a GitHub Action:
using a CLI token to deploy in a CI/CD pipeline
yml
1-uses: actions/checkout@v4
2-name: Install ggt # first, install ggt in the test runner environment
3run:|
4 npm install -g ggt@latest
5 ggt version
6shell: bash
7
8-name: Deploy to production # deploy to production for the passed in app and environment
The --allow-unknown-directory flag is required when an app's .gadget folder has not been pulled into your test runner before running
ggt deploy. This flag allow you to deploy to production without a .gadget/sync.json file.
The --force flag is used to overwrite the current hosted environment with whatever currently exists in the git branch, ensuring that the
lasted code and configuration is deployed.
Go to your GitHub repository's Settings, then find the Secrets section. Add a new secret named GGT_TOKEN and paste your CLI token as the value. This step ensures that your token is securely stored and accessible in your GitHub Actions workflow.
In your Gadget app, create a .github/workflows directory. Inside, you'll create a YAML file for your workflow.
In your YAML workflow file, paste the token as shown below in the config steps of your Github Action.
action.yml
yaml
1name: CI/CD Pipeline
2
3on:
4push:
5branches:
6- main # or any other branch you want to deploy from
7
8jobs:
9deploy:
10steps:
11-name: Checkout the current repository
12uses: actions/checkout@v4
13-name: Deploy to Gadget Production
14uses: gadget-inc/ggt-deploy-action@v1
15with:
16app:'<your-app-name>'
17environment:'<your-environment>'# The environment you are deploying to production
18token: ${{ secrets.GGT_TOKEN }}# Add your CLI token
19allow-issues:'false'# Optionally, continue deployment even if there are issues
This action will be run automatically every time you push to the main branch. It will:
install ggt into your test runner environment
take the latest code and configurations from your git branch and push it to the specified Gadget environment
deploy that environment to production
Automated testing
You can also run automated tests as part of a CI/CD pipeline. This means you run tests between pushing your changes from git to Gadget, and deploying.
To run automated tests in a CI/CD pipeline, you need to:
Run your tests against the updated environment. A ggt pull may be required to bring in files not maintained in source control if you are running tests using a Gadget API client.