|
| 1 | +# Settings |
| 2 | +# ======== |
| 3 | +# Use the Python version as installed on CI pelican builders (2023-06-02) |
| 4 | +ARG PYTHON_VERSION=3.8.10 |
| 5 | +ARG GFM_VERSION=0.28.3.gfm.12 # must agree with copy below |
| 6 | + |
| 7 | +# Build cmake-gfm |
| 8 | +FROM python:${PYTHON_VERSION}-slim-buster as pelican-asf |
| 9 | + |
| 10 | +RUN apt update && apt upgrade -y |
| 11 | +RUN apt install curl cmake build-essential -y |
| 12 | + |
| 13 | +WORKDIR /opt/pelican-asf |
| 14 | + |
| 15 | +# Copy only what we need to build cmark-gfm |
| 16 | +COPY build-cmark.sh bin/build-cmark.sh |
| 17 | + |
| 18 | +# build it |
| 19 | +RUN bash bin/build-cmark.sh ${GFM_VERSION} |
| 20 | + |
| 21 | +# rebase the image to save on image size |
| 22 | +FROM python:${PYTHON_VERSION}-slim-buster |
| 23 | + |
| 24 | +# Use the Pelican version as installed on CI pelican builders (2023-06-02) |
| 25 | +ARG PELICAN_VERSION=4.5.4 |
| 26 | +ARG GFM_VERSION=0.28.3.gfm.12 # must agree with copy above |
| 27 | + |
| 28 | +# Where we put GFM and the plugins |
| 29 | +ENV WORKDIR /opt/pelican-asf |
| 30 | +ENV LIBCMARKDIR ${WORKDIR}/cmark-gfm-${GFM_VERSION}/lib |
| 31 | + |
| 32 | +RUN apt update && apt upgrade -y |
| 33 | + |
| 34 | +# subversion is used by asfdata.py plugin in template-site to retrieve release information |
| 35 | +# wget is used by pagefind.sh (www-site) |
| 36 | +RUN apt install subversion wget -y |
| 37 | + |
| 38 | +# Need markdown as fallback for gfm as documented in ASF.YAML |
| 39 | +RUN pip install pelican[markdown]==${PELICAN_VERSION} |
| 40 | +# [1] https://cwiki.apache.org/confluence/display/INFRA/Git+-+.asf.yaml+features#Git.asf.yamlfeatures-PelicanCMS |
| 41 | + |
| 42 | +# Copy the built cmark and ASF |
| 43 | +WORKDIR $LIBCMARKDIR |
| 44 | +COPY --from=pelican-asf $LIBCMARKDIR . |
| 45 | + |
| 46 | +WORKDIR $WORKDIR |
| 47 | + |
| 48 | +COPY requirements.txt . |
| 49 | +# Don't automatically load dependencies; please add them to requirements.txt instead |
| 50 | +RUN pip install -r requirements.txt --no-deps |
| 51 | + |
| 52 | +# Could perhaps be added to requirements.txt but that would affect other uses |
| 53 | +RUN pip install 'MarkupSafe<2.1.0' # needed for Pelican 4.5.4 |
| 54 | + |
| 55 | +# Now add the local code; do this last to avoid unnecessary rebuilds |
| 56 | +COPY plugin_paths.py . |
| 57 | +COPY plugins plugins |
| 58 | +# Tidy up any old builds |
| 59 | +RUN { find plugins -type d -name __pycache__ -exec rm -rf {} \; ; true; } |
| 60 | + |
| 61 | +# If the site needs authtokens to build, copy them into the file .authtokens |
| 62 | +# and it will be picked up at build time |
| 63 | +# N.B. make sure the .authtokens file is not committed to the repo! |
| 64 | +RUN ln -s /site/.authtokens /root/.authtokens |
| 65 | + |
| 66 | +WORKDIR /site |
| 67 | + |
| 68 | +# Create a pelicanasf wrapper to add required arguments |
| 69 | +# The initial hashbang is needed, otherwise docker complains: 'exec format error' |
| 70 | +RUN { echo '#!/usr/bin/env bash' >/usr/local/bin/pelicanasf; chmod +x /usr/local/bin/pelicanasf;} |
| 71 | +# The -b (bind) is needed to allow connections from the host |
| 72 | +RUN echo 'SRC=${1:?source}; shift; python3 -B -m pelican $SRC -b 0.0.0.0 -e "$(python3 $WORKDIR/plugin_paths.py $WORKDIR/plugins)" "$@"' >>/usr/local/bin/pelicanasf; |
| 73 | + |
| 74 | +# --autoreload (-r) and --listen (-l) |
| 75 | +ENTRYPOINT [ "pelicanasf", "content", "-rl"] |
0 commit comments