Contents

Gem from a private Gitlab repository in your Gemfile(for Docker)

Gem from a private Gitlab repository in your Gemfile(for Docker)

If you want to deploy your Ruby on Rails project with Kamal, and your project depends on a Gem hosted in a private GitLab repository,

gem "mygem", git: "https://gitlab.com/username/mygem.git", branch: "develop"

you need to follow a few extra steps.

Go to your GitLab project (or group) → Settings → Repository → Deploy Tokens.

Create a new deploy token with at least read_repository scope.

Note the username and token — you will need them later.

Create or update your .env file:

GITLAB_USER=your-user-name
GITLAB_TOKEN=your-deploy-token

Update .kamal/secrets:

GITLAB_USER=$GITLAB_USER
GITLAB_TOKEN=$GITLAB_TOKEN

This makes the variables available during the Docker build process.

Add build arguments so Kamal can pass them into the Docker build:

builder:
  args:
    GITLAB_USER: ${GITLAB_USER}
    GITLAB_TOKEN: ${GITLAB_TOKEN}

In your Dockerfile, configure Git to use the credentials for GitLab:

ARG GITLAB_USER
ARG GITLAB_TOKEN

RUN git config --global url."https://${GITLAB_USER}:${GITLAB_TOKEN}@gitlab.com/".insteadOf "https://gitlab.com/"

Now, when Docker runs bundle install, it will be able to fetch your private Gem.