Skip to content

Commit

Permalink
ImageMagick library in PATH and Docker (#104)
Browse files Browse the repository at this point in the history
* Refactor code to use logger for errors

* Set symbolic link to ImageMagick if exists in parent directory

* Set PATH to include ImageMagick

* Add imagemagick to docker image
  • Loading branch information
younglim authored Mar 14, 2023
1 parent 8109e20 commit 96cc35d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:lts-alpine

# Installation of packages for purple-hats and chromium
RUN apk add --no-cache g++ make python3 chromium zip bash git
RUN apk add --no-cache g++ make python3 chromium zip bash git imagemagick

WORKDIR /app

Expand Down
20 changes: 13 additions & 7 deletions playwrightAxeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const playwrightAxeGenerator = async (domain, randomToken, answers) => {
});

if (unsafe.length > 0 ) {
consoleLogger.error("Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename);
silentLogger.error("Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename);
process.exit(1);
let unsafeExpressionsError = "Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename;
consoleLogger.error(unsafeExpressionsError);
silentLogger.error(unsafeExpressionsError);
process.exit(1);
};
}

Expand All @@ -37,14 +38,18 @@ const playwrightAxeGenerator = async (domain, randomToken, answers) => {
import { isSkippedUrl } from './constants/common.js';
import { spawnSync } from 'child_process';
import safe from 'safe-regex';
import { consoleLogger, silentLogger } from './logs.js';
const blacklistedPatternsFilename = 'exclusions.txt';
process.env.CRAWLEE_STORAGE_DIR = constants.a11yStorage;
const compareExe = getExecutablePath('**/ImageMagick*/bin','compare');
if (!compareExe) {
throw new Error("Could not find ImageMagick compare. Please ensure ImageMagick is installed.");
let ImagMagickNotFoundError = "Could not find ImageMagick compare. Please ensure ImageMagick is installed at current directory.";
consoleLogger.error(ImagMagickNotFoundError);
silentLogger.error(ImagMagickNotFoundError);
process.exit(1);
}
removeQuarantineFlag('**/ImageMagick*/lib/*.dylib');
Expand Down Expand Up @@ -73,10 +78,11 @@ if (fs.existsSync(blacklistedPatternsFilename)) {
});
if (unsafe.length > 0 ) {
consoleLogger.error("Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename);
silentLogger.error("Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename);
let unsafeExpressionsError = "Unsafe expressions detected: '"+ unsafe +"' Please revise " + blacklistedPatternsFilename;
consoleLogger.error(unsafeExpressionsError);
silentLogger.error(unsafeExpressionsError);
process.exit(1);
}
};
}
var index = 1;
Expand Down
9 changes: 9 additions & 0 deletions scripts/hats_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ else
export PATH="$PATH_TO_NODE:$PATH"
fi

if $(ls ImageMagick-*/bin/compare 1> /dev/null 2>&1) && [ -d purple-hats ]; then
echo "INFO: Set symbolic link to ImageMagick"
ln -sf "$(ls -d $PWD/ImageMagick-*)" "purple-hats/$(ls -d ImageMagick-*)"

echo "INFO: Set path to ImageMagick"
export PATH="$(ls -d $PWD/ImageMagick-*/bin):$PATH"

fi

echo "INFO: Path to node: $PATH_TO_NODE"

echo "INFO: Removing com.apple.quarantine attributes for required binaries to run"
Expand Down

0 comments on commit 96cc35d

Please sign in to comment.