-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathentrypoint.sh
executable file
·133 lines (113 loc) · 4.55 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
#!/usr/bin/env bash
set -eu
command="${1:-}"
documentation="$(cat <<-HELP
Usage: docker exec CONTAINER COMMAND [ARG]
Entrypoint script of TeXlive Docker containers.
Commands:
clean Remove all files in TMP_DIR.
help Print this message.
hold Halt execution and wait for interrupt, keeping container
alive.
version Print information about the TeXlive version installed in
CONTAINER.
work [STRING] If given, interprets STRING as Bash command. Otherwise,
BUILDSCRIPT is run as work command.
Execution proceeds as follows.
1. Install dependencies listed in TEXLIVEFILE.
2. Copy content of SRC_DIR to TMP_DIR.
3. Delete files matching OUTPUT from TMP_DIR.
4. Execute work command in TMP_DIR.
5. Copy files matching OUTPUT from TMP_DIR to OUT_DIR.
Note how the command is not per se idempotent since TMP_DIR
is not cleaned after each run.
Environment Variables:
OUT_DIR Directory for the relevant output of work commands.
Default: /work/out
SRC_DIR Directory with project sources. Can be read-only.
Default: /work/src
TMP_DIR The working directory for work commands.
Default: /work/tmp
BUILDSCRIPT Script in SRC_DIR that can be run by the work command.
Default: build.sh
TEXLIVE_REPOSITORY Direct URL to a TeXlive repository;
bypasses use of mirrors.ctan.org and gives access to history versions.
Default: empty (default behaviour of tlmgr)
TEXLIVEFILE A file in SRC_DIR that contains the TeXlive packages the
project requires, one package name per line.
Default: Texlivefile
OUTPUT Bash glob pattern that defines the relevant output of
work commands.
Default: '*.pdf *.log'
HELP
)"
# Make sure the main folders exist
mkdir -p "${SRC_DIR}" "${TMP_DIR}" "${OUT_DIR}"
case "${command}" in
"" | "help" )
echo "${documentation}"
;;
"version" )
cat /version
;;
"hold" )
echo "Blocking to keep container alive"
tail -f /dev/null
;;
"clean" )
rm -rf "${TMP_DIR:?}"/*
;;
"work" ) # Just because 'run' and 'exec' are Docker keywords
case "${2:-}" in
"" )
if [[ -f "${SRC_DIR}/${BUILDSCRIPT}" ]]; then
work_command="${SRC_DIR}/${BUILDSCRIPT}"
else
echo 'Neither work command or build script given.'
exit 1
fi
;;
*)
shift
work_command="$@"
if [[ -f "${SRC_DIR}/${BUILDSCRIPT}" ]]; then
echo "Work command overrides build script ${BUILDSCRIPT}."
fi
;;
esac
# Install dependencies
hashfile="${TMP_DIR}/${TEXLIVEFILE}.sha"
mkdir -p "$(dirname "${hashfile}")"
if [[ -f "${SRC_DIR}/${TEXLIVEFILE}" ]]; then
if ! sha256sum -c "${hashfile}" > /dev/null 2>&1; then
tlrepo=""
if [ -n "${TEXLIVE_REPOSITORY}" ]; then
echo "Will use TeXlive repository ${TEXLIVE_REPOSITORY}"
tlrepo="--repository ${TEXLIVE_REPOSITORY}"
fi
echo "Installing dependencies ..."
tlmgr update ${tlrepo} --self
xargs tlmgr install ${tlrepo} < "${SRC_DIR}/${TEXLIVEFILE}"
tlmgr path add
sha256sum "${SRC_DIR}/${TEXLIVEFILE}" > "${hashfile}"
else
echo "${TEXLIVEFILE} has not changed; nothing new to install."
fi
else
echo "${TEXLIVEFILE} not found; continuing without installing additional packages."
fi
echo ""
# Execute command on a copy of the sources
set +e # continue even if globs don't match
cp -rf "${SRC_DIR}"/* "${TMP_DIR}"/
cd "${TMP_DIR}"
rm -f ${OUTPUT}
bash -c "${work_command}"; work_status=$?
cp ${OUTPUT} "${OUT_DIR}"/
exit ${work_status}
;;
* )
echo "Unknown command '${command}'"
exit 1
;;
esac