forked from jgm/lunamark
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathDockerfile
319 lines (266 loc) · 9.58 KB
/
Dockerfile
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# syntax = docker/dockerfile:1.3-labs
ARG AUXILIARY_FILES="\
/tmp/* \
/var/tmp/* \
/var/log/* \
/var/lib/apt/lists/* \
/var/lib/{apt,dpkg,cache,log}/* \
/usr/share/man/* \
/usr/share/locale/* \
/var/cache/apt/* \
"
ARG DEPENDENCIES="\
ca-certificates \
gawk \
git \
m4 \
moreutils \
poppler-utils \
python3-pygments \
python3-venv \
rename \
retry \
unzip \
zip \
"
ARG PRODUCTION_DEPENDENCIES="\
curl \
graphviz \
npm \
pandoc \
plantuml \
wget \
"
ARG DEV_DEPENDENCIES="\
less \
vim \
"
ARG TEXLIVE_DEPENDENCIES="\
l3kernel \
latex \
latexmk \
luatex \
"
ARG BINARY_DIR=/usr/local/bin
ARG BUILD_DIR=/git-repo
ARG INSTALL_DIR=/usr/local/texlive/texmf-local
ARG PREINSTALLED_DIR=/usr/local/texlive/*/texmf-dist
ARG FROM_IMAGE=texlive/texlive
ARG TEXLIVE_TAG=latest
ARG DEV_IMAGE=false
FROM $FROM_IMAGE:$TEXLIVE_TAG as build
ARG DEPENDENCIES
ARG PRODUCTION_DEPENDENCIES
ARG TEXLIVE_DEPENDENCIES
ARG BINARY_DIR
ARG BUILD_DIR
ARG INSTALL_DIR
ARG PREINSTALLED_DIR
ARG TEXLIVE_TAG
ARG DEV_IMAGE
ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=xterm
ENV TEXMFLOCAL=${INSTALL_DIR}
COPY . ${BUILD_DIR}/
RUN <<EOF
set -o errexit
set -o nounset
set -o xtrace
# Install OS dependencies
apt-get -qy update
apt-get -qy install --no-install-recommends ${DEPENDENCIES}
if [ ${DEV_IMAGE} = false ] && echo ${TEXLIVE_TAG} | { ! grep -q latest-minimal; }
then
apt-get -qy install --no-install-recommends ${PRODUCTION_DEPENDENCIES}
npm install -g @mermaid-js/mermaid-cli
mv /root/.cache/puppeteer /puppeteer_cache
cat > /.puppeteerrc.json <<-'ANOTHER_EOF'
{
"args": ["--no-sandbox"],
"cacheDirectory": "/puppeteer_cache"
}
ANOTHER_EOF
mv ${BINARY_DIR}/mmdc ${BINARY_DIR}/mmdc.old
cat > ${BINARY_DIR}/mmdc <<-'ANOTHER_EOF'
#!/bin/bash
mmdc.old -p /.puppeteerrc.json "$@"
ANOTHER_EOF
chmod +x ${BINARY_DIR}/mmdc
fi
# Update packages in non-historic TeX Live versions
if echo ${TEXLIVE_TAG} | grep -q latest
then
retry -t 30 -d 60 tlmgr update --self --all
elif echo ${TEXLIVE_TAG} | grep -q pretest
then
retry -t 30 -d 60 tlmgr update --self --all --repository ftp://ftp.cstug.cz/pub/tex/local/tlpretest/
fi
# Install basic TeX Live dependencies
if echo ${TEXLIVE_TAG} | grep -q latest-minimal
then
retry -t 30 -d 60 tlmgr install ${TEXLIVE_DEPENDENCIES}
tlmgr path add
fi
# Uninstall the distribution Markdown package
rm -rfv ${PREINSTALLED_DIR}/tex/luatex/markdown/
rm -rfv ${PREINSTALLED_DIR}/scripts/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/generic/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/latex/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/context/third/markdown/
rm -fv ${BINARY_DIR}/markdown-cli
rm -fv ${BINARY_DIR}/markdown2tex
# Uninstall the distribution lt3luabridge package
rm -rfv ${PREINSTALLED_DIR}/tex/generic/lt3luabridge/
# Install the current Markdown package
make -C ${BUILD_DIR} implode
make -C ${BUILD_DIR} base
mkdir -p ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown.lua ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown-parser.lua ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown-unicode-data.lua ${INSTALL_DIR}/tex/luatex/markdown/
mkdir -p ${INSTALL_DIR}/scripts/markdown/
cp ${BUILD_DIR}/markdown-cli.lua ${INSTALL_DIR}/scripts/markdown/
cp ${BUILD_DIR}/markdown2tex.lua ${INSTALL_DIR}/scripts/markdown/
mkdir -p ${INSTALL_DIR}/tex/generic/markdown/
cp ${BUILD_DIR}/markdown.tex ${INSTALL_DIR}/tex/generic/markdown/
cp ${BUILD_DIR}/markdownthemewitiko_markdown_defaults.tex ${INSTALL_DIR}/tex/generic/markdown/
mkdir -p ${INSTALL_DIR}/tex/latex/markdown/
cp ${BUILD_DIR}/markdown.sty ${INSTALL_DIR}/tex/latex/markdown/
cp ${BUILD_DIR}/markdownthemewitiko_markdown_defaults.sty ${INSTALL_DIR}/tex/latex/markdown/
mkdir -p ${INSTALL_DIR}/tex/context/third/markdown/
cp ${BUILD_DIR}/t-markdown.tex ${INSTALL_DIR}/tex/context/third/markdown/
cp ${BUILD_DIR}/t-markdownthemewitiko_markdown_defaults.tex ${INSTALL_DIR}/tex/context/third/markdown/
# Make the markdown-cli and markdown2tex scripts executable
ln -s ${INSTALL_DIR}/scripts/markdown/markdown-cli.lua ${BINARY_DIR}/markdown-cli
ln -s ${INSTALL_DIR}/scripts/markdown/markdown2tex.lua ${BINARY_DIR}/markdown2tex
# Install the current lt3luabridge package
git clone https://github.com/witiko/lt3luabridge.git
cd lt3luabridge
luatex lt3luabridge.ins
mkdir -p ${INSTALL_DIR}/tex/generic/lt3luabridge/
cp lt3luabridge.tex ${INSTALL_DIR}/tex/generic/lt3luabridge/
cp lt3luabridge.sty ${INSTALL_DIR}/tex/generic/lt3luabridge/
cp t-lt3luabridge.tex ${INSTALL_DIR}/tex/generic/lt3luabridge/
# Generate the ConTeXt file database
if echo ${TEXLIVE_TAG} | { ! grep -q latest-minimal; }
then
mtxrun --generate
fi
# Reindex the TeX directory structure
texhash
# Produce the complete distribution archive of the Markdown package
if [ ${DEV_IMAGE} = false ] && echo ${TEXLIVE_TAG} | { ! grep -q latest-minimal; }
then
make -C ${BUILD_DIR} dist NO_DOCUMENTATION=false
else
make -C ${BUILD_DIR} dist NO_DOCUMENTATION=true
fi
mkdir ${BUILD_DIR}/dist
unzip ${BUILD_DIR}/markdown.tds.zip -d ${BUILD_DIR}/dist
# Include the current lt3luabridge package in the distribution directory
mkdir -p ${BUILD_DIR}/dist/tex/generic/lt3luabridge/
cp lt3luabridge.tex ${BUILD_DIR}/dist/tex/generic/lt3luabridge/
cp lt3luabridge.sty ${BUILD_DIR}/dist/tex/generic/lt3luabridge/
cp t-lt3luabridge.tex ${BUILD_DIR}/dist/tex/generic/lt3luabridge/
EOF
FROM $FROM_IMAGE:$TEXLIVE_TAG
ARG AUXILIARY_FILES
ARG DEPENDENCIES
ARG PRODUCTION_DEPENDENCIES
ARG DEV_DEPENDENCIES
ARG BINARY_DIR
ARG BUILD_DIR
ARG INSTALL_DIR
ARG PREINSTALLED_DIR
ARG TEXLIVE_TAG
ARG DEV_IMAGE
LABEL authors="Vít Starý Novotný <[email protected]>"
ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=xterm
ENV TEXMFLOCAL=${INSTALL_DIR}
COPY --from=build ${BUILD_DIR}/DEPENDS.txt ${BUILD_DIR}/DEPENDS.txt
COPY --from=build ${BUILD_DIR}/tests/DEPENDS.txt ${BUILD_DIR}/tests/DEPENDS.txt
RUN <<EOF
set -o errexit
set -o nounset
set -o xtrace
# Install dependencies, but this time we clean up after ourselves
apt-get -qy update
apt-get -qy install --no-install-recommends ${DEPENDENCIES}
if [ ${DEV_IMAGE} = true ]
then
apt-get -qy install --no-install-recommends ${DEV_DEPENDENCIES}
elif echo ${TEXLIVE_TAG} | { ! grep -q latest-minimal; }
then
apt-get -qy install --no-install-recommends ${PRODUCTION_DEPENDENCIES}
npm install -g @mermaid-js/mermaid-cli
mv /root/.cache/puppeteer /puppeteer_cache
cat > /.puppeteerrc.json <<-'ANOTHER_EOF'
{
"args": ["--no-sandbox"],
"cacheDirectory": "/puppeteer_cache"
}
ANOTHER_EOF
mv ${BINARY_DIR}/mmdc ${BINARY_DIR}/mmdc.old
cat > ${BINARY_DIR}/mmdc <<-'ANOTHER_EOF'
#!/bin/bash
mmdc.old -p /.puppeteerrc.json "$@"
ANOTHER_EOF
chmod +x ${BINARY_DIR}/mmdc
fi
apt-get -qy autoclean
apt-get -qy clean
apt-get -qy autoremove --purge
rm -rfv ${AUXILIARY_FILES}
# Update packages in non-historic TeX Live versions
if echo ${TEXLIVE_TAG} | grep -q latest
then
retry -t 30 -d 60 tlmgr update --self --all
elif echo ${TEXLIVE_TAG} | grep -q pretest
then
retry -t 30 -d 60 tlmgr update --self --all --repository ftp://ftp.cstug.cz/pub/tex/local/tlpretest/
fi
# Install TeX Live dependencies
if echo ${TEXLIVE_TAG} | grep -q latest-minimal
then
retry -t 30 -d 60 tlmgr install $(awk '{ print $2 }' ${BUILD_DIR}/DEPENDS.txt ${BUILD_DIR}/tests/DEPENDS.txt | sort -u)
tlmgr path add
fi
# Uninstall the distribution Markdown package
rm -rfv ${PREINSTALLED_DIR}/tex/luatex/markdown/
rm -rfv ${PREINSTALLED_DIR}/scripts/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/generic/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/latex/markdown/
rm -rfv ${PREINSTALLED_DIR}/tex/context/third/markdown/
rm -fv ${BINARY_DIR}/markdown-cli
rm -fv ${BINARY_DIR}/markdown2tex
# Uninstall the distribution lt3luabridge package
rm -rfv ${PREINSTALLED_DIR}/tex/generic/lt3luabridge/
EOF
# Install the Markdown package and the current lt3luabridge package
COPY --from=build ${BUILD_DIR}/dist ${INSTALL_DIR}/
RUN <<EOF
set -o errexit
set -o nounset
set -o xtrace
# Make the markdown-cli and markdown2tex scripts executable
ln -s ${INSTALL_DIR}/scripts/markdown/markdown-cli.lua ${BINARY_DIR}/markdown-cli
ln -s ${INSTALL_DIR}/scripts/markdown/markdown2tex.lua ${BINARY_DIR}/markdown2tex
# Generate the ConTeXt file database
if echo ${TEXLIVE_TAG} | grep -q latest-minimal
then
# A temporary fix for ConTeXt, see <https://gitlab.com/islandoftex/images/texlive/-/issues/30>.
sed -i '/package.loaded\["data-ini"\]/a if os.selfpath then environment.ownbin=lfs.symlinktarget(os.selfpath..io.fileseparator..os.selfname);environment.ownpath=environment.ownbin:match("^.*"..io.fileseparator) else environment.ownpath=kpse.new("luatex"):var_value("SELFAUTOLOC");environment.ownbin=environment.ownpath..io.fileseparator..(arg[-2] or arg[-1] or arg[0] or "luatex"):match("[^"..io.fileseparator.."]*$") end' /usr/bin/mtxrun.lua || true
fi
mtxrun --generate
if echo ${TEXLIVE_TAG} | grep -q latest-minimal
then
texlua /usr/bin/mtxrun.lua --luatex --generate
context --make
context --luatex --make
fi
# Reindex the TeX directory structure
texhash
# Remove the build directory
rm -rfv ${BUILD_DIR}
EOF