Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Docker #3

Merged
merged 5 commits into from
Jul 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added support using Docker
  • Loading branch information
David Bonnici committed Jun 19, 2020
commit 47e72cf33e99b1e91c142d07b65d96ef83ecc331
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
./node_modules
./project
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does it come from?

.DS_Store
.dockerignore
Dockerfile
.git
./files/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a folder called files in my repo, so there's no point to dockerignore it.

.gitignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing final EOL.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -12,3 +12,7 @@ VERSION.json
.DS_Store
npm-debug.log
yarn-error.log

./project
project
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does it come from?

package-lock.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package-lock.json shall NOT be put into .gitignore. This repo is using yarn, but the choice was made back in 2018. I moved to npm on master and plz rebase.

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:lts-alpine3.11
RUN apk add chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV CHROMIUM_PATH /usr/bin/chromium-browser
RUN mkdir -p /home/node/draw.io-export /files
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part looks OK to me.

WORKDIR /home/node/draw.io-export
COPY . .
RUN npm install
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use npm ci --only=production instead of npm install.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, consider COPY package*.json ./ first before COPY . ., as stated in this guide.

VOLUME ["/files"]
ENTRYPOINT [ "sh", "convert.sh" ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing final EOL.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -4,10 +4,18 @@ Convert [draw.io](https://app.diagrams.net/) xml file (usually `*.drawio`) to `p

Works nicely with `make` and/or `latexmk`. Useful if you are writing a paper or thesis with many figures.

## Usage
## Usage with NPM

```bash
npm install --global draw.io-export
drawio <source.drawio> -o <dest.pdf>
drawio <source.drawio> -o <dest.png>
```

## Usage with Docker

```
docker run --name drawioexport \
-v [Your folder with draw.io files]:/files \
davidbonnici1984/draw.io-export:0.1.0
```
13 changes: 13 additions & 0 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo "DRAW.IO-EXPORT Started."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing #!/bin/bash

dirs=$(find /files -name '*.drawio')

for dir in $dirs
do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scripts will fail if any of the files contains "abnormal" characters, like spaces.
Please consider write a separate script file convert-one.sh and do :

find /files -name '*.drawio' -exec ./convert-one.sh {} \;

Alternatively, you can try combining the two scripts together and, at the beginning of the script, check [ "$#" -eq 1 ] to know if the script is called by find or by docker.

echo "Converting ${dir} to ${dir}.pdf"
rm $dir.pdf
node /home/node/draw.io-export/bin/drawio.js $dir -o $dir.pdf
echo "Converting ${dir} to ${dir}.png"
rm $dir.png
node /home/node/draw.io-export/bin/drawio.js $dir -o $dir.png
done
echo "DRAW.IO-EXPORT Finished."
4 changes: 3 additions & 1 deletion export.js
Original file line number Diff line number Diff line change
@@ -59,8 +59,10 @@ module.exports = async ({ file, format, path: p }) => {
const xml = await readFile(file);

const browser = await puppeteer.launch({
executablePath: process.env.CHROMIUM_PATH,
headless: true,
});
args: ['--no-sandbox']
b1f6c1c4 marked this conversation as resolved.
Show resolved Hide resolved
});

try {
const page = await browser.newPage();
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const path = require('path');
const run = require('./export');

process.on('unhandledRejection', (e) => {
console.error(e);
throw e;
});