Add rendered example

This commit is contained in:
Daniel Berteaud 2024-01-05 13:53:10 +01:00
parent 39690e1f3a
commit 89655f19d1
12 changed files with 278 additions and 0 deletions

9
example/LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2023 nomad
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

4
example/README.md Normal file
View File

@ -0,0 +1,4 @@
# diagrams
A configurable diagramming/whiteboarding visualization application. draw.io is jointly owned and developed by JGraph Ltd and draw.io AG.

View File

@ -0,0 +1,3 @@
Kind = "service-defaults"
Name = "diagrams"
Protocol = "http"

View File

@ -0,0 +1,15 @@
Kind = "service-intentions"
Name = "diagrams"
Sources = [
{
Name = "traefik"
Permissions = [
{
Action = "allow"
HTTP {
PathPrefix = "/"
}
}
]
}
]

124
example/diagrams.nomad.hcl Normal file
View File

@ -0,0 +1,124 @@
job "diagrams" {
datacenters = ["dc1"]
group "diagrams" {
network {
mode = "bridge"
}
service {
name = "diagrams"
port = 8282
connect {
sidecar_service {
}
sidecar_task {
resources {
cpu = 50
memory = 64
}
}
}
check {
type = "http"
path = "/health"
expose = true
interval = "1m"
timeout = "8s"
check_restart {
limit = 4
grace = "1m"
}
}
tags = [
"traefik.enable=true",
# Define a middleware to set custom CSP headers
"traefik.http.middlewares.diagrams-headers.headers.contentsecuritypolicy=connect-src 'self' https://*.dropboxapi.com https://api.trello.com https://api.github.com https://raw.githubusercontent.com https://*.googleapis.com https://*.googleusercontent.com https://graph.microsoft.com https://*.1drv.com https://*.sharepoint.com https://gitlab.com https://*.google.com https://fonts.gstatic.com https://fonts.googleapis.com;default-src 'self';font-src * about:;frame-src 'self' https://*.google.com;img-src * data:;media-src * data:;script-src 'self' https://storage.googleapis.com https://apis.google.com https://docs.google.com https://code.jquery.com 'unsafe-inline';style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;",
# Main app router
"traefik.http.routers.diagrams.rule=Host(`draw.example.org`)",
"traefik.http.routers.diagrams.entrypoints=https",
"traefik.http.routers.diagrams.middlewares=diagrams-headers,rate-limit-std@file,inflight-std@file,security-headers@file,hsts@file,compression@file,csp-relaxed@file",
]
}
task "diagrams" {
driver = "docker"
config {
image = "danielberteaud/diagrams:22.1.16-1"
pids_limit = 200
readonly_rootfs = true
volumes = [
"local/PreConfig.js:/opt/tomcat/webapps/draw/js/PreConfig.js",
"local/PostConfig.js:/opt/tomcat/webapps/draw/js/PostConfig.js"
]
}
env {
JAVA_OPTS = "-Djava.io.tmpdir=/local"
TOMCAT_ADDRESS = "127.0.0.1"
}
template {
data = <<_EOT
window.DRAWIO_BASE_URL = 'https://draw.example.org';
window.DRAWIO_SERVER_URL = 'https://draw.example.org/';
window.DRAWIO_VIEWER_URL = 'https://draw.example.org/js/viewer.min.js';
window.DRAWIO_LIGHTBOX_URL = '';
window.DRAW_MATH_URL = 'math/es5';
window.DRAWIO_CONFIG = null;
urlParams['sync'] = 'manual'; //Disable Real-Time
urlParams['db'] = '0'; //dropbox
urlParams['gh'] = '0'; //github
urlParams['tr'] = '0'; //trello
urlParams['gapi'] = '0'; //Google Drive
urlParams['od'] = '0'; //OneDrive
urlParams['gl'] = '0'; //Gitlab
_EOT
destination = "local/PreConfig.js"
}
template {
data = <<_EOT
window.VSD_CONVERT_URL = null;
window.ICONSEARCH_PATH = null;
EditorUi.enableLogging = false; //Disable logging
window.EMF_CONVERT_URL = null;
App.prototype.isDriveDomain = function() { return true; }
_EOT
destination = "local/PostConfig.js"
}
# Use a template block instead of env {} so we can fetch values from vault
template {
data = <<_EOT
LANG=fr_FR.utf8
TZ=Europe/Paris
_EOT
destination = "secrets/.env"
perms = 400
env = true
}
resources {
cpu = 200
memory = 256
}
}
}
}

View File

