1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docker版 Gitlab の構築

Last updated at Posted at 2024-08-19

実現したいこと

GitLab 並びに DB管理(Adminer)、Runnerを1つのDockerで定義してみる

ARM版(ubantu 22.04対応)のgithub支援を始めてます。

2025.04.25時点の最新がこちらです。
image: esquina/gitlab:17.11.1-ce.0
image: esquina/gitlab:17.11.1-ee.0

ご注意:IntelやAMD CPUを利用されている場合はimageの指定を
標準へ変更して頂くべきです。
参考 image: gitlab/gitlab-ce:..*-ce.0

前提

サイト【https://sample.jp】
として、記載しているため、HTTPS(証明書)の考慮が必要です。
「adminer」は別途Windowsサーバなどローカルから参照することを想定。

GitLabとは?

GitLab(ギットラボ)は、Gitリポジトリをホスティングするソフトウェアで、ソフトの計画から開発・テスト・リリース・運用・監視というDevOps(デプオプス)ライフサイクルに必要な機能がすべて搭載されている。(引用元:aslead)連携機能を利用するにはハードルが高く、セキュリティの脆弱性も垣間見えるのが実情。業務では有償サポートが欲しいところ。

Adminerとは?

Adminerは、PHPで作られているデータベース管理ツール

GitLab Runnerとは?

GitLab RunnerとはGitLab CI/CDにおけるjobの実行主体

事前準備

  • docker engine

向いているひと

OSを汚したくないきれい好きな人向け。

Docker構成

ディレクトリ

gitlab
├── compose.yml
├── config
|     ├── gitlab.rb
|     └── gitlab-secrets.json 
├── data
├── backup
└── logs

gitlab-runner
└── config

構成ファイル

compose.yml
services:
  gitlab:
    image: esquina/gitlab:17.11.1-ce.0
    restart: always
    hostname: 'gitlab'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://sample.jp'
      #gitlab_rails
      gitlab_rails['time_zone'] = 'Asia/Tokyo'
      #Postgres for gitlab 17.3.0
      postgresql['shared_buffers'] = "512MB"
      #Postgres
      postgresql['listen_addresses'] = '*'
      postgresql['log_timezone'] = 'Asia/Tokyo'
    ports:
      - "443:443"
      - "80:80"
      - "5432:5432"
    volumes:
      - ~/gitlab/config:/etc/gitlab
      - ~/gitlab/logs:/var/log/gitlab
      - ~/gitlab/data:/var/opt/gitlab
      - ~/gitlab/backup:/var/opt/gitlab/backups
      - /var/run/docker.sock:/var/run/docker.sock
    shm_size: '2gb'
    networks:
      vpn_net:
  gitlab-runner:
    image: gitlab/gitlab-runner:alpine-v17.11.0
    restart: always
    volumes:
      - ~/gitlab-runner/config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      vpn_net:
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - gitlab
    networks:
      vpn_net:

networks:
  vpn_net:
    driver: bridge
    enable_ipv6: false
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
gitlab.rb
##
## 以下、設定をcompose.ymlに入れると、warning になるためそのまま残しております。
##
nginx['redirect_http_to_https'] = true
registry_nginx['redirect_http_to_https'] = true
mattermost_nginx['redirect_http_to_https'] = true
# ALB経由になるので、ヘッダーを修正
nginx['proxy_set_headers'] = {
    "Host" => "$http_host_with_default",
    "X-Real-IP" => "$remote_addr",
    "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
    "X-Forwarded-Proto" => "https",
    "X-Forwarded-Ssl" => "off",
    "Upgrade" => "$http_upgrade",
    "Connection" => "$connection_upgrade",
    "Access-Control-Allow-Origin" => "*"
}

実行方法

compose.ymlのディレクトリがある場所まで移動する。
その後、以下のコマンドで起動

docker-compose up -d
docker ps
NAME                     IMAGE                                 COMMAND                  SERVICE         CREATED         STATUS                            PORTS
gitlab-adminer-1         adminer                               "entrypoint.sh php -…"   adminer         2 minutes ago   Up 2 minutes                      0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
gitlab-gitlab-1          esquina/gitlab:17.11.1-ee.0            "/assets/wrapper"        gitlab          2 minutes ago   Up 2 minutes (health: starting)   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 22/tcp, 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp
gitlab-gitlab-runner-1   gitlab/gitlab-runner:alpine-v17.11.0   "/usr/bin/dumb-init …"   gitlab-runner   2 minutes ago   Up 2 minutes

補足

上記にて「compose.yml」にて「gitlab.rb」を指定する場合、docker内に入り(docker exec -it gitlab-gitlab-1 bash など)「gitlab-ctl reconfigure」すると、情報がなくエラーになります。そのため、 「compose.yml」にて、設定した分は「gitlab.rb」へ追記しておいた方が無難です。

「compose.yml」指定のメリットは、一部パラメータは初期化されてしまいます。そのようなパラメータを「compose.yml」から直接指定することができるため、上記形式を採用しております。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?