Build GitLab / Mattermost with DockerForWindows

Build GitLab / Mattermost with DockerForWindows

Introduction

I wanted to try various things using the Mattermost API, and when I tried to build a GitLab environment quickly, I was addicted to it unexpectedly, so I will leave what I did. What I want to do is build a GitLab environment using DockerForWindows.

Things that move

I put it on GitHub. (https://github.com/shimi58/CentOS8_GitLab) However, the Mattermost setting changes each time you build it, so the procedure described below is required.

Operation check environment version
Windows10 Home Edition Version 2004
Docker for Windows 2.4.0.0

Environment

Build CentOS 8 on Docker

I will describe it in the Dockerfile. The result is as follows.

FROM centos:8

#Localizing into Japanese
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial && \
    dnf -y upgrade && \
    dnf -y install glibc-locale-source && \
    dnf clean all && \
    localedef -f UTF-8 -i ja_JP ja_JP.UTF-8 && \
    ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

#C LANG for Gitlab installation.UTF-Change to 8
ENV LANG="C.UTF-8" \
    LANGUAGE="ja_JP:ja" \
    LC_ALL="ja_JP.UTF-8"

#root password setting
RUN echo "root:root" | chpasswd

# =====
# BASE packages
# =====
RUN dnf install -y  openssl openssl-devel openssh openssh-server wget sudo unzip  which tree git firewalld

# =====
#Install GitLab CE
# =====
RUN curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

RUN dnf install -y gitlab-ce

docker-compose.yml


version: '3'
services:
  centos8:
    container_name: "centos8"
    build: ./
    tty: true
    privileged: true
    command: /sbin/init   
    ports:
      - "2222:22"
      - "9080:9080" #For GitLab
      - "9081:9081" #For GitLab Mattermost
      - '10443:443'
    volumes:
      #Persistence according to the formula
      - './srv/gitlab/config:/etc/gitlab'   #Place GitLab definition file
      - './srv/gitlab/logs:/var/log/gitlab' #GItLab log file output
      - './srv/gitlab/data:/var/opt/gitlab' #GItLab data storage

Supplement

--Japanese environment settings

```
#Localizing into Japanese
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial && \
    dnf -y upgrade && \
    dnf -y install glibc-locale-source && \
    dnf clean all && \
    localedef -f UTF-8 -i ja_JP ja_JP.UTF-8 && \
    ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

#C LANG for Gitlab installation.UTF-Change to 8
ENV LANG="C.UTF-8" \
    LANGUAGE="ja_JP:ja" \
    LC_ALL="ja_JP.UTF-8"
```

I referred to this (https://qiita.com/polarbear08/items/e5c00869c7566db5f7b8). If you do not set LANG to C.UTF-8, it will stop around DB migration of "gitlab-ctl reconfigure", so be careful.

--Install GitLab CE

```cmd
RUN curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

RUN dnf install -y gitlab-ce
```

This is the official procedure. (Note that the official sample is gitlab-ee)

--Data persistence

```docker-compose.yml
    volumes:
      #Persistence according to the formula
      - './srv/gitlab/config:/etc/gitlab'   #Place GitLab definition file
      - './srv/gitlab/logs:/var/log/gitlab' #GItLab log file output
      - './srv/gitlab/data:/var/opt/gitlab' #GItLab data storage
```

If this is set, the data will be retained even if the container is dropped.

Construction procedure

  1. Place the above Dockerfile and docker-compose.yml in any directory.

  2. Move to the placed directory and start the container

    docker-compose up -d
    
  3. Place gitlab.rb in the specified folder

    srv
    └─gitlab
        ├─config
        │      gitlab.rb
        │
        ├─data
        └─logs
    

This file can be found here (https://github.com/shimi58/CentOS8_GitLab).

  1. Set the port of GitLab

    external_url 'http://localhost:9080'
    
  2. Enable GitLab Mattermost

    mattermost_external_url 'http://localhost:9081'
    mattermost['enable'] = true
    
  3. Log in to the container

    docker exec -it centos8 bash
    
  1. Reflect GitLab settings

    sudo /opt/gitlab/embedded/bin/runsvdir-start &
    gitlab-ctl reconfigure
    
  1. After the reflection, access GitLab

    http://localhost:9080
    

--Mattermost can also be displayed at this timing

    ```url
    http://localhost:9081
    ```

Supplement

――After that, it will be the procedure of Mattermost SSO cooperation

  1. After completing the initial password settings, log in

    image.png

  1. Check the Mattermost settings --Move to "Admin Area"-> "Applications" --If there is already a definition for Mattermost, use it, if not, create a new one (* It will not be displayed if the mattermost setting in gitlab.rb is enabled)

    image.png

  1. Reflect the "Application ID" and "Secret" confirmed above in gitlab.rb At the same time, add the necessary settings

    mattermost['gitlab_enable'] = true #SSO enabled
    mattermost['gitlab_id'] = "5e7f43cdf588e92c8b0ca589832c64dd5094969c5848667a09e50ffe4834c065"      #Application ID
    mattermost['gitlab_secret'] = "23791f7219f6782f38c9c1f462c5e715e88216ee13d3513a122dc9c302ba130b"  #secret
    mattermost['gitlab_auth_endpoint'] = "http://localhost:9080/oauth/authorize" #Enter the URL of GitLab
    mattermost['gitlab_token_endpoint'] = "http://localhost:9080/oauth/token"    #Enter the URL of GitLab
    mattermost['gitlab_user_api_endpoint'] = "http://localhost:9080/api/v4/user" #Enter the URL of GitLab
    
  2. Reflect GitLab settings

    gitlab-ctl reconfigure
    
  3. From Mattermost, select "Sign in with GitLab" and log in

    image.png

  1. Confirm that the transition to the Mattermost screen is displayed.

    image.png

finally

GitLab built this time is heavy even with CORE i7 and memory 16G. image.png

2020/10/18 postscript

After rebuilding the container, restore persistent data. Gitlab-ctl reconfigure is required to reflect.

Recommended Posts

Build GitLab / Mattermost with DockerForWindows
Build Doma1 with Ant
Build Growai with Centos7
Build Java with Wercker
Build bazel with alpine
(For myself) Build gitlab with ubuntu18.04 + docker for home (Note)
Build softether VPN with Centos7.
Set up GitLab with docker
Build docker environment with WSL
Build Ubuntu 18.04.5 with dual boot
Ninja-build with smart differential build
Build AWS Lambda with Quarkus
[Introduction] Build MVC with Scala
Build DynamoDB local with Docker
Build Couchbase local environment with Docker
Build a Java project with Gradle
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Build a web application with Javalin
Java build with mac vs code
Build Virtual Box & Vagrant & Centos7 & GitLab
Build jooby development environment with Eclipse
Build docker + laravel environment with laradock
Build WebRTC Janus with Docker container
Spring Boot gradle build with Docker
Make a daily build of the TOPPERS kernel with Gitlab and Docker