Automate Database CI/CD with CircleCI Orbs
CircleCI Orbs are reusable packages of CircleCI configuration that can be shared across projects. They provide a way to simplify your CircleCI configuration by encapsulating common tasks into a single line of code.
Atlas provides a number of Orbs to help you integrate Atlas into your CircleCI workflows.
| Action | Use Case |
|---|---|
| atlas-orb/setup | Install Atlas and authenticate with Atlas Cloud |
| atlas-orb/migrate_push | Push your migration directory to Atlas Cloud (atlasgo.cloud) |
| atlas-orb/migrate_lint | Lint migration changes with Atlas (Required atlas login) |
| atlas-orb/migrate_apply | Apply migrations to a database |
| atlas-orb/migrate_down | Revert migrations to a database. |
| atlas-orb/migrate_test | Test migrations to a database. |
| atlas-orb/migrate_autorebase | Fix atlas.sum conflicts in migration directory. |
| atlas-orb/schema_test | Test schema to a database. |
atlas-orb/setup
The atlas-orb/setup action can be used to install the Atlas CLI and authenticate with Atlas Cloud.
Usage
.circleci/config.yml
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- atlas-orb/setup:
version: "latest"
workflows:
use-atlas:
jobs:
- push-dir
Inputs
cloud_token_env- (Optional) The Atlas Cloud token to use for authentication. To create a cloud token see the docs. Defaults toATLAS_TOKENenvironment variable.version- (Optional) The version of the Atlas CLI to install. Defaults to the latest version.
atlas-orb/migrate_push
Push the current version of your migration directory to Atlas Cloud.
Usage
- MySQL
- MariaDB
- PostgreSQL
- SQLite
- SQL Server
- Clickhouse
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
- image: cimg/mysql:8
environment:
MYSQL_DATABASE: dev
MYSQL_ROOT_PASSWORD: pass
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- run:
name: Wait for MySQL
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 60s
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "mysql://root:pass@localhost:3306/dev"
workflows:
use-atlas:
jobs:
- push-dir
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
- image: cimg/mariadb:10.6
environment:
MYSQL_DATABASE: dev
MYSQL_ROOT_PASSWORD: pass
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- run:
name: Wait for MariaDB
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 60s
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "maria://root:pass@localhost:3306/dev"
workflows:
use-atlas:
jobs:
- push-dir
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
- image: cimg/postgres:15.0
environment:
POSTGRES_DB: dev
POSTGRES_PASSWORD: pass
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- run:
name: Wait for Postgres
command: dockerize -wait tcp://127.0.0.1:5432 -timeout 60s
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "postgres://postgres:pass@localhost:5432/dev?sslmode=disable"
workflows:
use-atlas:
jobs:
- push-dir
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
environment:
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "sqlite://file?mode=memory&_fk=1"
workflows:
use-atlas:
jobs:
- push-dir
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
- image: mcr.microsoft.com/mssql/server:2022-latest
environment:
ACCEPT_EULA: Y
MSSQL_PID: Developer
MSSQL_SA_PASSWORD: P@ssw0rd0995
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- run:
name: Wait for SQL Server
command: dockerize -wait tcp://127.0.0.1:1433 -timeout 60s
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "sqlserver://sa:P@ssw0rd0995@localhost:1433?database=master"
workflows:
use-atlas:
jobs:
- push-dir
version: 2.1
orbs:
atlas-orb: ariga/atlas-orb@0.0.6
jobs:
push-dir:
docker:
- image: cimg/base:current
- image: clickhouse/clickhouse-server:23.10
environment:
CLICKHOUSE_DB: test
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
CLICKHOUSE_PASSWORD: pass
CLICKHOUSE_USER: root
environment:
# Define those envs in CircleCI context to keep them secure
ATLAS_TOKEN: "your-atlas-token"
steps:
- checkout
- run:
name: Wait for Clickhouse
command: dockerize -wait tcp://127.0.0.1:9000 -timeout 60s
- atlas-orb/setup:
version: "latest"
- atlas-orb/migrate_push:
dir_name: my-project
dev_url: "clickhouse://root:pass@localhost:9000/test"
workflows:
use-atlas:
jobs:
- push-dir
Inputs
All inputs are optional as they may be specified in the Atlas configuration file.
dir- The URL of the migration directory to push. For example:file://migrations. Read more about Atlas URLs.dir_name- The name (slug) of the project in Atlas Cloud.dev_url- The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.tag- The tag to apply to the pushed migration directory. By default the current git commit hash is used.config- The path to the Atlas configuration file. By default, Atlas will look for a file. namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.env- The environment to use from the Atlas configuration file. For example,dev.vars- Extra variables to pass to the Atlas configuration file. For example,key=value key2=values.working_directory- The working directory to run from. Defaults to project root.