@ -0,0 +1,36 @@
FROM danielberteaud/java:17.24.1-1
MAINTAINER Daniel Berteaud <dbd@ehtrace.com>
ARG TOMCAT_VERSION=9.0.84 \
DIAGRAMS_VERSION=22.1.16
ENV CATALINA_HOME=/opt/tomcat \
TOMCAT_PORT=8282 \
TOMCAT_ADDRESS=0.0.0.0
RUN set -euxo pipefail &&\
cd /tmp &&\
apk --no-cache update &&\
apk --no-cache add bash &&\
curl -sSLO https://dlcdn.apache.org/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz &&\
curl -sSLO https://dlcdn.apache.org/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz.sha512 &&\
sha512sum -c < apache-tomcat-${TOMCAT_VERSION}.tar.gz.sha512 &&\
mkdir -p /opt/tomcat &&\
tar xvzf apache-tomcat-${TOMCAT_VERSION}.tar.gz --strip-components 1 --directory ${CATALINA_HOME} &&\
find /opt/tomcat -type d -exec chmod 755 "{}" \; &&\
find /opt/tomcat -type f -exec chmod 644 "{}" \; &&\
chmod +x /opt/tomcat/bin/* &&\
rm -f apache-tomcat-${TOMCAT_VERSION}.tar.gz.sha512 apache-tomcat-${TOMCAT_VERSION}.tar.gz &&\
curl -sSLO https://github.com/jgraph/drawio/releases/download/v${DIAGRAMS_VERSION}/draw.war &&\
unzip draw.war -d ${CATALINA_HOME}/webapps/draw &&\
rm draw.war &&\
addgroup --gid 8282 diagrams &&\
adduser --system --ingroup diagrams --disabled-password --uid 8282 --home ${CATALINA_HOME} --shell /sbin/nologin diagrams
COPY root/ /
WORKDIR ${CATALINA_HOME}
EXPOSE ${TOMCAT_PORT}
USER diagrams
CMD ["/opt/tomcat/bin/catalina.sh", "run"]

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eu
export CATALINA_OPTS="${JAVA_OPTS} -Dtomcat.port=${TOMCAT_PORT} -Dtomcat.address=${TOMCAT_ADDRESS}"

View File

@ -0,0 +1,16 @@
handlers = java.util.logging.ConsoleHandler
.handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = UTF-8
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = java.util.logging.ConsoleHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = java.util.logging.ConsoleHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = java.util.logging.ConsoleHandler

View File

@ -0,0 +1,20 @@
<?xml version='1.0' encoding='utf-8'?>
<Server port="8082" address="127.0.0.1" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<Service name="Catalina">
<Connector port="${tomcat.port}" address="${tomcat.address}" protocol="HTTP/1.1"
connectionTimeout="20000" />
<Engine name="Catalina" defaultHost="diagrams">
<Host name="diagrams" appBase="webapps"
unpackWARs="false" autoDeploy="false">
<Context path="" docBase="draw"></Context>
<Valve className="org.apache.catalina.valves.HealthCheckValve" />
</Host>
</Engine>
</Service>
</Server>

View File

@ -0,0 +1,5 @@
window.VSD_CONVERT_URL = null;
window.ICONSEARCH_PATH = null;
EditorUi.enableLogging = false; //Disable logging
window.EMF_CONVERT_URL = null;
App.prototype.isDriveDomain = function() { return true; }

View File

@ -0,0 +1,22 @@
(function() {
try {
var s = document.createElement('meta');
s.setAttribute('content', 'default-src \'self\'; script-src \'self\' https://storage.googleapis.com https://apis.google.com https://docs.google.com https://code.jquery.com \'unsafe-inline\'; connect-src \'self\' https://*.dropboxapi.com https://api.trello.com https://api.github.com https://raw.githubusercontent.com https://*.googleapis.com https://*.googleusercontent.com https://graph.microsoft.com https://*.1drv.com https://*.sharepoint.com https://gitlab.com https://*.google.com https://fonts.gstatic.com https://fonts.googleapis.com; img-src * data:; media-src * data:; font-src * about:; style-src \'self\' \'unsafe-inline\' https://fonts.googleapis.com; frame-src \'self\' https://*.google.com;');
s.setAttribute('http-equiv', 'Content-Security-Policy');
var t = document.getElementsByTagName('meta')[0];
t.parentNode.insertBefore(s, t);
} catch (e) {} // ignore
})();
window.DRAWIO_BASE_URL = 'http://localhost:8080';
window.DRAWIO_SERVER_URL = window.DRAWIO_BASE_URL + '/';
window.DRAWIO_VIEWER_URL = '';
window.DRAWIO_LIGHTBOX_URL = '';
window.DRAW_MATH_URL = 'math/es5';
window.DRAWIO_CONFIG = null;
urlParams['sync'] = 'manual'; //Disable Real-Time
urlParams['db'] = '0'; //dropbox
urlParams['gh'] = '0'; //github
urlParams['tr'] = '0'; //trello
urlParams['gapi'] = '0'; //Google Drive
urlParams['od'] = '0'; //OneDrive
urlParams['gl'] = '0'; //Gitlab

19
example/prep.d/10-mv-conf.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -eu
if [ "diagrams" != "diagrams" ]; then
for DIR in vault consul nomad; do
if [ -d output/${DIR} ]; then
for FILE in $(find output/${DIR} -name "*diagrams*.hcl" -type f); do
NEW_FILE=$(echo "${FILE}" | sed -E "s/diagrams/diagrams/g")
mv "${FILE}" "${NEW_FILE}"
done
fi
done
fi