Skip to content

Commit

Permalink
Make a Docker container for pelican
Browse files Browse the repository at this point in the history
  • Loading branch information
dltj committed Nov 10, 2024
1 parent d6251ef commit 3db670b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 92 deletions.
93 changes: 37 additions & 56 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,71 +1,52 @@
# Ruby image to use, change with [--build-arg RUBY_VERSION="3.3.0"]
ARG RUBY_VERSION="3.3.0"
# Alpine image to use, change with [--build-arg ALPINE_VERSION="3.19"]
ARG ALPINE_VERSION="3.19"
# s3deploy version to use
ARG S3DEPLOY_VERSION="2.11.0"


FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION} AS dltj-jekyll-builder

# Install build dependencies
RUN set -eux; \
apk add --no-cache --virtual build-deps \
build-base \
zlib-dev \
git

# Install Bundler
RUN set -eux; gem install bundler

COPY Gemfile-docker ./Gemfile

ENV BUNDLE_HOME=/usr/local/bundle \
BUNDLE_APP_CONFIG=/usr/local/bundle \
BUNDLE_DISABLE_PLATFORM_WARNINGS=true \
BUNDLE_BIN=/usr/local/bundle/bin

# Install gems from `Gemfile` via Bundler
RUN set -eux; \
bundler install
# Use Python as the base image
FROM python:3.12.7-slim

# s3deploy version to use
ARG S3DEPLOY_VERSION="2.12.1"

FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION} AS dltj-jekyll-runner
# Repeat ARG here because [Docker is stupid](https://docs.docker.com/reference/dockerfile/#understand-how-arg-and-from-interact)
ARG S3DEPLOY_VERSION
# Set the working directory
WORKDIR /app

# `git` is needed by the last-modified-at plugin
# `nodejs` is needed by one of the gems
# `jemalloc` is the malloc replacement
RUN set -eux; \
apk add --no-cache --virtual runner-deps \
# Install necessary system dependencies and PDM
RUN apt-get update && apt-get install -y \
git \
nodejs \
jemalloc \
aws-cli \
curl \
jq
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
# Install PDM
&& curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -

# Ensure /root/.local/bin is in PATH
ENV PATH="/root/.local/bin:$PATH"

# Get the `s3deploy` program
RUN set -eux; \
curl -s -S -L -f https://github.com/bep/s3deploy/releases/download/v${S3DEPLOY_VERSION}/s3deploy_${S3DEPLOY_VERSION}_linux-amd64.tar.gz -o /tmp/s3deploy.tar.gz; \
tar -xzf /tmp/s3deploy.tar.gz --directory /usr/local/bin s3deploy; \
rm /tmp/s3deploy.tar.gz

# Install jemalloc — see https://github.com/jemalloc/jemalloc/issues/1443#issuecomment-1895891270
RUN set -eux; \
apk add --no-cache patchelf; \
patchelf --add-needed libjemalloc.so.2 /usr/local/bin/ruby; \
apk del patchelf
# Copy the pyproject.toml and pdm.lock files
COPY pyproject.toml pdm.lock* util /app/

# Install the dependencies
RUN pdm install --prod --no-self

# Clone the specified Pelican source repository
RUN git clone https://github.com/dltj/pelican.git /app/pelican

# Clone the specified theme repository
RUN git clone https://github.com/dltj/pelican-hyde.git /app/pelican-themes/pelican-hyde

ENV RUBY_YJIT_ENABLE=1 \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:500,muzzy_decay_ms:5000,narenas:2"
# Install Pelican from the cloned source
RUN pip install /app/pelican

COPY --from=dltj-jekyll-builder /usr/local/bundle /usr/local/bundle
COPY --from=dltj-jekyll-builder /Gemfile* /
# Copy your Pelican configuration files to the container
COPY pelicanconf.py /app/pelicanconf.py
COPY publishconf.py /app/publishconf.py

# Clean up
WORKDIR /srv/jekyll
# Expose port 8000 for serving
EXPOSE 8000

EXPOSE 4000
ENTRYPOINT ["bundler", "exec", "jekyll"]
CMD ["--version"]
# Let's get into it!
ENTRYPOINT ["pdm", "run", "pelican"]
CMD ["--version"]
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,14 @@ devserver-global:
publish:
"$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(PUBLISHCONF)" $(PELICANOPTS)

docker-build:
docker build -t 202092910073.dkr.ecr.us-east-1.amazonaws.com/codebuild/dltj-pelican-runner\:latest -t dltj-pelican-runner\:latest .

.PHONY: html help clean regenerate serve serve-global devserver devserver-global publish
docker-serve:
docker run --rm -v "$(CURDIR)/assets:/app/assets" -v "$(CURDIR)/content:/app/content" -v "$(CURDIR)/output:/app/output" -v "$(CURDIR)/root-content:/app/root-content" -p 8000\:8000 dltj-pelican-runner -lr content -s pelicanconf.py -o output -t /app/pelican-themes/pelican-hyde -b 0.0.0.0

docker-push:
aws --profile dltj-admin ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 202092910073.dkr.ecr.us-east-1.amazonaws.com
docker push 202092910073.dkr.ecr.us-east-1.amazonaws.com/codebuild/dltj-pelican-runner:latest

.PHONY: html help clean regenerate serve serve-global devserver devserver-global publish docker-build docker-serve docker-push
72 changes: 43 additions & 29 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"""

import os
import sys

sys.path.append("./util")
import macros
import pelican.plugins.dltj_plugin as macros

AUTHOR = "Peter Murray"
SITENAME = "Disruptive Library Technology Jester"
Expand Down
Loading

0 comments on commit 3db670b

Please sign in to comment.