GitLab CI/CD
Setting up per-branch preview environments on SHIP GitLab is easy!
Using Airbase with GitLab CI
Check in Project Configuration to Git
The project's Git repository should contain the following files to support CI / CD:
- airbase.link.json required
- airbase.json required
- next.config.js
- ... NextJS project files
Add CI / CD environment variables
Airbase Credentials for CI / CD
Create and configure Airbase credentials for your CI / CD environment:
AIRBASE_ACCESS_KEY_ID
- Identifies the Airbase Access KeyAIRBASE_SECRET_ACCESS_KEY
- Actual Access Key (Secret)
Credentials can be created in the Airbase Console under Settings > Credentials.
Application Environment Variables
Include any environment variables required for the application in an ENV
variable, like this.
NEXTAUTH_SECRET=secretvaluegoeshere
NEXTAUTH_URL=http://localhost:3000
ROOT_USERNAME=user@example.com
ROOT_PASSWORD=secretpasswordgoeshere
Read more about environment variables on Airbase.
Configure GitLab CI pipeline
Add these lines into .gitlab-ci.yml
to enable GitLab CI pipelines using our recommended template.
include:
- project: "innersource/sgts/ship-hats/ship-hats-templates"
ref: "main"
file:
- "/templates/.gitlab-ci-airbase-nextjs-cicd.yml"
deploy:
extends: .airbase-deploy
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- npx @airbase/airbase-cli deploy --output deploy.env --yes
environment:
name: production
url: $DYNAMIC_ENVIRONMENT_URL
review:
extends: .airbase-deploy
stage: test
artifacts:
paths:
- .airbase/airbase.link.json
environment:
name: review/$CI_COMMIT_REF_SLUG
url: $DYNAMIC_ENVIRONMENT_URL
on_stop: stop_review
stop_review:
extends: .airbase-destroy
needs:
- review
script:
- npx @airbase/airbase-cli destroy "$CI_COMMIT_REF_SLUG" --yes
when: manual
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
This pipeline helps projects to get started with DevOps:
- automatically deploy branches to preview environments
- integrates with GitLab's Environments to produce a "View Deployment" button
- for example:
feat/123-new-feature
->https://project-feat-123-new-demo.app.airbase.sg
- on the
main
branch, if tests succeed, automatically deploy to production.
Conclusion
You should now be able to View Deployment on new Merge Requests and Branches in GitLab.
Click on Operate > Environments to view all the branch environments.
Examples and Inspiration
Here's are some projects that use GitLab CI / CD: