Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
[tool] Remove node renderer
Browse files Browse the repository at this point in the history
Resolves #163
  • Loading branch information
Avi Flax committed Sep 16, 2019
1 parent c987903 commit 286359a
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 1,544 deletions.
29 changes: 10 additions & 19 deletions .circleci/config.yml
Expand Up @@ -11,7 +11,7 @@ tool_job_defaults: &tool_job_defaults
working_directory: ~/project/tool
docker:
# See https://circleci.com/docs/2.0/circleci-images/
- image: circleci/clojure:openjdk-11-tools-deps-node-browsers
- image: circleci/clojure:openjdk-11-tools-deps-browsers

jobs:
tool_test:
Expand All @@ -20,12 +20,12 @@ jobs:
- checkout: {path: ~/project}
- restore_cache:
keys:
- test-deps-v1-{{checksum "deps.edn"}}-{{checksum "renderer/package.json"}}-{{checksum "bin/download-test-deps"}}
- test-deps-v1-{{checksum "deps.edn"}}-{{checksum "bin/download-test-deps"}}
- run: bin/download-test-deps
- run: bin/tests-with-coverage
- save_cache:
key: test-deps-v1-{{checksum "deps.edn"}}-{{checksum "renderer/package.json"}}-{{checksum "bin/download-test-deps"}}
paths: [.cpcache, ~/.m2, ~/.gitlibs, renderer/node_modules]
key: test-deps-v1-{{checksum "deps.edn"}}-{{checksum "bin/download-test-deps"}}
paths: [.cpcache, ~/.m2, ~/.gitlibs]
- store_test_results: {path: target/test-results}
- store_artifacts: {path: target/coverage}
- run:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- checkout: {path: ~/project}
- restore_cache:
keys:
- pkg-deps-v1-{{checksum "deps.edn"}}-{{ checksum "renderer/package.json" }}-{{checksum "bin/download-pkg-deps"}}
- pkg-deps-v1-{{checksum "deps.edn"}}-{{checksum "bin/download-pkg-deps"}}
- run: bin/download-pkg-deps
- run:
name: Create distribution packages
Expand All @@ -75,37 +75,28 @@ jobs:
- persist_to_workspace: {root: ~/workspace, paths: [packages]}
- store_artifacts: {path: ~/workspace/packages}
- save_cache:
key: pkg-deps-v1-{{checksum "deps.edn"}}-{{ checksum "renderer/package.json" }}-{{checksum "bin/download-pkg-deps"}}
# ~/.npm is needed here because that is (or includes) npm’s cache, and that’s where pkg
# downloads the built node runtimes for various platforms.
paths: [.cpcache, ~/.m2, ~/.gitlibs, ~/.npm, ~/node_modules]
key: pkg-deps-v1-{{checksum "deps.edn"}}-{{checksum "bin/download-pkg-deps"}}
paths: [.cpcache, ~/.m2, ~/.gitlibs]

tool_test_dist_pkg:
docker:
# The test renders failed (Chrome crashed) when we used the tag `11-browsers` tag but succeed
# when we use `11-stretch-browsers` — not sure why. Debian and Chrome are both a little newer
# (as of this writing) in the `-stretch-` tag so that probably accounts for it.
- image: circleci/openjdk:11-stretch-browsers
working_directory: ~/test/test-renders
working_directory: ~/test/test-renders # overrides the value in tool_job_defaults.
steps:
- checkout: {path: ~/project} # only so we can access the test diagram YAML file
- attach_workspace: {at: ~/workspace} # so we can access the distribution package that was built in tool_build_dist_pkg
- run:
name: Extract tool from distribution package
command: tar -xzv -f ~/workspace/packages/fc4-tool-linux-*.tar.gz -C /tmp
command: tar -xzv -f ~/workspace/packages/fc4-tool-*.tar.gz -C /tmp
- run:
name: Move test diagram YAML into place
command: mv ~/project/tool/test/data/structurizr/express/diagram_valid_messy.yaml test-render-1.yaml
- run:
name: Render the diagram with the default renderer # See https://github.com/FundingCircle/fc4-framework/projects/2
name: Render the diagram
command: /tmp/fc4/fc4 --render test-render-1.yaml && mv test-render-1.png test-render-default.png
- run:
name: Render the diagram with the stable renderer # See https://github.com/FundingCircle/fc4-framework/projects/2
command: /tmp/fc4/fc4 --render --tmp-renderer=stable test-render-1.yaml && mv test-render-1.png test-render-stable.png
- run:
name: Render the diagram with the experimental renderer # See https://github.com/FundingCircle/fc4-framework/projects/2
command: /tmp/fc4/fc4 --render --tmp-renderer=experimental test-render-1.yaml && mv test-render-1.png test-render-experimental.png
- store_artifacts: {path: ~/test/test-renders}

tool_publish_dist_pkg:
docker:
Expand Down
7 changes: 0 additions & 7 deletions docs/tool/fc4-tool-02-container.yaml
Expand Up @@ -22,11 +22,6 @@ elements:
technology: Clojure/Java/JVM
position: '100,500'
type: Container
- name: Renderer
description: Invokes and controls Chromium to render diagrams using Structurizr Express
technology: JavaScript/Node
position: '700,500'
type: Container
- name: Chromium
description: or Chrome; Web browser; runs in headless mode
position: '1300,500'
Expand All @@ -36,8 +31,6 @@ relationships:
- source: Chromium
destination: Structurizr Express
- source: Main Executable
destination: Renderer
- source: Renderer
destination: Chromium
- source: Software Creator
destination: Main Executable
Expand Down
1 change: 0 additions & 1 deletion tool/.dockerignore
@@ -1,3 +1,2 @@
.cpcache
target
**/node_modules
12 changes: 4 additions & 8 deletions tool/Dockerfile.pkg
@@ -1,7 +1,7 @@
# This Dockerfile is intended for building distribution packages/artifacts.

# This base image is documented here: https://circleci.com/docs/2.0/circleci-images/
FROM circleci/clojure:openjdk-11-tools-deps-node-browsers
FROM circleci/clojure:openjdk-11-tools-deps-browsers

# We need to create the working dir explicitly via mkdir, rather than just let WORKDIR create it
# (or it might actually be created lazily by e.g. COPY) because if we let WORKDIR (or maybe COPY)
Expand All @@ -13,14 +13,10 @@ USER circleci

WORKDIR /home/circleci/tool

# Copy Clojure’s deps.edn and Node’s package files then download the deps
# separately from and prior to copying the app code so that we don’t have to
# Download the deps separately from and prior to copying the app code so that we don’t have to
# re-download deps every time the app code changes.
COPY --chown=circleci:circleci deps.edn ./
COPY --chown=circleci:circleci renderer/package*.json ./renderer/
COPY --chown=circleci:circleci bin/download-pkg-deps bin/

# Download the deps!
COPY deps.edn ./
COPY bin/download-pkg-deps bin/
RUN bin/download-pkg-deps

# Now copy *all* the code.
Expand Down
13 changes: 5 additions & 8 deletions tool/Dockerfile.test
Expand Up @@ -2,12 +2,12 @@
#
# It isn’t useful for _using_ the tool because:
#
# * the tool itself has far fewer system-level requirements at runtime
# * most meaningfully it does not require Clojure or Node to be installed
# * the tool itself has fewer system-level requirements at runtime than the tests
# * most meaningfully it does not require a JRE or Clojure to be installed
# * but it does requires access to your files.

# This base image is documented here: https://circleci.com/docs/2.0/circleci-images/
FROM circleci/clojure:openjdk-11-tools-deps-node-browsers
FROM circleci/clojure:openjdk-11-tools-deps-browsers

# We need to create the working dir explicitly via mkdir, rather than just let WORKDIR create it
# (or it might actually be created lazily by e.g. COPY) because if we let WORKDIR (or maybe COPY)
Expand All @@ -19,13 +19,10 @@ USER circleci

WORKDIR /home/circleci/tool

# Copy Clojure’s deps.edn and Node’s package files then download the deps
# separately from and prior to copying the app code so that we don’t have to
# Download the deps separately from and prior to copying the app code so that we don’t have to
# re-download deps every time the app code changes.
COPY --chown=circleci:circleci deps.edn ./
COPY --chown=circleci:circleci renderer/package*.json ./renderer/
COPY --chown=circleci:circleci bin/download-test-deps ./bin/

COPY --chown=circleci:circleci bin/download-test-deps bin/
RUN bin/download-test-deps

# Now copy *all* the code.
Expand Down
4 changes: 2 additions & 2 deletions tool/README.md
Expand Up @@ -46,8 +46,8 @@ bin/docker-test-run bin/tests

If you’re old-school and prefer to run tests on bare metal:

