kokoichi206 / routines

0 stars 0 forks source link

ラズパイに Gitlab 導入 #4

Open kokoichi206 opened 2 years ago

kokoichi206 commented 2 years ago

参考リンク

sudo apt-get install -y curl openssh-server ca-certificates apt-transport-https
sudo curl https://packages.gitlab.com/gpg.key | sudo apt-key add - 
sudo curl -o /etc/apt/sources.list.d/gitlab_ce.list "https://packages.gitlab.com/install/repositories/gitlab/raspberry-pi2/config_file.list?os=debian&dist=jessie" && sudo apt-get update
sudo apt install -y gitlab-ce 
Screen Shot 2022-04-22 at 2 07 44
kokoichi206 commented 2 years ago

メモ

本当は別の(メイン以外の)ラズパイに導入したい(ラズパイ同士の接続等)

kokoichi206 commented 2 years ago

Gitlab がうまく起動できてなさそう

raspberry pi + ubuntu が gitlab の公式の対象外っぽいので、ノートパソコンで試す

kokoichi206 commented 2 years ago

CentOS7 on ノートパソコン

インストール時エラー

$ sudo EXTERNAL_URL="http://192.168.200.50:10080" yum install -y gitlab-ee
[sudo] password for Koko: 
Loaded plugins: axelget, fastestmirror, langpacks
No metadata available for adobe-linux-x86_64
No metadata available for base
No metadata available for centos-sclo-rh
No metadata available for centos-sclo-sclo
No metadata available for code
No metadata available for docker-ce-stable
No metadata available for epel
No metadata available for extras
No metadata available for forensics
No metadata available for forensics-splunk
repomd.xml                                             | 1.0 kB     00:00     
update gitlab_gitlab-ee metadata successfully
repomd.xml                                             |  951 B     00:00     
update gitlab_gitlab-ee-source metadata successfully
No metadata available for google-chrome
No metadata available for mssql-server-2017
No metadata available for nux-dextop
No metadata available for sublime-text
No metadata available for teamviewer
No metadata available for updates
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * centos-sclo-rh: ftp.iij.ad.jp
 * centos-sclo-sclo: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * nux-dextop: mirror.li.nux.ro
 * updates: ftp.iij.ad.jp
gitlab_gitlab-ee/x86_64/signature                      |  862 B     00:00     
gitlab_gitlab-ee/x86_64/signature                      | 1.0 kB     00:00 !!! 
gitlab_gitlab-ee-source/signature                      |  862 B     00:00     
gitlab_gitlab-ee-source/signature                      |  951 B     00:00 !!! 
(1/2): gitlab_gitlab-ee-source/primary                   |  175 B   00:01     
(2/2): gitlab_gitlab-ee/x86_64/primary                   | 3.5 MB   00:02     
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ee.x86_64 0:14.3.3-ee.0.el7 will be updated
---> Package gitlab-ee.x86_64 0:14.9.3-ee.0.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
 Package        Arch        Version               Repository             Size
==============================================================================
Updating:
 gitlab-ee      x86_64      14.9.3-ee.0.el7       gitlab_gitlab-ee      1.0 G

Transaction Summary
==============================================================================
Upgrade  1 Package

Total download size: 1.0 G
Downloading packages:
No Presto metadata available for gitlab_gitlab-ee
gitlab-ee-14.9.3-ee.0.el7.x86_64.rpm                   |    0 B     00:03 ... 
No Presto metadata available for gitlab_gitlab-ee
gitlab-ee-14.9.3-ee.0.el7.x86_64.rpm                     | 1.0 GB   03:40     
Running transaction check
Running transaction test

Transaction check error:
  installing package gitlab-ee-14.9.3-ee.0.el7.x86_64 needs 1324MB on the / filesystem

Error Summary
-------------
Disk Requirements:
  At least 1324MB more space needed on the / filesystem.

FUC

kokoichi206 commented 2 years ago

Laptop

やったこと

kokoichi206 commented 2 years ago

TODO

kokoichi206 commented 2 years ago

Please configure a URL for your GitLab instance by setting external_url configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure

kokoichi206 commented 2 years ago
$ sudo gitlab-rake gitlab:env:info

System information
System:     Ubuntu 22.04
Current User:   git
Using RVM:  no
Ruby Version:   2.7.5p203
Gem Version:    3.1.4
Bundler Version:2.2.33
Rake Version:   13.0.6
Redis Version:  6.2.6
Sidekiq Version:6.4.0
Go Version: unknown

GitLab information
Version:    14.10.0
Revision:   88da5554d96
Directory:  /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.7
URL:        http://kokoichi0305.mydns.jp
HTTP Clone URL: http://kokoichi0305.mydns.jp/some-group/some-project.git
SSH Clone URL:  git@kokoichi0305.mydns.jp:some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:

GitLab Shell
Version:    13.25.1
Repository storage paths:
- default:  /var/opt/gitlab/git-data/repositories
GitLab Shell path:      /opt/gitlab/embedded/service/gitlab-shell
kokoichi206 commented 2 years ago
$ ls /var/opt/gitlab/
alertmanager  gitlab-ci        gitlab-workhorse  postgres-exporter       trusted-certs-directory-hash
backups       gitlab-exporter  grafana           postgresql
bootstrapped  gitlab-kas       logrotate         prometheus
git-data      gitlab-rails     nginx             public_attributes.json
gitaly        gitlab-shell     node-exporter     redis
kokoichi206 commented 2 years ago

