GitLab集成PlantUML

1. 摘要

本文提供了将PlantUML与GitLab集成的逐步指南。它涵盖了从配置PlantUML服务器到在GitLab中启用它的所有内容,并包括代码块以说明必要的命令。通过遵循本指南,您将能够使用PlantUML在GitLab snips、wikis和代码库中创建图表。

2. 前言

当在GitLab集成并正确配置PlantUML后,您可以在snip、Wiki和代码库中创建图表。此GitLab.com上PlantUML默认为所有SaaS用户启用,不需要任何额外配置。

要在自管理实例上设置PlantUML,必须:

  • 配置PlantUML服务器。
  • 配置本地PlantUML访问。
  • 配置PlantUML安全性。
  • 启用PlantUML。

3. 配置PlantUML服务器

如果你的服务器是debian或ubuntu系列, 可以使用源码安装plantuml server. 如果是其他类型的服务器, 建议使用docker安装plantuml server.
本教程主要讲解docker启动plantuml server.

使用下面的命令即可快速启动一个plantuml server容器.

1
2
3

docker run -d --name plantuml -p 8080:8080 -e PLANTUML_LIMIT_SIZE=8192m -e PLANTUML_FONT_PATH=/usr/share/fonts/truetype/dejavu/ plantuml/plantuml-server:tomcat

确认容器启动没有问题后, 将容器设置为开机自启.

1
2
3

docker update --restart=always plantuml

如果你的gitlab服务器本身就是使用docker-compose启动的, 那么可以在docker-compose的配置文件中, 可以参考下面配置添加plantuml-server

1
2
3
4
5
6
7
8
9
10
11
version: "3"
services:
gitlab:
image: 'gitlab/gitlab-ee:12.2.5-ee.0'
environment:
GITLAB_OMNIBUS_CONFIG: |
nginx['custom_gitlab_server_config'] = "location /-/plantuml/ { \n proxy_cache off; \n proxy_pass http://plantuml:8080/; \n}\n"

plantuml:
image: 'plantuml/plantuml-server:tomcat'
container_name: plantuml

4. 配置本地PlantUML访问

PlantUML服务器在您的服务器上运行,因此默认情况下无法从外部访问。您的服务器必须捕获PlantUML调用gitlab请求https://gitlab.example.com/-/plantuml/并将它们重定向到PlantUML服务器。根据您的设置,URL为以下任一项:

http://plantuml:8080/
http://localhost:8080/

如果使用安全协议TLS运行GitLab,则必须配置此重定向,因为PlantUML使用不安全的HTTP协议。较新的浏览器(如Google Chrome 86+)不会在通过HTTPS提供的页面上加载不安全的HTTP资源。所以需要添加额外的配置.

要启用此重定向,请执行以下操作:
根据您的设置方法,在/etc/gitlab/gitlab.rb中添加以下行:

1
2
3
4

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

要激活更改,请运行以下命令:

1
2
3

sudo gitlab-ctl reconfigure

重启gitlab

1
2
3

sudo gitlab-ctl restart

5. 开启 PlantUML

启动完成后,需要在 GitLab 上配置开启 PlantUML,管理员登录 -> Admin Area -> Settings,复选框选中 Enable PlantUML,输入 PlantUML URL(就是刚刚启动的 PlantUML Server 服务监听地址)例如:http://your_plantuml_server_host:8080。好了现在可以开始 PlantUML 之旅了。

6. 关联阅读

gitlab安装升级及迁移

使用gitlab issue board的四种方式

GitLab集成PlantUML

gitlab-runner安装与配置

macOS上安装gitlab-runner安装与配置

ubuntu上安装gitlab-runner安装与配置

windows上安装gitlab-runner

gitlab CICD基础

7. 参考文档

PlantUML and GitLab