Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 34 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21.0.6_7-jre-noble
FROM eclipse-temurin:21.0.6_7-jre-noble AS structurizr-lite
ENV PORT=8080

RUN set -eux; \
Expand All @@ -12,3 +12,36 @@ EXPOSE ${PORT}
HEALTHCHECK CMD curl --fail http://localhost:${PORT}/health || exit 1

CMD ["java", "-Dserver.port=${PORT}", "-jar", "/usr/local/structurizr-lite.war"]

FROM structurizr-lite AS structurizr-export

ENV STRUCTURIZR_EXPORT=/opt/structurizr-export
ENV STRUCTURIZR_WORKSPACE_PATH=/workspace

RUN set -eux; \
apt-get install -y --no-install-recommends git nodejs npm; \
git clone https://github.com/structurizr/puppeteer.git $STRUCTURIZR_EXPORT; \
sed -i $STRUCTURIZR_EXPORT/export-diagrams.js -e 's@headless: HEADLESS@headless: HEADLESS, args: [ "--no-sandbox" ]@'; \
sed -i $STRUCTURIZR_EXPORT/export-documentation.js -e 's@headless: HEADLESS@headless: HEADLESS, args: [ "--no-sandbox" ]@'; \
cd $STRUCTURIZR_EXPORT; \
npm install puppeteer; \
npx puppeteer browsers install --install-deps chrome-headless-shell@stable; \
npm install -g svgo; \
mkdir $STRUCTURIZR_WORKSPACE_PATH; \
apt-get remove -y --purge git npm; \
apt-get autoremove -y; \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*

COPY svgo /usr/local/lib/svgo
COPY --chmod=0775 puppeteer-export-diagrams.sh /usr/local/bin/export-diagrams
COPY --chmod=0775 puppeteer-export-documentation.sh /usr/local/bin/export-documentation

WORKDIR /workspace

CMD ["/bin/bash"]

# Local Variables:
# dockerfile-indent-offset: 8
# tab-width: 8
# indent-tabs-mode: t
# End:
35 changes: 35 additions & 0 deletions puppeteer-export-diagrams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# export <output-directory> [[format] ...]

cleanup() {
kill %1
wait
}

export STRUCTURIZR_WORKSPACE_FILENAME=$1
shift
OUTPUT_DIR="${STRUCTURIZR_WORKSPACE_PATH}/${1}"
shift

java -Dserver.port=${PORT} -jar /usr/local/structurizr-lite.war / &
(until printf "" 2>>/dev/null >>/dev/tcp/localhost/$PORT; do sleep 1; done) > /dev/null 2>&1

trap cleanup EXIT
trap cleanup INT
trap cleanup TERM

mkdir -p "$OUTPUT_DIR"
cd "$OUTPUT_DIR"

for FORMAT in $@; do
echo exporting $STRUCTURIZR_WORKSPACE_FILENAME diagrams to $FORMAT in $OUTPUT_DIR
for FILE in $(node $STRUCTURIZR_EXPORT/export-diagrams.js http://localhost:$PORT $FORMAT | grep "^ - .*\\.$FORMAT" | sed "s/ - //"); do
OUTPUT_FILE="$OUTPUT_DIR/${STRUCTURIZR_WORKSPACE_FILENAME}_${FILE}"
if [ $FORMAT == svg ]; then
svgo --config=/usr/local/lib/svgo/svgo.config.js --quiet "$OUTPUT_DIR/$FILE" -o "$OUTPUT_FILE"
else
mv "$OUTPUT_DIR/$FILE" "$OUTPUT_FILE"
fi
echo exported "$OUTPUT_FILE"
done
done
25 changes: 25 additions & 0 deletions puppeteer-export-documentation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# export <output-directory> [[format] ...]

cleanup() {
kill %1
wait
}

export STRUCTURIZR_WORKSPACE_FILENAME=$1
shift
OUTPUT_DIR="${STRUCTURIZR_WORKSPACE_PATH}/${1}"
shift

java -Dserver.port=${PORT} -jar /usr/local/structurizr-lite.war / &
(until printf "" 2>>/dev/null >>/dev/tcp/localhost/$PORT; do sleep 1; done) > /dev/null 2>&1

trap cleanup EXIT
trap cleanup INT
trap cleanup TERM

mkdir -p "$OUTPUT_DIR"
cd "$OUTPUT_DIR"

echo exporting $STRUCTURIZR_WORKSPACE_FILENAME documentation in $OUTPUT_DIR
node $STRUCTURIZR_EXPORT/export-documentation.js http://localhost:$PORT $FORMAT
27 changes: 27 additions & 0 deletions svgo/removeNoDimensionImages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

exports.name = 'removeNodDimensionImages';
exports.type = 'visitor';
exports.active = true;
exports.description = 'removes images without width or height attributes (disabled by default)';

/**
* Remove raster images references in <image>.
*
* @see https://bugs.webkit.org/show_bug.cgi?id=63548
*
* @author Kir Belevich
*
* @type {import('../lib/types').Plugin<void>}
*/
exports.fn = () => {
return {
element: {
enter: (node, parentNode) => {
if (node.name === 'image' && !(node.attributes.width && node.attributes.height)) {
parentNode.children = parentNode.children.filter((child) => child !== node);
}
},
},
};
};
10 changes: 10 additions & 0 deletions svgo/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

const removeNoDimensionImages = require('/usr/local/lib/svgo/removeNoDimensionImages.js');
module.exports = {
multipass: true,

plugins: [
'preset-default',
removeNoDimensionImages,
],
};