LoginSignup
1
0

More than 1 year has passed since last update.

GitLab(オムニバス版)でPlantUMLを有効化する方法

Last updated at Posted at 2021-07-05

なぜかGitLab公式の通りに設定してもうまくいかなかったので、試行錯誤してうまくいった方法です。

実行環境

私の環境は以下の通りです。

  • Ubuntu 18.04.5
  • GitLab-ce 14.0.1 (Omnibus版) ※Dockerを使わず直接apt installしています。

PlantUML ServerをDockerで起動

まずPlantUMLは描画用のWebサーバーを立てないといけないので今回はDockerを使用します。
コマンドは以下です。

sudo docker run --restart=on-failure:10 -d --name plantuml -p 8085:8080 plantuml/plantuml-server:tomcat

--restart=on-failure:10としているのは、うちのサーバーは定期的に落としているので、再起動時にDockerサービスが上がったタイミングで一緒にコンテナも起動してもらう様にする為です。

ポート番号8085は好きな番号で構いません。

GitLabの設定ファイル

オムニバスパッケージ版ではおなじみの/etc/gitlab/gitlab.rbに追記を行います。
以下を追記してください。

nginx['custom_gitlab_server_config'] = "location /-/plantuml { \n rewrite ^/-/plantuml/(.*) /$1 break;\n proxy_cache off; \n proxy_pass http://localhost:8085; \n}\n"

その後忘れずにsudo gitlab-ctl reconfigureを実行します。

解説

公式では以下となっています。

# Docker deployment
nginx['custom_gitlab_server_config'] = "location /-/plantuml/ { \n    proxy_cache off; \n    proxy_pass  http://plantuml:8080/; \n}\n"

# Built from source
nginx['custom_gitlab_server_config'] = "location /-/plantuml { \n rewrite ^/-/(plantuml.*) /$1 break;\n proxy_cache off; \n proxy_pass http://localhost:8080/plantuml; \n}\n"

Dockerだから上だろと思って設定したら、GitLabにアクセス出来なくなるという罠が待っていました・・・
plantumlの部分が悪いと思いlocalhostに変えると、今度はちゃんと接続はできるけど、Docker内のtomcatにアクセス拒否を喰らいます。

というわけで下をベースに一部修正を行います。
公式と異なる部分は2点です。
plantuml/(.*)
http://localhost:8085

何をしているかざっくり説明しますと、
指定した条件にマッチするURLでアクセスした時にDocker内のwebサーバーにプロキシする様にしています。
例えばhttps://mygitlab.com/-/plantumlにアクセスすると、http://localhost:8085にプロキシします。
この時、URLパラメータを正規表現で^/-/plantuml/(.*)から/$1に置き換えています。$1は置換前文字列の括弧の中を意味するので、^/-/plantuml/の部分を消しているんですね。
https://mygitlab.com/-/plantuml/png/ABCDEというURLはhttp://localhost:8085/png/ABCDEになります。

plantuml/がいらないというところがミソです。

GitLab Admin AreaでPlantUMLを有効化

GitLabからAdminエリアに入って、(日本語の場合)設定→一般→PlantUMLからURLに、https://mygitlab.com/-/plantuml/を設定します。
mygitlab.comはご自身のサーバーURLを入れる)

これで、GitLab内でPlantUMLが描画される様になります。

1
0
4

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
0