GitLab

GitLab offers a comprehensive DevOps platform that includes Git repository management, CI/CD pipelines, and more.

View as Markdown

Overview

Integrating Knapsack with GitLab allows you to take full advantage of its built-in CI/CD capabilities, streamline your workflows, and ensure that your design system components are always up-to-date and well-managed. GitLab’s self-hosted and cloud options provide flexibility to meet your organization’s needs.

Cloud Authoring

Authentication through Personal Access Token (PAT)

To enable cloud authoring within GitLab, we use a Personal Access Token (PAT) for authentication. This token allows secure access to your GitLab repositories and enables necessary actions on your behalf.

Step 1: Add Knapsack Bot as a Collaborator

  1. Navigate to your repository on GitLab and click on the “Settings” tab.
  2. In the left-hand sidebar, select “Members”.
  3. Under “Invite members to the project”, enter “knapsack-bot@knapsack.cloud” in the “Username or email” field.
  4. Set the access level to “Maintainer” or “Owner” to ensure the bot has the necessary permissions to perform actions on your repository.
  5. Click “Invite” to send the invitation to the Knapsack Bot.

Permissions Required

You may need administrative privileges on your repository to invite the Knapsack Bot as a collaborator. If you encounter any issues, please reach out to our support team for assistance.

Step 2: Knapsack Generates PAT for Authentication

  • Once the Knapsack Bot has been added as a collaborator, we will use its account to generate a PAT for authentication.
  • This process allows us to securely access your repository without needing your personal credentials.

For any questions or further assistance, please contact our support team.

Important Notes

This is a manual process. If handling asynchronously, we’ll notify you when it is completed.

Mandatory Step

This step must be completed for Cloud Authoring to function.


GitLab CI

Required CI/CD Variables

Deployments to Heroku rely on the following CI/CD variables:

  1. HEROKU_APP — The name of the Heroku application
  2. HEROKU_API_KEY — The API Key associated with the Heroku account (found in profile settings)

Configuration notes:

  • For an easy GitLab integration with Heroku — we are utilizing the Ruby gem dpl
  • When adding CI/CD variables — do not mark them as protected or CI will not catch them

Example .gitlab-ci.yml

1stages:
2 - build
3 - deploy
4
5
6Build_Main:
7 image: node:16
8 stage: build
9 script:
10 - yarn
11 - yarn build
12 cache:
13 key: knapsack-build
14 paths:
15 - node_modules
16 only:
17 - main
18
19
20Deploy_Main:
21 image: ruby:2.6
22 stage: deploy
23 before_script:
24 - echo 'Deploying to heroku...'
25 - gem install dpl -v ">= 1.10.15"
26 - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
27 script:
28 - dpl --provider=heroku --app=$HEROKU_APP --api-key=$HEROKU_API_KEY
29 only:
30 - main

In this example

Build_Main

Handles installing dependencies and a simple build.

Deploy_Main

Handles installing DPL and the Heroku CLI, then fires off the deployment.