-
Notifications
You must be signed in to change notification settings - Fork 12
/
Dockerfile
108 lines (92 loc) · 3.95 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
# Dockerfile to build with infrastructure-pelican.
# Inspired from https://github.com/boonto/docker-pelican
# (which is MIT licensed) for the Pelican-specific bits.
#
# To build the image, use
#
# docker build -t pelican-asf .
#
# You can then run the image with
#
# docker run -it -p8000:8000 -v $PWD:/site pelican-asf
#
# from a folder that contains your pelicanconf.yaml file and ./content folder.
#
# That should build the site, make it available at http://localhost:8000 and rebuild
# if you make changes to the content.
#
# To run a different command you can override the entrypoint, like for example:
#
# docker run -it -p8000:8000 -v $PWD:/site --entrypoint "pelican-quickstart" pelican-asf
#
# To troubleshoot the image you can get a shell in a container that runs it, with
#
# docker run -it -p8000:8000 -v $PWD:/site --entrypoint bash pelican-asf
#
# And then run this or anything suitable in that shell to experiment:
#
# source /tmp/pelican-asf/LIBCMARKDIR.sh
# /tmp/pelican-asf/bin/buildsite.py dir --listen
#
# To build the site from the latest commit and simply listen.
#
# docker run -it -p8000:8000 -v $PWD:/site --entrypoint bash pelican-asf
# source /tmp/pelican-asf/LIBCMARKDIR.sh
# git config --global user.email "<git email>"
# git config --global user.name "<git name>"
# /tmp/pelican-asf/bin/buildsite.py git --source . --sourcebranch main --project <project>
# cd /tmp/<project>/source
# pelican -b '0.0.0.0' -l
#
# Use the Python version as installed on CI pelican builders (2023-06-02)
ARG PYTHON_VERSION=3.8.10
# Build basic Pelican image
FROM python:${PYTHON_VERSION}-slim-buster as pelican-asf
RUN apt update && apt upgrade -y
RUN apt install curl cmake build-essential -y
# Copy the current ASF code
WORKDIR /tmp/pelican-asf
# copy only the GFM build code initially, to reduce rebuilds
COPY bin/build-cmark.sh bin/build-cmark.sh
# build gfm
RUN ./bin/build-cmark.sh | grep LIBCMARKDIR > LIBCMARKDIR.sh
# Standard Pelican stuff
# rebase the image to save up to 230MB of image size
# image does not need curl, cmake and build-essential
# Use the Python version as installed on CI pelican builders (2023-06-02)
FROM python:${PYTHON_VERSION}-slim-buster
RUN apt update && apt upgrade -y
# git is used by `buildsite.py git`
RUN apt install git -y
# subversion is used by asfdata.py plugin in template-site to retrieve release information
# wget is used by pagefind.sh (www-site)
RUN apt install subversion wget -y
# we likely do not need the following
# RUN apt install unzip fontconfig -y
# Use the Pelican version as installed on CI pelican builders (2023-06-02)
ARG PELICAN_VERSION=4.5.4
# Need markdown as fallback for gfm as documented in ASF.YAML
RUN pip install pelican[markdown]==${PELICAN_VERSION}
# [1] https://cwiki.apache.org/confluence/display/INFRA/Git+-+.asf.yaml+features#Git.asf.yamlfeatures-PelicanCMS
# Copy the built cmark and ASF
WORKDIR /tmp/pelican-asf
COPY --from=pelican-asf /tmp/pelican-asf .
COPY requirements.txt .
# Don't automatically load dependencies; please add them to requirements.txt instead
RUN pip install -r requirements.txt --no-deps
# Could perhaps be added to requirements.txt but that would affect other uses
RUN pip install 'MarkupSafe<2.1.0' # needed for Pelican 4.5.4
# Now add the local code; do this last to avoid unnecessary rebuilds
COPY bin bin
COPY plugins plugins
# If the site needs authtokens to build, copy them into the file .authtokens
# and it will be picked up at build time
# N.B. make sure the .authtokens file is not committed to the repo!
RUN ln -s /site/.authtokens /root/.authtokens
# buildsite.py expects python to be here:
RUN ln -s /usr/local/bin/python3 /usr/bin/python3
# Run Pelican
WORKDIR /site
# Add settings for interactive use
RUN { cat /tmp/pelican-asf/LIBCMARKDIR.sh; echo "alias buildsite='/tmp/pelican-asf/bin/buildsite.py dir --listen'"; } >>/root/.bashrc
ENTRYPOINT [ "/bin/bash", "-c", "source /tmp/pelican-asf/LIBCMARKDIR.sh && /tmp/pelican-asf/bin/buildsite.py dir --listen" ]