-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·133 lines (108 loc) · 3.26 KB
/
entrypoint.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
usage () {
echo "Usage:
docker run <container> [help|extract]
Commands:
help: show help and exit
extract: extract a json-ld or html page for a specific schema.org
data type (Dataset), for data in a Github repository
Options [extract]:
--contact | -c the name to add as the maintainer / contact
--name|-n: the name of the Dataset (required)
--html output html instead
--version the dataset version (defaults to commit)
--deploy if running in a Github action, given that
GITHUB_TOKEN is also defined, deploy html
page with embedded json-ld back to Github Pages
Examples:
docker run <container> extract --contact vsoch
docker run <container> extract --contact vsoch --html
docker run <container> extract --contact vsoch -f /path/to/Dockerfile
"
}
if [ $# -eq 0 ]; then
usage
exit
fi
EXTRACTION="no"
MAINTAINER="${GITHUB_ACTOR}"
DATASET_VERSION="${GITHUB_SHA}"
OUTPUT_FORMAT="json"
DATASET_NAME=""
DEPLOY="no"
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
while true; do
case ${1:-} in
-h|--help|help)
usage
exit
;;
--extract|extract|-e)
shift
EXTRACTION="yes"
;;
--contact|-c)
shift
MAINTAINER="${1:-}"
shift
;;
--html|html)
shift
OUTPUT_FORMAT="html"
;;
--deploy)
shift
DEPLOY="yes"
;;
--name|-n)
shift
DATASET_NAME="${1:-}"
shift
;;
--version)
shift
DATASET_VERSION="${1:-}"
shift
;;
-*)
echo "Unknown option: ${1:-}"
exit 1
;;
*)
break
;;
esac
done
# Deploy requires GITHUB_TOKEN
if [ -z "${GITHUB_TOKEN}" ]; then
DEPLOY="no"
fi
if [ -z "${MAINTAINER}" ]; then
echo "Please provide a --contact alias for the Maintainer."
exit 1;
fi
if [ "${DATASET_NAME}" == "" ]; then
echo "Please provide a --name for the Dataset."
exit 1;
fi
# Are we doing an extraction?
if [ "${EXTRACTION}" == "yes" ]; then
echo "Preparing to do extraction."
echo "Dataset Name: ${DATASET_NAME}"
echo "Dataset Maintainer: ${MAINTAINER}"
echo "Dataset Version ${DATASET_VERSION}"
echo "Output Format: ${OUTPUT_FORMAT}"
# If we are deploying, then pipe into a file
if [ "${DEPLOY}" == "yes" ]; then
# Write the index file
python3 ${HERE}/run.py "html" "${MAINTAINER}" "${DATASET_NAME}" "${DATASET_VERSION}" > /opt/index.html
cat /opt/index.html
# We know that GITHUB_TOKEN is in environment from check above
/bin/bash ${HERE}/deploy.sh /opt/index.html
# Otherwise just do the extraction
else
python3 run.py "${OUTPUT_FORMAT}" "${MAINTAINER}" "${DATASET_NAME}" "${DATASET_VERSION}"
fi
else
echo "Please select an action (e.g., docker run <container> extract <options>)"
fi