1. Ensure that Clojure, Node, and Chromium/Chrome are installed
1. On Macos with Homebrew: `brew cask install adoptopenjdk chromium && brew install clojure npm`
1. Ensure that a JRE, Clojure, and Chromium/Chrome are installed
1. On Macos with Homebrew: `brew cask install adoptopenjdk chromium && brew install clojure`
1. Run:
1. `bin/download-test-deps`
1. `bin/tests`
Expand Down
7 changes: 0 additions & 7 deletions tool/bin/download-pkg-deps
Expand Up @@ -9,10 +9,3 @@ set -ex

# clojure automatically downloads deps if necessary
clojure -R:uberjar -Stree

# npm install automatically downloads deps if necessary
(cd renderer && npm install)

# Install pkg in our home dir rather than globally so we can safely cache it in
# our CI environment.
[ -f ~/node_modules/.bin/pkg ] || (cd && npm install pkg@4.3.7)
12 changes: 4 additions & 8 deletions tool/bin/download-test-deps
@@ -1,16 +1,12 @@
#!/bin/sh

## This script is intended to download all dependencies and tools needed for
## testing this tool.
## This script is intended to download all dependencies and tools needed for testing this tool.

## Run this from <project-root>/tool/

set -ex

# Both `clojure` and `npm install` automatically download deps if necessary. If
# this is running in CI, however, then hopefully the dependencies needed have
# already been restored from a cache, and these commands will do very little,
# quickly.

# The `clojure` script automatically download deps if necessary. If this is running in CI, however,
# then hopefully the dependencies needed have already been restored from a cache, and this command
# will do very little, quickly.
clojure -R:test:test/coverage -Stree
(cd renderer && npm install)
23 changes: 9 additions & 14 deletions tool/bin/pkg-all
Expand Up @@ -7,21 +7,16 @@ set -e
# TODO: how risky is this, that we’ll end up packaging stale files? I think not *too* risky since
# we *should* be running this script in a fresh CI container!
if [ ! -f target/pkg/fc4.jar ]; then bin/pkg-uberjar; fi
if [ ! -f target/pkg/renderer/render-macos ]; then bin/pkg-renderer; fi

for os in macos linux; do
echo "Compiling distribution package for $os:"
echo "Compiling distribution package:"

os_dir="target/pkg/$os"
pkg_dir="$os_dir/fc4"
pkg_dir="target/pkg/fc4"

echo " Collecting files in $pkg_dir..."
mkdir -p $pkg_dir
cp target/pkg/fc4.jar dist/fc4 $pkg_dir/
cp ../docs/tool/index.md $pkg_dir/README.md
cp "target/pkg/renderer/render-$os" $pkg_dir/fc4-render
echo " Collecting files in $pkg_dir..."
mkdir -p $pkg_dir
cp target/pkg/fc4.jar dist/fc4 $pkg_dir/
cp ../docs/tool/index.md $pkg_dir/README.md

archive="fc4-tool-$os-amd64-$FC4_VERSION.tar.gz"
echo " Building archive target/pkg/$archive..."
(cd $os_dir && tar -czf "../$archive" fc4/*)
done
archive="fc4-tool-$FC4_VERSION.tar.gz"
echo " Building archive target/pkg/$archive..."
(cd target/pkg && tar -czf "../$archive" fc4/*)
11 changes: 0 additions & 11 deletions tool/bin/pkg-renderer

This file was deleted.

13 changes: 7 additions & 6 deletions tool/dist/fc4
Expand Up @@ -9,12 +9,13 @@ SCRIPT_DIR="${BASH_SOURCE%/*}"

JVM_OPTS=()

# It’s crucial to ensure that the JVM’s default character encoding is UTF-8
# because the Node renderer outputs UTF-8 encoded text to its stderr, which the main
# program (the JVM program) then needs to read correctly. We’ve found that some
# Linux systems seem to default to US-ASCII which will generally break the
# ability of the main program to properly parse the error output of the
# renderer.
# This was originally introduced for obscure technical reasons related to the old, since-removed,
# Node renderer, which was executed as a separate process (at the OS level) and the IPC was impacted
# by the OS’s default character encoding setting, which we had to override. *That* reason for this
# setting no longer applies, but I’m keeping it around for now because I kinda like the idea of the
# tool using UTF8 no matter what, because some OS’s do use ASCII as their default character encoding
# setting, and I want YAML files containing “extended Unicode characters” (e.g. emoji) to be read
# correctly. This may be naive and problematic and may need to be revisited at some point.
JVM_OPTS+=("-Dfile.encoding=UTF8")

# Prevent the Java app icon from popping up and grabbing focus on MacOS.
Expand Down
1 change: 0 additions & 1 deletion tool/renderer/.gitignore

This file was deleted.

0 comments on commit 286359a

Please sign in to comment.