Skip to content

Commit 2ef607c

Browse files
authored
Merge pull request #40 from sebbASF/dockerfile
NR: Add a Docker build for local use
2 parents 3ad4743 + 41f84de commit 2ef607c

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

pelican/Docker.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Docker execution instructions
2+
=============================
3+
4+
Prerequisites
5+
-------------
6+
7+
You will need Docker and git.
8+
9+
Building the image
10+
------------------
11+
12+
$ git clone https://github.com/apache/infrastructure-pelican PELICANDIR
13+
14+
$ cd PELICANDIR
15+
16+
$ docker build -t IMAGENAME pelican
17+
18+
This will build the image as IMAGENAME (choose a better name!)
19+
20+
Running the image
21+
-----------------
22+
23+
$ cd <website checkout containing pelicanconf.py>
24+
25+
$ docker run --rm -it -p8000:8000 -v $PWD:/site IMAGENAME
26+
27+
This will start the Docker container.
28+
The website files are mapped to /site.
29+
30+
Browse to http://127.0.0.1:8000/
31+
32+
Changes to the website files should be reflected in the website display
33+
34+
Running the image interactively
35+
-------------------------------
36+
37+
$ cd WEBSITE # directory must contain pelicanconf.py
38+
39+
$ docker run --rm -it -p8000:8000 -v $PWD:/site --entrypoint bash IMAGENAME
40+
41+
This will start a shell in the container.
42+
Use the `pelicanasf` wrapper command to run Pelican as it automatically adds
43+
the location of the plugins to the Pelican configuration.
44+
45+
For example, to build once:
46+
47+
$ pelicanasf content
48+
49+
To build again to a different directory:
50+
51+
$ pelicanasf content -t output2
52+
53+
Testing changes to plugins
54+
--------------------------
55+
56+
For testing changes to plugins, one can remap the plugins directory to
57+
the host directory by adding a option of the form:
58+
59+
$ docker ... -v <hostpath>:/opt/pelican-asf/plugins ...
60+
where <hostpath> is the path to pelican/plugins
61+
62+
The next run of pelicanasf will pick up any changes

pelican/Dockerfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)