LoginSignup
0
4

More than 5 years have passed since last update.

vagrantとdockerで自分用GitLabを構築

Posted at

目的

GitHubがMicrosoftに買収されてからGitLabに移行する人が多かったので、流行りに乗ってみました。
乗るしかないでしょこのビックウェーブに!

構築環境

Vagrant + docker(docker-compose) で構築しています。

名前 バージョン
ホストOS Windows8.1
VirtualBox 5.2.12 r122591 (Qt5.6.2)
Vagrant 2.1.2
BOX ubuntu/bionic64
docker 18.03.1-ce
docker-compose 1.17.1
コンテナ gitlab/gitlab-ce:latest

構築方法

任意のフォルダにVagrantfiledocker-compose.ymlを置きます。
PowerShellなどで、フォルダに移動して、vagrant upとすれば自動で作成してくれます。
後は、指定したIPにブラウザでアクセスするだけです。
(vagrant up後にGitLabが起動するため、少し時間がかかってます。)

Vagrantfiledocker-compose.ymlの中身は下記になります。

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  # 使用したいボックスを選択
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "ubuntu/bionic64"

  # IPアドレス(DHCPの場合は、", ip:~"は不要)
  config.vm.network "public_network", ip: "192.168.0.100"

  # ホスト名
  config.vm.hostname = "VM-GitLab"

  # 共有フォルダ
  # dockerfileの場所を共有フォルダとしています。
  config.vm.synced_folder "E:\\dockerfile", "/dockerfile", type: "virtualbox"

  config.vm.provider "virtualbox" do |vb|

    # Display the VirtualBox GUI when booting the machine
    vb.gui = false

    # 仮想マシン名
    vb.name = "GitLab"

    # CPU数
    vb.cpus = 2

    # メモリー
    # 4096Mbyteが推奨らしい。
    vb.memory = "4096"

  end

  # シェルスクリプト
  config.vm.provision "shell", inline: <<-SHELL

    apt update
    apt install -y apt-transport-https ca-certificates curl software-properties-common git
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    apt update
    apt install -y docker-ce
    apt install -y docker-compose
    cd /dockerfile
    docker-compose up -d

    echo "TZ=Asia/Tokyo" > /etc/environment

  SHELL

end

docker-compose.yml

docker-compose.yml
web:
  # 使用するイメージ
  image: 'gitlab/gitlab-ce:latest'
  # ゲストOSが起動したら自動的に起動させる。
  restart: always
  # ホスト名
  hostname: 'gitlab.example.com'
  # 環境変数
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://192.168.0.100'
      gitlab_rails['gitlab_shell_ssh_port'] = 2222
  # ポートフォワード
  ports:
    - '80:80'
    - '443:443'
    - '2222:22'
  # 共有ディレクトリ
  # GitLabデータをゲストOSの上に保存する。
  volumes:
    - '/srv/gitlab/config:/etc/gitlab'
    - '/srv/gitlab/logs:/var/log/gitlab'
    - '/srv/gitlab/data:/var/opt/gitlab'

おわりに

はじめはdocker-compose.ymlの環境変数らへんの設定がわからずに苦労しました。
gitlab_railsの設定があまりわかってないので、もう少し調べたいと思ってます。

0
4
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
0
4