2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference, howto
---
2021-03-11 19:13:27 +05:30
# PlantUML & GitLab **(FREE)**
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/8537) in GitLab 8.16.
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
When [PlantUML ](https://plantuml.com ) integration is enabled and configured in
2021-03-11 19:13:27 +05:30
GitLab you can create diagrams in AsciiDoc and Markdown documents
2020-05-24 23:13:21 +05:30
created in snippets, wikis, and repositories.
2017-08-17 22:00:37 +05:30
## PlantUML Server
2021-03-11 19:13:27 +05:30
Before you can enable PlantUML in GitLab; set up your own PlantUML
server to generate the diagrams.
2018-03-27 19:54:05 +05:30
### Docker
With Docker, you can just run a container like this:
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
docker run -d --name plantuml -p 8080:8080 plantuml/plantuml-server:tomcat
```
2018-03-27 19:54:05 +05:30
2021-03-11 19:13:27 +05:30
The **PlantUML URL** is the hostname of the server running the container.
2018-03-27 19:54:05 +05:30
2021-03-11 19:13:27 +05:30
When running GitLab in Docker, it must have access to the PlantUML container.
You can achieve that by using [Docker Compose ](https://docs.docker.com/compose/ ).
A basic `docker-compose.yml` file could contain:
2019-12-21 20:55:43 +05:30
```yaml
version: "3"
services:
gitlab:
2021-03-08 18:12:59 +05:30
image: 'gitlab/gitlab-ee:12.2.5-ee.0'
2019-12-21 20:55:43 +05:30
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
```
2021-03-11 19:13:27 +05:30
In this scenario, PlantUML is accessible to GitLab at the URL
2019-12-21 20:55:43 +05:30
`http://plantuml:8080/` .
2018-03-27 19:54:05 +05:30
### Debian/Ubuntu
2021-03-11 19:13:27 +05:30
You can also install and configure a PlantUML server in Debian/Ubuntu distributions using Tomcat.
2017-08-17 22:00:37 +05:30
First you need to create a `plantuml.war` file from the source code:
2020-03-13 15:44:24 +05:30
```shell
2019-09-04 21:01:54 +05:30
sudo apt-get install graphviz openjdk-8-jdk git-core maven
2017-08-17 22:00:37 +05:30
git clone https://github.com/plantuml/plantuml-server.git
cd plantuml-server
mvn package
```
2021-03-11 19:13:27 +05:30
The above sequence of commands generates a `.war` file you can deploy with Tomcat:
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
```shell
sudo apt-get install tomcat8
sudo cp target/plantuml.war /var/lib/tomcat8/webapps/plantuml.war
sudo chown tomcat8:tomcat8 /var/lib/tomcat8/webapps/plantuml.war
sudo service tomcat8 restart
2017-08-17 22:00:37 +05:30
```
2021-03-11 19:13:27 +05:30
After the Tomcat service restarts, the PlantUML service is ready and
2017-08-17 22:00:37 +05:30
listening for requests on port 8080:
2020-05-24 23:13:21 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
http://localhost:8080/plantuml
```
2021-03-11 19:13:27 +05:30
To change these defaults, edit the `/etc/tomcat8/server.xml` file.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
NOTE:
The default URL is different when using this approach. The Docker-based image
makes the service available at the root URL, with no relative path. Adjust
2019-12-21 20:55:43 +05:30
the configuration below accordingly.
2019-12-04 20:38:33 +05:30
### Making local PlantUML accessible using custom GitLab setup
The PlantUML server runs locally on your server, so it is not accessible
2021-03-08 18:12:59 +05:30
externally by default. As such, it is necessary to catch external PlantUML
calls and redirect them to the local server.
2019-12-04 20:38:33 +05:30
The idea is to redirect each call to `https://gitlab.example.com/-/plantuml/`
2019-12-21 20:55:43 +05:30
to the local PlantUML server `http://plantuml:8080/` or `http://localhost:8080/plantuml/` , depending on your setup.
2019-12-04 20:38:33 +05:30
To enable the redirection, add the following line in `/etc/gitlab/gitlab.rb` :
```ruby
2019-12-21 20:55:43 +05:30
# Docker deployment
nginx['custom_gitlab_server_config'] = "location /-/plantuml/ { \n proxy_cache off; \n proxy_pass http://plantuml:8080/; \n}\n"
# Built from source
2019-12-26 22:10:19 +05:30
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"
2019-12-21 20:55:43 +05:30
```
To activate the changes, run the following command:
2020-03-13 15:44:24 +05:30
```shell
2019-12-21 20:55:43 +05:30
sudo gitlab-ctl reconfigure
2019-12-04 20:38:33 +05:30
```
2021-03-11 19:13:27 +05:30
Note that the redirection through GitLab must be configured
2021-03-08 18:12:59 +05:30
when running [GitLab with TLS ](https://docs.gitlab.com/omnibus/settings/ssl.html )
due to PlantUML's use of the insecure HTTP protocol. Newer browsers such
as [Google Chrome 86+ ](https://www.chromestatus.com/feature/4926989725073408 )
do not load insecure HTTP resources on a page served over HTTPS.
2020-06-23 00:09:42 +05:30
### Security
2021-03-11 19:13:27 +05:30
PlantUML has features that allow fetching network resources.
2020-06-23 00:09:42 +05:30
```plaintext
@startuml
start
' ...
!include http://localhost/
stop;
@enduml
```
**If you self-host the PlantUML server, network controls should be put in place to isolate it.**
2017-08-17 22:00:37 +05:30
## GitLab
You need to enable PlantUML integration from Settings under Admin Area. To do
2021-03-11 19:13:27 +05:30
that, sign in with an Administrator account, and then do following:
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
1. In GitLab, go to **Admin Area > Settings > General** .
1. Expand the **PlantUML** section.
1. Select the **Enable PlantUML** check box.
1. Set the PlantUML instance as `https://gitlab.example.com/-/plantuml/` .
2017-08-17 22:00:37 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2020-07-28 23:09:34 +05:30
If you are using a PlantUML server running v1.2020.9 and
2020-05-24 23:13:21 +05:30
above (for example, [plantuml.com ](https://plantuml.com )), set the `PLANTUML_ENCODING`
2021-03-11 19:13:27 +05:30
environment variable to enable the `deflate` compression. On Omnibus GitLab,
this can be set in `/etc/gitlab.rb` :
2020-05-24 23:13:21 +05:30
```ruby
gitlab_rails['env'] = { 'PLANTUML_ENCODING' => 'deflate' }
```
From GitLab 13.1 and later, PlantUML integration now
[requires a header prefix in the URL ](https://github.com/plantuml/plantuml/issues/117#issuecomment-6235450160 )
to distinguish different encoding types.
2017-08-17 22:00:37 +05:30
## Creating Diagrams
With PlantUML integration enabled and configured, we can start adding diagrams to
2020-05-24 23:13:21 +05:30
our AsciiDoc snippets, wikis, and repositories using delimited blocks:
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
- **Markdown**
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
````markdown
2019-09-30 21:07:59 +05:30
```plantuml
Bob -> Alice : hello
2019-12-21 20:55:43 +05:30
Alice -> Bob : hi
2019-09-30 21:07:59 +05:30
```
2020-04-08 14:13:33 +05:30
````
2018-03-17 18:26:18 +05:30
- **AsciiDoc**
2020-05-24 23:13:21 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
[plantuml, format="png", id="myDiagram", width="200px"]
----
Bob->Alice : hello
2019-12-21 20:55:43 +05:30
Alice -> Bob : hi
2019-09-30 21:07:59 +05:30
----
```
2018-03-17 18:26:18 +05:30
- **reStructuredText**
2020-05-24 23:13:21 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
.. plantuml::
:caption: Caption with **bold** and *italic*
2018-03-17 18:26:18 +05:30
2019-09-30 21:07:59 +05:30
Bob -> Alice: hello
2019-12-21 20:55:43 +05:30
Alice -> Bob: hi
2019-09-30 21:07:59 +05:30
```
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
You can also use the `uml::` directive for compatibility with
[`sphinxcontrib-plantuml` ](https://pypi.org/project/sphinxcontrib-plantuml/ ),
but GitLab only supports the `caption` option.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
The above blocks are converted to an HTML image tag with source pointing to the
2017-08-17 22:00:37 +05:30
PlantUML instance. If the PlantUML server is correctly configured, this should
render a nice diagram instead of the block:
2019-12-21 20:55:43 +05:30
```plantuml
Bob -> Alice : hello
Alice -> Bob : hi
```
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
Inside the block you can add any of the diagrams PlantUML supports, such as:
- [Sequence ](https://plantuml.com/sequence-diagram )
- [Use Case ](https://plantuml.com/use-case-diagram )
- [Class ](https://plantuml.com/class-diagram )
- [Activity ](https://plantuml.com/activity-diagram-legacy )
- [Component ](https://plantuml.com/component-diagram )
- [State ](https://plantuml.com/state-diagram ),
- [Object ](https://plantuml.com/object-diagram )
You do not need to use the PlantUML
diagram delimiters `@startuml` /`@enduml`, as these are replaced by the AsciiDoc `plantuml` block.
2017-08-17 22:00:37 +05:30
Some parameters can be added to the AsciiDoc block definition:
2020-05-24 23:13:21 +05:30
- `format` : Can be either `png` or `svg` . Note that `svg` is not supported by
2019-09-30 21:07:59 +05:30
all browsers so use with care. The default is `png` .
2020-05-24 23:13:21 +05:30
- `id` : A CSS ID added to the diagram HTML tag.
- `width` : Width attribute added to the image tag.
- `height` : Height attribute added to the image tag.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
Markdown does not support any parameters and always uses PNG format.