Overview
Docker is an essential part of the development workflow in the gitlab-org/gitlab-ce environment. This documentation provides an in-depth guide on how Docker is configured and utilized specifically for development purposes.
Docker Setup
docker-compose.yml
In the development environment, the docker-compose.yml
file serves as the primary orchestration definition for the application services. The configuration for GitLab CE is straightforward, using the latest image:
version: '3.1'
services:
app:
image: gitlab/gitlab-ce:latest
This code specifies that the app
service will use the latest version of the gitlab/gitlab-ce
image from the Docker registry.
Dockerfile
The Dockerfile
outlines the process for building a custom Docker image tailored for the development environment. Here’s a step-by-step breakdown:
Base Image Configuration
At the beginning of the Dockerfile, several arguments define versions and configurations to be used:
ARG BUILD_OS=debian
ARG CHROME_VERSION=123
ARG DOCKER_VERSION=24.0.5
ARG GCLOUD_VERSION=413
ARG GIT_VERSION=2.45
ARG HELM_VERSION=3.14
ARG KUBECTL_VERSION=1.28
ARG LFS_VERSION=2.9
ARG OS_VERSION=bookworm
ARG QA_BUILD_TARGET=ee
ARG RUBY_VERSION=3.2.4
The FROM
statement combines these arguments to specify the exact Ruby image with the required dependencies for GitLab CE:
FROM registry.gitlab.com/gitlab-org/gitlab-build-images/${BUILD_OS}-${OS_VERSION}-ruby-${RUBY_VERSION}:git-${GIT_VERSION}-lfs-${LFS_VERSION}-chrome-${CHROME_VERSION}-docker-${DOCKER_VERSION}-gcloud-${GCLOUD_VERSION}-kubectl-${KUBECTL_VERSION}-helm-${HELM_VERSION} AS foss
Environment Variables
Next, relevant environment variables are set:
ENV DEBIAN_FRONTEND="noninteractive"
ENV BUNDLE_APP_CONFIG=/home/gitlab/.bundle
By setting DEBIAN_FRONTEND
to "noninteractive"
, the installation processes will not prompt for user input. The BUNDLE_APP_CONFIG
variable is configured to simplify gem management.
Package Installation
The Dockerfile proceeds to install necessary packages:
RUN apt-get update \
&& apt-get install -y xvfb unzip google-cloud-sdk-gke-gcloud-auth-plugin \
&& apt-get -yq autoremove \
&& apt-get clean -yqq \
&& rm -rf /var/lib/apt/lists/*
xvfb
, unzip
, and Google Cloud SDK components are installed. Afterwards, the package lists are cleaned to reduce image size.
1Password CLI Installation
For managing credentials, the 1Password CLI is installed:
RUN wget -P /tmp/ https://downloads.1password.com/linux/debian/$(dpkg --print-architecture)/stable/1password-cli-$(dpkg --print-architecture)-latest.deb
RUN dpkg -i /tmp/1password-cli-$(dpkg --print-architecture)-latest.deb
RUN op --version
This section downloads the latest 1Password CLI package and checks its version to ensure successful installation.
Adding Root Certificates
To secure communications, root certificates are added:
RUN mkdir -p /usr/share/ca-certificates/gitlab
ADD ./qa/tls_certificates/authority/ca.crt /usr/share/ca-certificates/gitlab/
RUN echo 'gitlab/ca.crt' >> /etc/ca-certificates.conf
RUN chmod -R 644 /usr/share/ca-certificates/gitlab && update-ca-certificates
This process ensures that the Docker image has the necessary certificate for secure connections.
Working Directory and Dependencies
The working directory is set, and application dependencies are installed:
WORKDIR /home/gitlab/qa
COPY qa/Gemfile* /home/gitlab/qa/
COPY vendor/gems/ /home/gitlab/vendor/gems/
COPY gems/gitlab-utils /home/gitlab/gems/gitlab-utils
COPY qa/gems /home/gitlab/qa/gems
RUN ls -la && bundle config set --local without development \
&& bundle install --retry=3
The Gemfile
and any gems necessary for the application are copied, with dependencies managed through Bundler.
Adding Application Files
Additional necessary configuration files are copied into the image:
COPY ./config/initializers/0_inject_enterprise_edition_module.rb /home/gitlab/config/initializers/
COPY ./config/feature_flags /home/gitlab/config/feature_flags
COPY ./config/bundler_setup.rb /home/gitlab/config/
COPY ./lib/gitlab_edition.rb /home/gitlab/lib/
COPY ./spec/support/fast_quarantine.rb /home/gitlab/spec/support/
COPY ./tooling/lib/tooling/fast_quarantine.rb /home/gitlab/tooling/lib/tooling/
COPY ./INSTALLATION_TYPE ./VERSION /home/gitlab/
COPY ./qa /home/gitlab/qa
This integration step ensures that the application has all required Ruby files and configurations to operate within the Docker environment.
Entrypoint
The Dockerfile defines an entrypoint for running tests:
ENTRYPOINT ["bin/test"]
This instruction sets the command to be executed when the container starts, pointing to a testing framework or script.
Additional Build Targets
The Dockerfile supports different build targets: ee
for Enterprise Edition and jhqa
for specific QA tasks or custom configurations. Examples of these build stages include:
FROM foss AS ee
ONBUILD COPY VERSION ./ee/config/feature_flag[s] /home/gitlab/ee/config/feature_flags/
FROM ee AS jhqa
ONBUILD COPY ./jh/qa /home/gitlab/jh/qa
ONBUILD COPY ./jh/lib /home/gitlab/jh/lib
ONBUILD COPY ./jh/config/feature_flags /home/gitlab/jh/config/feature_flags
The use of ONBUILD
allows subsequent builds to inherit configurations and files that apply to specific development or QA requirements.
Development Environment Setup
For specifically configuring the development environment, the Dockerfile includes a step to install the Solargraph gem:
FROM ee AS dev
RUN gem install solargraph --force
This enhances the development tooling available within this container.
Conclusion
This documentation provides a detailed overview of how Docker is integrated and configured within the gitlab-org/gitlab-ce development environment. By utilizing Docker in this manner, developers can ensure a consistent and efficient workflow while working on the GitLab CE codebase.
Information sourced from the gitlab-org/gitlab-ce project’s
Dockerfile
anddocker-compose.yml
.