GitLab Deployment and Configuration Management

Overview

The gitlab-ce repository houses the GitLab Community Edition source code and includes features and tools for deployment and configuration management. This document outlines the processes and technologies utilized to deploy and manage GitLab instances.

Deployment Pipelines

GitLab leverages its own CI/CD capabilities to automate the deployment process. Deployment pipelines are defined in .gitlab-ci.yml files within various subdirectories of the repository. These pipelines orchestrate tasks such as:

  • Building and packaging the GitLab application: This involves compiling the source code and generating distributable packages.
  • Running tests: Extensive unit, integration, and acceptance tests are executed to ensure code quality and functionality.
  • Deploying to different environments: The pipelines support deployments to various environments like development, staging, and production.
  • Configuration management: Configuration files and environment variables are handled within the pipelines.

Example: gitlab-ce/gitlab-rails/spec/support/gitlab_helper.rb:

# frozen_string_literal: true
          
          require 'active_support/core_ext/string/inflections'
          
          module Gitlab
            module GitlabHelper
              # This module is intended to simplify the process of testing against different GitLab versions
              # in the spec/support/gitlab_helper.rb
              #
              # Example usage:
              #
              #   Gitlab::GitlabHelper.set_gitlab_versions('13.9.0')
              #   Gitlab::GitlabHelper.gitlab_version
              #   Gitlab::GitlabHelper.reset_gitlab_versions
              #
              # This works by setting the environment variable `GITLAB_VERSION` with the desired version
              # and setting the `GITLAB_VERSION` attribute to the Gitlab class.
              module_function
          
              def set_gitlab_versions(versions)
                return unless versions.is_a?(Array) || versions.is_a?(String)
          
                unless versions.is_a?(Array)
                  versions = [versions]
                end
          
                versions.each do |version|
                  if version.is_a?(String)
                    # This is a version string that can be parsed
                    #
                    # We should check if this string is a valid semver and raise an error if not
                    # otherwise an invalid value will be set
                    begin
                      Gem::Version.new(version)
                    rescue ArgumentError => e
                      raise ArgumentError.new("Invalid version #{version}. #{e.message}")
                    end
                  elsif version.is_a?(Gem::Version)
                    # This is already a Gem::Version and does not require further validation
                  else
                    raise ArgumentError.new("Invalid version #{version}. Supported versions: String or Gem::Version.")
                  end
                end
          
                Rails.application.config.gitlab.version = versions
                ENV['GITLAB_VERSION'] = versions.join(',')
                Gitlab.gitlab_version = versions
              end
          
              def gitlab_version
                Gitlab.gitlab_version
              end
          
              def reset_gitlab_versions
                Rails.application.config.gitlab.version = nil
                ENV.delete('GITLAB_VERSION')
                Gitlab.gitlab_version = nil
              end
            end
          end
          

Configuration Files

Configuration settings for GitLab are stored in a variety of files depending on the environment and specific configuration. These files may include:

  • config/gitlab.yml: This YAML file defines core configuration settings, such as database connection parameters, email settings, and external URL.
  • config/secrets.yml: This file holds sensitive data like API keys and secret tokens.
  • config/database.yml: Specifies database configuration details, including the database type, hostname, and credentials.

Example: gitlab-ce/config/gitlab.yml.example:

# This file is an example of a GitLab configuration file for development, staging and production environments.
          #
          # For further information on configuration options, please refer to the GitLab documentation:
          # https://docs.gitlab.com/ee/administration/configuration/
          #
          # For production environments, you will need to set `gitlab_rails['gitlab_shell_ssh_port']` in the
          # `gitlab.yml` file. You can change this port from the default of 22 to a different port.
          #
          # Also, you should enable `gitlab_rails['audit_events']` in the `gitlab.yml` file to
          # enable logging of events for security purposes.
          #
          
          # The default setting for this option is 'http'.
          #
          # If your GitLab instance is behind a reverse proxy, you need to configure the
          # GitLab URL to be accessible through that proxy and set the `gitlab_rails['http_proxy_url']`
          # option to the URL of the reverse proxy.
          #
          # If your GitLab instance is behind a load balancer, you need to set the `gitlab_rails['http_proxy_url']`
          # option to the URL of the load balancer.
          #
          # Example for reverse proxy:
          #
          # gitlab_rails:
          #   http_proxy_url: http://proxy.example.com
          #   external_url: http://gitlab.example.com
          #
          # Example for load balancer:
          #
          # gitlab_rails:
          #   http_proxy_url: http://loadbalancer.example.com
          #   external_url: http://gitlab.example.com
          #
          # For more information on configuring GitLab behind a reverse proxy, please see the GitLab documentation:
          # https://docs.gitlab.com/ee/administration/integration/reverse_proxy.html
          
          ---
          default: &default
            gitlab_rails:
              # Specifies the hostname where GitLab is accessible from. This is used for
              # links to GitLab in emails and other places.
              # You can use a domain name, a subdomain or an IP address.
              #
              # IMPORTANT: This setting should match the value used for `external_url` in
              # `gitlab.yml`, so that the link is correct.
              #
              # The default value is `http://localhost` for the development and test environments.
              external_url: http://localhost
              # The path prefix that GitLab will use.
              #
              # This is helpful to prevent collisions if you are running multiple GitLab
              # instances on the same server.
              #
              # If you are running GitLab in a container, you will need to set this to the path
              # that the container is mounted to.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     path_prefix: /gitlab
              #
              # This will make GitLab accessible at http://localhost/gitlab.
              path_prefix: ""
              # This setting can be used to change the port that GitLab listens on.
              # This can be used to avoid port conflicts with other services that are running
              # on the server.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     port: 3000
              #
              # This will make GitLab accessible at http://localhost:3000.
              port: 80
              # This setting can be used to configure GitLab to use a different scheme
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     scheme: https
              #
              # This will make GitLab accessible at https://localhost.
              scheme: http
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     host: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              host: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # The GitLab URL that will be used for links in the user interface and API.
              # This should be the same as the URL used for accessing GitLab.
              #
              # IMPORTANT: This setting should match the value used for `external_url` in
              # `gitlab.yml`, so that the link is correct.
              #
              # This setting is deprecated and will be removed in a future version of GitLab.
              #
              # The default value is `http://localhost` for the development and test environments.
              url: http://localhost
              # This setting can be used to configure GitLab to use a different port
              # for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     port: 8080
              #
              # This will make GitLab accessible at http://localhost:8080.
              port: 80
              # This setting can be used to configure GitLab to use a different scheme
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     scheme: https
              #
              # This will make GitLab accessible at https://localhost.
              scheme: http
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     host: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              host: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     protocol: https
              #
              # This will make GitLab accessible at https://localhost.
              protocol: ""
              # This setting can be used to configure GitLab to use a different
              # hostname for accessing it.
              #
              # This can be useful if you are running GitLab behind a load balancer or
              # a reverse proxy.
              #
              # Example:
              #
              #   gitlab_rails:
              #     # ...
              #     hostname: gitlab.example.com
              #
              # This will make GitLab accessible at http://gitlab.example.com.
              hostname: ""
              # This setting can be used to configure GitLab to use a different protocol
              # for accessing it.
              #
              # Example:
              #
              #   gitlab