forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-schema-faker.bash
executable file
·52 lines (42 loc) · 1.37 KB
/
json-schema-faker.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\n\t'
image_name="$(basename $0):latest"
# get a temp directory
tmp_dir=$(mktemp --directory)
# paste there the JS file copied from [https://github.com/oprogramador/json-schema-faker-cli/blob/master/app/generate.js]
# used here because it was linked to an old version of json-schema-faker
cat << EOF > $tmp_dir/generate.js
#!/usr/bin/env node
const jsonfile = require('jsonfile');
const faker = require('json-schema-faker');
function generate(inputPath, outputPath) {
const inputObject = jsonfile.readFileSync(inputPath);
const output = faker.generate(inputObject)
jsonfile.writeFileSync(outputPath, output);
}
generate(process.argv[2], process.argv[3])
EOF
# create a Dockerfile
cat << EOF > $tmp_dir/Dockerfile
FROM node:12.18.2
COPY ./generate.js /app/generate.js
WORKDIR /app
RUN npm install \
[email protected] && \
npm list --depth=0
ENTRYPOINT ["node", "/app/generate.js"]
EOF
docker buildx build --load --tag "$image_name" $tmp_dir
schema="$(basename $1)"
output="$(basename $2)"
docker run \
--user "$(id --user ${USER})":"$(id --group ${USER})" \
--rm \
--volume "$(realpath $1)":/src/"$schema" \
--volume $(dirname $(realpath "$2")):/output/ \
"$image_name" "/src/$schema" "/output/$output"