|
| 1 | +#!/usr/bin/env sh |
| 2 | +set -e |
| 3 | + |
| 4 | +# Synopsis: |
| 5 | +# Run the representer on a solution using the representer Docker image. |
| 6 | +# The representer Docker image is built automatically. |
| 7 | + |
| 8 | +# Arguments: |
| 9 | +# $1: exercise slug |
| 10 | +# $2: path to solution folder |
| 11 | +# $3: path to output directory |
| 12 | + |
| 13 | +# Output: |
| 14 | +# Writes the representation to a representation.txt and representation.json file |
| 15 | +# in the passed-in output directory. |
| 16 | +# The output files are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/representers/interface.md |
| 17 | + |
| 18 | +# Example: |
| 19 | +# ./bin/run-in-docker.sh two-fer path/to/solution/folder/ path/to/output/directory/ |
| 20 | + |
| 21 | +# Stop executing when a command returns a non-zero return code |
| 22 | +set -e |
| 23 | + |
| 24 | +# If any required arguments is missing, print the usage and exit |
| 25 | +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then |
| 26 | + echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +slug="$1" |
| 31 | +solution_dir=$(realpath "${2%/}") |
| 32 | +output_dir=$(realpath "${3%/}") |
| 33 | + |
| 34 | +# Create the output directory if it doesn't exist |
| 35 | +mkdir -p "${output_dir}" |
| 36 | + |
| 37 | +# Build the Docker image |
| 38 | +docker build --rm -t exercism/ruby-representer . |
| 39 | + |
| 40 | +# Run the Docker image using the settings mimicking the production environment |
| 41 | +docker run \ |
| 42 | + --rm \ |
| 43 | + --network none \ |
| 44 | + --read-only \ |
| 45 | + --mount type=bind,src="${solution_dir}",dst=/solution \ |
| 46 | + --mount type=bind,src="${output_dir}",dst=/output \ |
| 47 | + --mount type=tmpfs,dst=/tmp \ |
| 48 | + exercism/ruby-representer "${slug}" /solution /output |
0 commit comments