履歴: オンプレGitLabでgit+CI+npmサーバー2024
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 15 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2024/10/11 18:39:53 | オンプレGitLabでgit+CI+npmサーバー2024 最新版 | 40,236 | +1 | -1 | 表示 | 差分 | — |
| 2024/10/11 18:39:53 | オンプレGitLabでgit+CI+npmサーバー2024 | 40,242 | +5 | -2 | 表示 | 差分 | 選択 |
| 2024/9/21 9:34:07 | オンプレGitLabでgit+CI+npmサーバー2024 | 40,114 | +46 | -2 | 表示 | 差分 | 選択 |
| 2024/9/10 19:22:18 | オンプレGitLabでgit+CI+npmサーバー2024 | 39,136 | +13 | -7 | 表示 | 差分 | 選択 |
| 2024/9/10 17:24:01 | オンプレGitLabでgit+CI+npmサーバー2024 | 38,907 | +119 | -2 | 表示 | 差分 | 選択 |
| 2024/9/9 10:31:44 | オンプレGitLabでgit+CI+npmサーバー2024 | 36,273 | +15 | -5 | 表示 | 差分 | 選択 |
| 2024/9/9 8:03:14 | オンプレGitLabでgit+CI+npmサーバー2024 | 36,083 | +30 | -8 | 表示 | 差分 | 選択 |
| 2024/9/9 2:20:03 | オンプレGitLabでgit+CI+npmサーバー2024 | 35,619 | +166 | -18 | 表示 | 差分 | 選択 |
| 2024/9/8 19:19:09 | オンプレGitLabでgit+CI+npmサーバー2024 | 31,171 | +129 | -1 | 表示 | 差分 | 選択 |
| 2024/9/8 12:41:21 | オンプレGitLabでgit+CI+npmサーバー2024 | 27,587 | +474 | -6 | 表示 | 差分 | 選択 |
| 2024/9/7 22:45:54 | オンプレGitLabでgit+CI+npmサーバー2024 | 14,324 | +27 | -2 | 表示 | 差分 | 選択 |
| 2024/9/7 22:12:54 | オンプレGitLabでgit+CI+npmサーバー2024 | 13,784 | +307 | -44 | 表示 | 表示中 | 選択 |
| 2024/9/7 10:39:10 | オンプレGitLabでgit+CI+npmサーバー2024 | 5,232 | +17 | -5 | 表示 | 差分 | 基準 |
| 2024/9/7 1:22:49 | オンプレGitLabでgit+CI+npmサーバー2024 | 5,096 | +50 | -23 | 表示 | 差分 | 選択 |
| 2024/9/7 0:49:18 | オンプレGitLabでgit+CI+npmサーバー2024 | 4,572 | — | — | 表示 | — | 選択 |
基準: オンプレGitLabでgit+CI+npmサーバー2024 (2024/9/7 10:39:10) → 比較: オンプレGitLabでgit+CI+npmサーバー2024 (2024/9/7 22:12:54)
@@ -1,4 +1,4 @@
-#author("2024-09-07T01:39:10+00:00","default:administrator","administrator")
+#author("2024-09-07T13:12:54+00:00","default:administrator","administrator")
[[プログラミング/svelte]]
* 自前サーバーで GitLab を動かしてプライベートな npm プロジェクトなどを置きたい [#p3da9108]
@@ -26,11 +26,12 @@
を見ながら docker イメージで動作するよう設定する。
-- サーバーにはすでに docker 環境があって、自分が管理者になっている
-- サーバーには apache2 が https://myserver.com/ への通信を受け付ける状況になっている
-- gitlab は https://myserver.com/gitlab/ というアドレスで動かす
+- ホストサーバーには docker 環境があって、自分が管理者である
+-- gitlab は docker 内で動かす
+- ホストサーバーには apache2 が https://myserver.com/ への通信を受け付ける状況になっている
+- https://myserver.com/gitlab/ というアドレスへの通信を docker 内の gitlab サーバーへ繋ぐ
-という条件で GitLab を動かします。。
+という形で GitLab を動かします。
LANG:console
$ cd ~
@@ -42,10 +43,11 @@
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
- hostname: 'myserver.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://myserver.com/gitlab'
+ nginx['listen_port'] = 80
+ nginx['listen_https'] = false
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '8980:80'
@@ -71,8 +73,157 @@
✔ Network gitlab_default Created 0.0s
✔ Container gitlab-web-1 Started 0.7s
-これでもう立ち上がっている。
+これで docker 内で GitLab サーバーが立ち上がる。
+** 全体としての注意 [#o2bf1916]
+
+上記のようにして動かすと、etc/ フォルダに etc/gitlab.rb というのができて、
+これを書き換えれば設定を変えられる。
+
+設定項目についてはこちらに説明がある。~
+https://gitlab-docs.creationline.com/omnibus/settings/configuration.html
+
+また、ファイルの冒頭には以下の注意書きがある。
+
+ ## GitLab configuration settings
+ ##! This file is generated during initial installation and **is not** modified
+ ##! during upgrades.
+ ##! Check out the latest version of this file to know about the different
+ ##! settings that can be configured, when they were introduced and why:
+ ##! https://gitlab.com/gitlab-org/omnibus-gitlab/blame/master/files/gitlab-config-template/gitlab.rb.template
+
+ ##! Locally, the complete template corresponding to the installed version can be found at:
+ ##! /opt/gitlab/etc/gitlab.rb.template
+
+ ##! You can run `gitlab-ctl diff-config` to compare the contents of the current gitlab.rb with
+ ##! the gitlab.rb.template from the currently running version.
+
+ ##! You can run `gitlab-ctl show-config` to display the configuration that will be generated by
+ ##! running `gitlab-ctl reconfigure`
+
+ ##! In general, the values specified here should reflect what the default value of the attribute will be.
+ ##! There are instances where this behavior is not possible or desired. For example, when providing passwords,
+ ##! or connecting to third party services.
+ ##! In those instances, we endeavour to provide an example configuration.
+
+ ## GitLab URL
+ ##! URL on which GitLab will be reachable.
+ ##! For more details on configuring external_url see:
+ ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
+ ##!
+ ##! Note: During installation/upgrades, the value of the environment variable
+ ##! EXTERNAL_URL will be used to populate/replace this value.
+ ##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
+ ##! address from AWS. For more details, see:
+ ##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
+ # external_url 'GENERATED_EXTERNAL_URL'
+
+ ## Roles for multi-instance GitLab
+ ##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance.
+ ##! Options:
+ ##! redis_sentinel_role redis_master_role redis_replica_role geo_primary_role geo_secondary_role
+ ##! postgres_role consul_role application_role monitoring_role
+ ##! For more details on each role, see:
+ ##! https://docs.gitlab.com/omnibus/roles/index.html#roles
+ ##!
+ # roles ['redis_sentinel_role', 'redis_master_role']
+
+ ## Legend
+ ##! The following notations at the beginning of each line may be used to
+ ##! differentiate between components of this file and to easily select them using
+ ##! a regex.
+ ##! ## Titles, subtitles etc
+ ##! ##! More information - Description, Docs, Links, Issues etc.
+ ##! Configuration settings have a single # followed by a single space at the
+ ##! beginning; Remove them to enable the setting.
+
+ ##! **Configuration settings below are optional.**
+
+一方、例えば data/nginx/conf/gitlab-http.conf に nginx 関連の設定ファイルが見つかるのだけれど、
+こちらの設定ファイルはサーバーを立ち上げ直すと gitlab.rb の内容を元に自動的に生成されるものなので、
+手で書きかえてはいけない。
+
+ちゃんと冒頭に
+
+ # This file is managed by gitlab-ctl. Manual changes will be
+ # erased! To change the contents below, edit /etc/gitlab/gitlab.rb
+ # and run `sudo gitlab-ctl reconfigure`.
+
+などと書かれている。
+
+etc/gitlab.rb を書き換えてしまうと設定情報が docker-compose.yml と gitlab.rb とに分かれてしまうので、どちらか一方にまとめた方がいいのかもしれない。
+
+単純な見やすさからすると docker-compose.yml に書く方が良さそうなのだけれど、
+gitlab-ctl diff-config を使うなら gitlab.rb でもいいのかもしれない。
+
+docker コンテナの外から確認するなら:
+
+ LANG:console
+ $ docker compose exec web gitlab-ctl diff-config
+
+
+** ポートの指定 [#i42dc48e]
+
+外からの接続を受ける apache2 と同じマシンに置くのであれば docker-compose.yml の
+
+ ports:
+ - '8980:80'
+
+のところは
+
+ ports:
+ - '127.0.0.1:8980:80'
+
+として、外からの接続が直接 docker へ行かないようにする。
+
+docker でポートを開けると
+ufw などのファイアウォールで許可してなくても
+外向きにポートが開いてしまうので十分注意する。
+
+** https を名乗りつつ http で待ち受ける [#z2f50ccd]
+
+gitlab の設定で
+
+ GITLAB_OMNIBUS_CONFIG: |
+ external_url 'https://myserver.com/gitlab'
+ nginx['listen_port'] = 80
+ nginx['listen_https'] = false
+
+としている理由は以下の通り。
+
+この docker イメージは external_url の設定を見て、内部の nginx で 80 番で http を待つか、443 番で https を待つかを決めている。
+
+「どちらか片方しか有効にならない」というのが重要な点。
+
+今実現したい構成では、外部から見た gitlab サーバーのアドレスは https://myserver.com/gitlab
+で https 接続になるのだけれど、その暗号化通信は間に入る apache2 が受け持つので
+docker 内の nginx への接続は http になる。
+
+external_url を https としてしまうと gitlab docker は nginx を 443 番で https を待つように設定してしまい 80 番の http では繋がらなくなってしまう。
+
+そこで 80 番で http を待つように設定しているのがこの部分だ。
+
+サーバーに繋ぎに行って「接続をリセットされました」みたいになるときは、
+
+ LANG:console
+ $ sudo less data/nginx/conf/gitlab-http.conf
+
+として gitlab 関連の nginx の設定を確かめるといい。
+
+(これに気付くのにかなり時間がかかりました・・・)
+
+** GITLAB_OMNIBUS_CONFIG で指定可能なその他の設定 [#d7e481ac]
+
+GITLAB_OMNIBUS_CONFIG では
+
+ LANG:console
+ $ sudo less etc/gitlab.rb
+
+として表示される設定項目に値を指定できるので、
+「こんなことできないのかな」と思ったときにはじっくり読むといい。
+
+* apache2 をプロキシサーバーとして接続を中継させる [#g1e47924]
+
ホストマシンの /etc/apache2/sites-enabled/default-ssl.conf に
<IfModule mod_proxy.c>
@@ -100,22 +251,10 @@
とすることで apache2 がプロキシサーバーとして振る舞い、
https://myserver.com/gitlab 以下へのアクセスを http://localhost:8929/gitlab へ転送してくれる。
-この使い方の場合、
+ここで重要なのが AllowEncodedSlashes NoDecode だ。
- ports:
- - '8980:80'
+これをしておかないと、後々 GitLab を npm パッケージサーバーとして使おうとした際に、パッケージリポジトリへの PUT が 404 で失敗する。
-のところは
-
- ports:
- - '127.0.0.1:8980:80'
-
-とした方がよいのかも。
-
-で、結構重要なのが AllowEncodedSlashes NoDecode だ。
-
-これをしておかないと、後々 GitLab を npm サーバーとして使おうとした際に、パッケージリポジトリへの PUT が 404 で失敗する。
-
https://stackoverflow.com/questions/20496963/avoid-nginx-decoding-query-parameters-on-proxy-pass-equivalent-to-allowencodeds
LANG: console
@@ -135,30 +274,26 @@
* メールを送れるように設定する [#aa2a5159]
-ホストで exim4 が動いていて、正しくメールが送れているとする。
+GITLAB_OMNIBUS_CONFIG に
- LANG:console
- $ echo "MAIN_RELAY_NETS = 172.16.0.0/12" | sudo tee -a exim4.conf.localmacros
- $ sudo update-exim4.conf
- $ sudo systemctl restart exim4
-
-とすることで、172.16.???.??? からのメール転送を許可する。
-
-docker-compose.yml には
-
- extra_hosts:
- - "host.docker.internal:host-gateway"
-
-を追加して、コンテナ内から host.docker.internal という名前でホストマシンへ到達できるようにした。
-
-etc/gitlab.rb には、
-
+ gitlab_rails['gitlab_email_from'] = 'gitlab@myserver.com'
+ gitlab_rails['gitlab_email_display_name'] = 'GitLab'
gitlab_rails['smtp_enable'] = true
- gitlab_rails['smtp_address'] = "host.docker.internal"
- gitlab_rails['smtp_port'] = 25
+ gitlab_rails['smtp_address'] = "smtp.server"
+ gitlab_rails['smtp_port'] = 465
+ gitlab_rails['smtp_user_name'] = "smtp user"
+ gitlab_rails['smtp_password'] = "smtp password"
+ gitlab_rails['smtp_domain'] = "example.com"
+ gitlab_rails['smtp_authentication'] = "login"
+ gitlab_rails['smtp_enable_starttls_auto'] = true
+ gitlab_rails['smtp_tls'] = false
+ gitlab_rails['smtp_pool'] = false
-を設定した。
+あたりを追加する。
+設定の仕方はこちらを参照:~
+https://gitlab-docs.creationline.com/omnibus/settings/smtp.html
+
* root でログインする [#u468af48]
初期設定で root という管理者ユーザーが登録されているので、
@@ -169,7 +304,7 @@
LANG:console
$ sudo cat etc/initial_root_password
-* root のパスワードを忘れてしまった場合 [#p77da698]
+** 自分で変更した root のパスワードを忘れてしまった場合 [#p77da698]
https://blog.k-bushi.com/post/tech/environment/construct-gitlab-runner-docker/#gitlab%E3%81%B8%E3%81%AE%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3
@@ -184,7 +319,7 @@
とすればパスワードを設定しなおせるらしい。
-* runner も docker で動かす [#a35f227c]
+* GitLab Runner も docker で動かす [#a35f227c]
同時に使用する人数と比較するとこのサーバーには余裕があるので、
CI サーバーも同じホストで動かしてしまう。
@@ -207,6 +342,134 @@
* runner を GitLab に追加する [#k5e1dceb]
+** GitLab 画面で新しい Runner インスタンスを作成 [#k2bc716a]
+
https://myserver.com/gitlab/admin/runners
-から
+から右上の [New Instance Runner] を押す。
+
+ここでは特別な設定をしないごく一般的な shell の動くサーバーを建てるので、
+
+x Run untagged jobs のチェックを付けて [Create runner]
+
+** docker で動かした Runner と対応付ける [#ka34cbec]
+
+次の画面の Step 1 となっているところで
+
+ $ gitlab-runner register
+ --url https://myserver.com/gitlab
+ --token glrt-iqghvxb-GLHJG9WsFPT6
+
+のようなところをコピーする。
+
+ちょっと手直しをして次の形にして Runnner を起動した docker-compose.yml のあるフォルダで実行。
+
+ $ docker compose exec runner \
+ gitlab-runner register \
+ --url https://myserver.com/gitlab \
+ --token glrt-iqghvxb-GLHJG9WsFPT6
+
+コマンドを起動するといくつか質問に答えることになる。
+
+- GitLab instance URL には指定した https://myserver.com/gitlab が入っているのでそのまま ENTER
+- Enter a name for the runner にはこの Runner を識別する名前を付ける
+- Enter an executor には shell を指定
+
+これで Runner 一覧に正しく追加される。
+
+* CI 動作を試してみる [#jb5189f3]
+
+ LANG: console
+ $ mkdir ~/gitlab-ci-hello
+ $ cd ~/gitlab-ci-hello
+ $ cat <<"EOS" > .gitlab-ci.yml
+ build:
+ script:
+ - echo hello `pwd`
+ - ls -la
+ EOS
+ $ git init
+ $ git add .
+ $ git commit -m "Initial commit"
+
+として .gitlab-ci.yml だけをコミットした git リポジトリを作成する。
+
+GitLab 上でブランクプロジェクトを作ってそこへコミットしてみる。
+
+https://myserver.com/gitlab/projects/new#blank_project
+
+- Project name: gitlab-ci-hello
+- Project url: https://myserver.com/gitlab/myname/gitlab-ci-hello
+- Visibility Level: private
+- Project Configuration: README のチェックを外す
+
+そして Create Project
+
+次のページの Push an existing Git repository の手順で push する。
+
+ LANG:console
+ $ git remote add origin https://myserver.com/gitlab/myname/gitlab-ci-hello.git
+ $ git push --set-upstream origin --all
+ Username for 'https://myserver.com': myname
+ Password for 'https://myname@myserver.com': xxxxxx
+ Enumerating objects: 3, done.
+ Counting objects: 100% (3/3), done.
+ Delta compression using up to 4 threads
+ Compressing objects: 100% (2/2), done.
+ Writing objects: 100% (3/3), 266 bytes | 266.00 KiB/s, done.
+ Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
+ To https://myserver.com/gitlab/myname/gitlab-ci-hello.git
+ * [new branch] master -> master
+ branch 'master' set up to track 'origin/master'.
+ $ git push --set-upstream origin --tags
+ Username for 'https://myserver.com': myname
+ Password for 'https://myname@myserver.com': xxxxxx
+ Everything up-to-date
+
+push 時には gitlab サーバーのユーザー名とパスワードを聞かれるので入力する。
+
+GitLab の画面で確認すると、
+
+&ref(job-success.png,,50%);
+
+こちらのようにコミット番号の隣に緑のチェックマークがついて、
+ジョブが成功したことを確認できる。
+
+このチェックをクリックして中を見ると、
+
+ LANG:console
+ Running with gitlab-runner 17.3.1 (66269445)
+ on myrunnner1 t2X9wkLjw, system ID: r_FoHQflE05Zou
+ Preparing the "shell" executor 00:00
+ Using Shell (bash) executor...
+ Preparing environment 00:00
+ Running on 8163caea6de5...
+ Getting source from Git repository 00:00
+ Fetching changes with git depth set to 20...
+ Initialized empty Git repository in /home/gitlab-runner/builds/t2X9wkLjw/0/gitlab/myname/gitlab-ci-hello/.git/
+ Created fresh repository.
+ Checking out cc71a4d9 as detached HEAD (ref is master)...
+ Skipping Git submodules setup
+ Executing "step_script" stage of the job script 00:00
+ $ echo hello `pwd`
+ hello /home/gitlab-runner/builds/t2X9wkLjw/0/gitlab/myname/gitlab-ci-hello
+ $ ls -la
+ total 16
+ drwxrwxr-x 3 gitlab-runner gitlab-runner 4096 Sep 7 13:03 .
+ drwxrwxr-x 4 gitlab-runner gitlab-runner 4096 Sep 7 13:03 ..
+ drwxrwxr-x 6 gitlab-runner gitlab-runner 4096 Sep 7 13:03 .git
+ -rw-rw-r-- 1 gitlab-runner gitlab-runner 53 Sep 7 13:03 .gitlab-ci.yml
+ Cleaning up project directory and file based variables 00:00
+ Job succeeded
+
+のようにして、
+
+ LANG:console
+ $ echo hello `pwd`
+
+と
+
+ LANG:console
+ $ ls -la
+
+が正しく実行されていることを確認できる。