-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·132 lines (107 loc) · 3.21 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
#!/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 (ImageDefinition), from a Dockerfile
Options [extract]:
--contact | -c the name to add as the maintainer / contact
--name|-n: the name of the container for the Dockerfile
-f|--filename: specify a Dockerfile path (other than Dockerfile)
--html output html instead
--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"
DOCKERFILE="Dockerfile"
OUTPUT_FORMAT="json"
CONTAINER_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"
;;
--filename|-f)
shift
DOCKERFILE="${1:-}"
shift
;;
--contact|-c)
shift
MAINTAINER="${1:-}"
shift
;;
--html|html)
shift
OUTPUT_FORMAT="html"
;;
--deploy)
shift
DEPLOY="yes"
;;
--name|-n)
shift
CONTAINER_NAME="${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 for the contact."
exit 1;
fi
# Are we doing an extraction?
if [ "${EXTRACTION}" == "yes" ]; then
echo "Preparing to do extraction."
echo "Dockerfile: ${DOCKERFILE}"
echo "Container Name: ${CONTAINER_NAME}"
echo "Output Format: ${OUTPUT_FORMAT}"
# Does the Dockerfile exist?
if [ ! -f "${DOCKERFILE}" ]; then
echo "${DOCKERFILE} does not exist.";
exit 1;
fi
# If we are deploying, then pipe into a file
if [ "${DEPLOY}" == "yes" ]; then
# Write the index file
python3 ${HERE}/run.py "${DOCKERFILE}" "html" "${MAINTAINER}" "${CONTAINER_NAME}" > /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 "${DOCKERFILE}" "${OUTPUT_FORMAT}" "${MAINTAINER}" "${CONTAINER_NAME}"
fi
else
echo "Please select an action (e.g., docker run <container> extract <options>)"
fi