Skip to content

Gitlab

Gitlab

docker-compose.yml with Treafik options
    ---
    version: "3.3"

    networks:
      zabra:
        external: true

    services:
      gitlab:
        image: "gitlab/gitlab-ce:15.3.0-ce.0"
        container_name: gitlab
        hostname: "gitlab.enoks.fr"
        restart: always
        networks:
          - zabra
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            external_url "https://gitlab.enoks.fr"
            # Disable some services
            registry['enable'] = false
            prometheus_monitoring['enable'] = false
            grafana['enable'] = false
            # Set ssh external port
            #gitlab_rails['gitlab_shell_ssh_port'] = 2221
            # Adapt nginx conf because we have traefik above
            letsencrypt['enable'] = false # ssl is managed by traefik
            nginx['listen_port'] = 80
            nginx['listen_https'] = false
            nginx['proxy_set_headers'] = {
              "X-Forwarded-Proto" => "https",
              "X-Forwarded-Ssl" => "on"
            }
        labels:
          # Enable proxy through traefik and https
          - "traefik.enable=true"
          - "traefik.http.routers.gitlab.rule=Host(`gitlab.enoks.fr`)"
          - "traefik.http.routers.gitlab.entrypoints=websecure"
          - "traefik.http.routers.gitlab.tls=true"
          - "traefik.http.routers.gitlab.tls.certresolver=letsencrypt"
          # Tell Traefik to use the port 80 to connect to container/service: gitlab
          # because image has more than one exposed port. trafefik take the first by default
          - "traefik.http.services.gitlab.loadbalancer.server.port=80"
        ports:
        - "2221:22"
        volumes:
          # GITLAB_HOME is defined in .env file:
          - "$GITLAB_HOME/config:/etc/gitlab"
          - "$GITLAB_HOME/logs:/var/log/gitlab"
          - "$GITLAB_HOME/data:/var/opt/gitlab"
Setup - Deploy
  ## Create folders to mount them as volumes
  mkdir -p /opt/data/gitlab/config /opt/data/gitlab/data   /opt/data/gitlab/logs
  # create docker-compose.yml in /opt/data/gitlab
  docker-compose up -d
  # Get default password
  cat /opt/data/gitlab/config/initial_root_password

Gitlab runner

  • Install gitlab-runner Service : https://docs.gitlab.com/runner/install/linux-manually.html
  • Register a runner executor : https://docs.gitlab.com/runner/register/
Install
  ## Ubuntu
  sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
  sudo chmod +x /usr/local/bin/gitlab-runner
  #Create a GitLab CI user
  sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
  #Install and run as service:
  sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
  sudo gitlab-runner start
Register a runner executor
    # docker executor to build doc.enoks.fr
    gitlab-runner register -h  # to see all options

    sudo gitlab-runner register \
      --non-interactive \
      --url "https://gitlab.example.com/" \
      --registration-token "YOUR_TOKEN" \
      --executor "docker" \
      --docker-image alpine:latest \
      --docker-volumes /opt/application/mk:/mkdocs \
      --description "docker-runner to build mkdocs site" \
      --tag-list "docker,mk" \
      --run-untagged="true" \
      --locked="false" \
      --access-level="not_protected"

    # conf will be saved here: /etc/gitlab-runner/config.toml for next update
    # Add 'pull_policy = "if-not-present" ' to avoid pulling image each time

If you set a Shell runner executor and you got ERROR: Job failed (system failure): prepare environment: exit status 1
You should comment the content of /home/gitlab-runner/.bash_logout