Integrating with GitLab CI
This tutorial will show you the steps to integrate Bytebase CLI bb
into a GitLab project. You will set up a pipeline automating the database schema change along with the code change, which brings your teamβs DevOps automation to a new level.
Prerequisites
- A GitLab Project. (GitLab.com or GitLab CE/EE. We use GitLab.com for this tutorial.)
- Self-managed GitLab Runner on a Linux machine. (You can follow the GitLab Runner docs to install)
- A MySQL database that is network accessible by the GitLab Runner.
Install bb
on GitLab Runner
On your GitLab Runner shell prompt, paste the following command:
Run bb --version
to check if bb
is installed.
You can go back to overview for more installation details.
Register GitLab Runner to a GitLab Project
In your GitLab Project, go to Settings > CI/CD > Runners, click the Show Runner Installation Instructions button, and follow the instructions to register runner.
From the shell prompt, add tag bb-runner
to specify this runner has bb
installed.
Configure GitLab CI
Set up .gitlab-ci.yml
:
Configure DSN
bb
configures --dsn to access databases. Here are a few examples:
- mysql://root@localhost:3306/
- postgresql://user:pass@localhost:5432/dbname?ssl-ca=a&ssl-cert=b&ssl-key=c
You also need to setup DSN secret to make this workflow available:
Go to Setting > CI/CD > Variables, add your DSN as BYTEBASE_DSN
.
Trigger a Migration
Finally, you can trigger a migration by adding a new commit to your GitLab project.
Commit a script to dev/
and check if this job runs correctly:
The schema snapshots before and after the migration are stored in artifacts:
You can browse this job detail on GitLab.com.