drawio docker 部署

drawio docker 部署

  • Dockerfile 文件
FROM openjdk:8-alpine AS build

RUN apk update --no-cache && \
    apk add --no-cache \
        apache-ant \
        git

RUN cd /tmp && \
    git clone --depth 1 https://github.com/jgraph/drawio.git && \
    cd /tmp/drawio/etc/build/ && \
    ant war

FROM tomcat:9-jre8-alpine

LABEL maintainer="JGraph Ltd"

RUN apk update --no-cache && \
    apk add --no-cache \
        certbot \
        curl \
        xmlstarlet

COPY --from=build /tmp/drawio/build/draw.war /tmp

# Extract draw.io war & Update server.xml to set Draw.io webapp to root
RUN mkdir -p $CATALINA_HOME/webapps/draw && \
    unzip /tmp/draw.war -d $CATALINA_HOME/webapps/draw && \
    rm -rf /tmp/draw.war /tmp/drawio && \
    cd $CATALINA_HOME && \
    xmlstarlet ed \
        -P -S -L \
        -i '/Server/Service/Engine/Host/Valve' -t 'elem' -n 'Context' \
        -i '/Server/Service/Engine/Host/Context' -t 'attr' -n 'path' -v '/' \
        -i '/Server/Service/Engine/Host/Context[@path="/"]' -t 'attr' -n 'docBase' -v 'draw' \
        -s '/Server/Service/Engine/Host/Context[@path="/"]' -t 'elem' -n 'WatchedResource' -v 'WEB-INF/web.xml' \
        conf/server.xml

# Copy docker-entrypoint
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

WORKDIR $CATALINA_HOME

EXPOSE 8080 8443

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["catalina.sh", "run"]
  • docker-entrypoint.sh 文件
FROM openjdk:8-alpine AS build

RUN apk update --no-cache && \
    apk add --no-cache \
        apache-ant \
        git

RUN cd /tmp && \
    git clone --depth 1 https://github.com/jgraph/drawio.git && \
    cd /tmp/drawio/etc/build/ && \
    ant war

FROM tomcat:9-jre8-alpine

LABEL maintainer="JGraph Ltd"

RUN apk update --no-cache && \
    apk add --no-cache \
        certbot \
        curl \
        xmlstarlet

COPY --from=build /tmp/drawio/build/draw.war /tmp

# Extract draw.io war & Update server.xml to set Draw.io webapp to root
RUN mkdir -p $CATALINA_HOME/webapps/draw && \
    unzip /tmp/draw.war -d $CATALINA_HOME/webapps/draw && \
    rm -rf /tmp/draw.war /tmp/drawio && \
    cd $CATALINA_HOME && \
    xmlstarlet ed \
        -P -S -L \
        -i '/Server/Service/Engine/Host/Valve' -t 'elem' -n 'Context' \
        -i '/Server/Service/Engine/Host/Context' -t 'attr' -n 'path' -v '/' \
        -i '/Server/Service/Engine/Host/Context[@path="/"]' -t 'attr' -n 'docBase' -v 'draw' \
        -s '/Server/Service/Engine/Host/Context[@path="/"]' -t 'elem' -n 'WatchedResource' -v 'WEB-INF/web.xml' \
        conf/server.xml

# Copy docker-entrypoint
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

WORKDIR $CATALINA_HOME

EXPOSE 8080 8443

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["catalina.sh", "run"]
  • 构建命令
docker build -t jgraph/drawio .
  • docker-compose.yml 文件
#This compose file adds diagrams.net (ex draw.io) to your stack
version: '3.5'
services:
  drawio:
    image: jgraph/drawio
    container_name: drawio
    restart: unless-stopped
    ports:
      - 8080:8080
      - 8443:8443
    environment:
      PUBLIC_DNS: drawio.weihongbin.com
      ORGANISATION_UNIT: unit
      ORGANISATION: org
      CITY: city
      STATE: state
      COUNTRY_CODE: country
    healthcheck:
      test: ["CMD-SHELL", "curl -f https://drawio.weihongbin.com || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 5
      start_period: 10s
  • docker-compose 启动
docker-compose up -d
  • nginx 配置
upstream drawio.weihongbin {
    server 127.0.0.1:8080;
}

map $http_upgrade $connection_upgrade {
    default Upgrade;
    '' close;
}

server {
    listen 443 ssl http2;
    server_name drawio.weihongbin.com;
    ssl_certificate cert/drawio.weihongbin.com.pem;
    ssl_certificate_key cert/drawio.weihongbin.com.key;

    location / {
        sendfile off;
        proxy_pass http://drawio.weihongbin;
        proxy_redirect default;
        proxy_http_version 1.1;

        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_max_temp_file_size 0;

        client_max_body_size 1024m;
        client_body_buffer_size 128k;

        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        proxy_buffering off;
        proxy_request_buffering off; 
        proxy_set_header Connection ""; 
    }
}

server {
    listen 80;
    server_name drawio.weihongbin.com;
    return 301 https://$server_name$request_uri;
}
  • 相关链接

https://github.com/jgraph/drawio
https://github.com/jgraph/docker-drawio