5APyU1x9eJooxznz6/FIzfIJaQ03MqOCapI9vHOAYR4=

気になる

https://syachiku.net/docker-gitlab-gitlab-runner/

kokoichi206 commented 2 years ago

Runner 登録

参考にしたサイト

Enter the GitLab instance URL (for example, https://gitlab.com/):
http://192.168.0.5/
Enter the registration token:
GG2eXR123kb1RGFze-NR
Enter a description for the runner:
[ubuntu]: raspberrypi
Enter tags for the runner (comma-separated):
raspi
Enter optional maintenance note for the runner:

ERROR: Registering runner... failed                 runner=GG2eXR12 status=couldn't execute POST against http://192.168.0.5/api/v4/runners: Post "http://192.168.0.5/api/v4/runners": dial tcp 192.168.0.5:80: connect: connection refused
kokoichi206 commented 2 years ago

これ、何を選んだらいいんだろう

DockerやKubernetes かと思って docker にした

Screen Shot 2022-06-23 at 8 23 13

default Docker image も選ばないといけないっぽい

あ、あえての ruby3.1.1 ..

kokoichi206 commented 2 years ago

ラズパイを Runner として登録できた

Screen Shot 2022-06-23 at 8 28 38

この後、しばらく待っても Runner has never contacted this instance 的な感じで疎通できてなかった(?)

以下コマンドで green にはなった

gitlab-runner verify
kokoichi206 commented 2 years ago

pending のまま始まらない問題

stack overflow

If you did not started gitlab-runner yet

gitlab-runner start system-mode execution

sudo gitlab-runner run user-mode execution

gitlab-runner run

sudo gitlab-runner verify
sudo gitlab-runner start
sudo gitlab-runner run
ERROR: Job failed (system failure): Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied (docker.go:863:0s)
kokoichi206 commented 2 years ago

system-mode execution だとつながらないし、user-mode execution だと permission error が起こる!

Gitlab Runner を Docker で!

$ cat docker-compose.yml
version: '3.7'

services:
  gitlabee-runner:
    image: gitlab/gitlab-runner:alpine
    container_name: gitlabee-runner
    volumes:
      - gitlab_home_runner_config:/home/gitlab-runner
      - gitlab_etc_runner_config:/etc/gitlab-runner
      # this is important as it needs to talk to your local docker daemon from within the container instance
      - /var/run/docker.sock:/var/run/docker.sock
    # This is not required to have but is something I do for all my service
    restart: unless-stopped

volumes:
  gitlab_home_runner_config:
    # external: true // Specify if you wish to create and manage yourself
  gitlab_etc_runner_config:
    # external: true // Specify if you wish to create and manage yourself
$ docker-compose up -d

$ docker exec -it gitlabee-runner bash
bash-5.1# gitlab-runner register

# どっちかな気きする
$ gitlabee-runner  | Runtime platform                                   
 arch=amd64 os=linux pid=8 revision=5316d4ac version=14.6.0

# どっちかな気きする
$ gitlabee-runner  | Starting multi-runner from /etc/gitlab-runner/config.toml...  builds=0

$ docker logs gitlabee-runner

Links

kokoichi206 commented 2 years ago

Gitlab を公開

https://my.domain/gitlab/

gitlab パスへアクセス ↔︎ local ip を使って家の gitlab へリバースプロキシ

をしようと考えています。

問題は、非認証時には login path へリダイレクトされることになっているが、その宛先が http://192.168.0.5:12000/users/sign_in となっていること。 このリダイレクトは、gitlab マシン側のリダイレクト。

これがこれがそのまま返っているため、 https://kokoichi0206.mydns.jp//users/sign_in となっている。 本当は https://kokoichi0206.mydns.jp/gitlab/users/sign_in となってほしい。(上記アドレスを直接打ち込むとうまくいく)

また、リソースに関しても 404 が連発する。

今の設定(/etc/apache2/conf-available/reverse_proxy.conf)。

<IfModule mod_proxy.c>
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>
    RewriteEngine On
    ProxyPreserveHost On
    # 転送先サーバーとディレクトリ
    ProxyPass /gitlab/ http://192.168.0.5:12000/
    ProxyPassReverse /gitlab/ http://192.168.0.5:12000/
</IfModule>

解決策

Reverse proxy から一部パスを除外

<IfModule mod_proxy.c>
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>

    # ここ!
    ProxyPass /imgs !

    RewriteEngine On
    ProxyPreserveHost On
    # 転送先サーバーとディレクトリ
    ProxyPass / http://192.168.0.5:12000/
    ProxyPassReverse / http://192.168.0.5:12000/
</IfModule>
sudo service apache2 restart
kokoichi206 commented 1 year ago

Routing の件

これは他の例だけど、アプリ側で調整して proxy 先のパスも書き換えるのが良いっぽい https://github.com/sameersbn/docker-redmine#apache-proxy-as-frontend

/etc/apache2/conf-enabled/reverse_proxy.conf に以下を記載

# REDMINE Pass connections to docker
ProxyRequests Off
ProxyPass /redmine http://127.0.0.1:10083/redmine/
ProxyPassReverse /redmine http://127.0.0.1:10083/redmine/