2016-11-28 12:41:29 -05:00
# PlantUML & GitLab
2019-09-18 10:02:45 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/8537) in GitLab 8.16.
2016-11-28 12:41:29 -05:00
When [PlantUML ](http://plantuml.com ) integration is enabled and configured in
2017-01-15 19:07:02 -05:00
GitLab we are able to create simple diagrams in AsciiDoc and Markdown documents
created in snippets, wikis, and repos.
2016-11-28 12:41:29 -05:00
## PlantUML Server
Before you can enable PlantUML in GitLab; you need to set up your own PlantUML
2018-02-02 05:47:33 -05:00
server that will generate the diagrams.
### Docker
With Docker, you can just run a container like this:
2019-07-12 04:00:24 -04:00
```sh
docker run -d --name plantuml -p 8080:8080 plantuml/plantuml-server:tomcat
```
2018-02-02 05:47:33 -05:00
The **PlantUML URL** will be the hostname of the server running the container.
2019-10-15 02:07:25 -04:00
When running GitLab in Docker, it will need to have access to the PlantUML container.
The easiest way to achieve that is by using [Docker Compose ](https://docs.docker.com/compose/ ).
A simple `docker-compose.yml` file would be:
```yaml
version: "3"
services:
gitlab:
image: 'gitlab/gitlab-ce:12.2.5-ce.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
```
In this scenario, PlantUML will be accessible for GitLab at the URL
`http://plantuml:8080/` .
2018-02-02 05:47:33 -05:00
### Debian/Ubuntu
Installing and configuring your
2016-11-28 12:41:29 -05:00
own PlantUML server is easy in Debian/Ubuntu distributions using Tomcat.
First you need to create a `plantuml.war` file from the source code:
2019-07-12 04:00:24 -04:00
```sh
2019-05-29 10:01:43 -04:00
sudo apt-get install graphviz openjdk-8-jdk git-core maven
2016-11-28 12:41:29 -05:00
git clone https://github.com/plantuml/plantuml-server.git
cd plantuml-server
mvn package
```
The above sequence of commands will generate a WAR file that can be deployed
using Tomcat:
2019-11-21 19:06:08 -05:00
```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
2016-11-28 12:41:29 -05:00
```
Once the Tomcat service restarts the PlantUML service will be ready and
listening for requests on port 8080:
2019-07-12 04:00:24 -04:00
```text
2016-11-28 12:41:29 -05:00
http://localhost:8080/plantuml
```
2019-11-21 19:06:08 -05:00
you can change these defaults by editing the `/etc/tomcat8/server.xml` file.
2016-11-28 12:41:29 -05:00
2019-10-15 02:07:25 -04:00
Note that the default URL is different than when using the Docker-based image,
where the service is available at the root of URL with no relative path. Adjust
the configuration below accordingly.
2019-09-08 19:28:07 -04:00
### Making local PlantUML accessible using custom GitLab setup
The PlantUML server runs locally on your server, so it is not accessible
2019-09-08 20:11:05 -04:00
externally. As such, it is necessary to catch external PlantUML calls and
redirect them to the local server.
2019-09-08 19:28:07 -04:00
The idea is to redirect each call to `https://gitlab.example.com/-/plantuml/`
2019-10-15 02:07:25 -04:00
to the local PlantUML server `http://plantuml:8080/` or `http://localhost:8080/plantuml/` , depending on your setup.
2019-09-08 19:28:07 -04:00
To enable the redirection, add the following line in `/etc/gitlab/gitlab.rb` :
```ruby
2019-10-15 02:07:25 -04:00
# 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-11-01 08:06:26 -04:00
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-09-26 02:06:27 -04:00
```
To activate the changes, run the following command:
```sh
sudo gitlab-ctl reconfigure
2019-09-08 19:28:07 -04:00
```
2016-11-28 12:41:29 -05:00
## GitLab
You need to enable PlantUML integration from Settings under Admin Area. To do
that, login with an Admin account and do following:
2019-07-12 04:00:24 -04:00
- In GitLab, go to **Admin Area > Settings > Integrations** .
- Expand the **PlantUML** section.
- Check **Enable PlantUML** checkbox.
2019-09-08 19:28:07 -04:00
- Set the PlantUML instance as `https://gitlab.example.com/-/plantuml/` .
2016-11-28 12:41:29 -05:00
## Creating Diagrams
With PlantUML integration enabled and configured, we can start adding diagrams to
2017-01-15 19:07:02 -05:00
our AsciiDoc snippets, wikis and repos using delimited blocks:
2016-11-28 12:41:29 -05:00
2017-11-01 06:56:06 -04:00
- **Markdown**
2019-08-16 08:06:00 -04:00
~~~markdown
2019-07-10 14:23:55 -04:00
```plantuml
Bob -> Alice : hello
2019-10-14 20:06:37 -04:00
Alice -> Bob : hi
2019-07-09 10:03:32 -04:00
```
2019-08-16 08:06:00 -04:00
~~~
2016-11-28 12:41:29 -05:00
2017-11-01 06:56:06 -04:00
- **AsciiDoc**
2017-01-15 19:07:02 -05:00
2019-07-12 04:00:24 -04:00
```text
[plantuml, format="png", id="myDiagram", width="200px"]
----
Bob->Alice : hello
2019-10-14 20:06:37 -04:00
Alice -> Bob : hi
2019-07-12 04:00:24 -04:00
----
```
2017-01-15 19:07:02 -05:00
2017-11-01 06:56:06 -04:00
- **reStructuredText**
2017-08-29 10:04:32 -04:00
2019-07-12 04:00:24 -04:00
```text
.. plantuml::
:caption: Caption with **bold** and *italic*
2017-08-29 10:04:32 -04:00
2019-07-12 04:00:24 -04:00
Bob -> Alice: hello
2019-10-14 20:06:37 -04:00
Alice -> Bob: hi
2019-07-12 04:00:24 -04:00
```
2017-11-01 06:56:06 -04:00
2019-07-10 14:23:55 -04:00
You can also use the `uml::` directive for compatibility with [sphinxcontrib-plantuml ](https://pypi.org/project/sphinxcontrib-plantuml/ ), but please note that we currently only support the `caption` option.
2017-08-29 10:04:32 -04:00
2017-01-15 19:07:02 -05:00
The above blocks will be converted to an HTML img tag with source pointing to the
2016-11-28 12:41:29 -05:00
PlantUML instance. If the PlantUML server is correctly configured, this should
render a nice diagram instead of the block:
2019-10-14 20:06:37 -04:00
```plantuml
Bob -> Alice : hello
Alice -> Bob : hi
```
2016-11-28 12:41:29 -05:00
Inside the block you can add any of the supported diagrams by PlantUML such as
[Sequence ](http://plantuml.com/sequence-diagram ), [Use Case ](http://plantuml.com/use-case-diagram ),
[Class ](http://plantuml.com/class-diagram ), [Activity ](http://plantuml.com/activity-diagram-legacy ),
[Component ](http://plantuml.com/component-diagram ), [State ](http://plantuml.com/state-diagram ),
and [Object ](http://plantuml.com/object-diagram ) diagrams. You do not need to use the PlantUML
diagram delimiters `@startuml` /`@enduml` as these are replaced by the AsciiDoc `plantuml` block.
2017-01-15 19:07:02 -05:00
Some parameters can be added to the AsciiDoc block definition:
2016-11-28 12:41:29 -05:00
2019-07-10 14:23:55 -04:00
- *format*: Can be either `png` or `svg` . Note that `svg` is not supported by
all browsers so use with care. The default is `png` .
- *id*: A CSS id added to the diagram HTML tag.
- *width*: Width attribute added to the img tag.
- *height*: Height attribute added to the img tag.
2016-11-28 12:41:29 -05:00
2017-01-15 19:07:02 -05:00
Markdown does not support any parameters and will always use PNG format.