Skip to content

Commit

Permalink
Working on adding universal-calibre to the CWA image instead of havin…
Browse files Browse the repository at this point in the history
…g to rely on users adding it via the DOCKER_MODS env variable in their docker-compose files.

To accomplish this, a number of oneshot start up services have been added to CWA and the Dockerfile has been modified.

Those performing development on the current release version should continue to use the old Dockerfile via Dockerfile-old in the meantime
  • Loading branch information
crocodilestick committed Nov 8, 2024
1 parent 96c329a commit b9764e6
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 7 deletions.
45 changes: 38 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ FROM ghcr.io/linuxserver/baseimage-ubuntu:jammy
# Set the default shell for the following RUN instructions to bash instead of sh
SHELL ["/bin/bash", "-c"]

# Old Example Build Command:
# docker build --tag crocodilestick/calibre-web-automated:dev --build-arg="BUILD_DATE=27-09-2024 12:06" --build-arg="VERSION=2.1.0-test-5" .
# Simple Example Build Command:
# docker build \
# --tag crocodilestick/calibre-web-automated:dev \
# --build-arg="BUILD_DATE=27-09-2024 12:06" \
# --build-arg="VERSION=2.1.0-test-5" .

# New Example Build & Push Command:
# Good guide on how to set up a buildx builder here:
# https://a-berahman.medium.com/simplifying-docker-multiplatform-builds-with-buildx-3d7efd670f58

# Multi-Platform Example Build & Push Command:
# docker buildx build \
# --push \
# --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
# --platform linux/amd64,linux/arm64, \
# --build-arg="BUILD_DATE=02-08-2024 20:52" \
# --build-arg="VERSION=2.1.0" \
# --tag crocodilestick/calibre-web-automated:latest .

# set version label
ARG BUILD_DATE
ARG VERSION
ARG CALIBREWEB_RELEASE=0.6.23
ARG LSCW_RELEASE=0.6.23-ls291
ARG UNIVERSAL_CALIBRE_RELEASE=7.16.0
LABEL build_version="Version:- ${VERSION}"
LABEL build_date="${BUILD_DATE}"
LABEL CW-Stock-version="${CALIBREWEB_RELEASE}"
Expand Down Expand Up @@ -101,6 +107,7 @@ RUN \
python3 \
python3-pip \
nano \
git \
sqlite3 && \
# STEP 2.2 - Install additional required python packages
pip install -r /app/calibre-web-automated/requirements.txt && \
Expand All @@ -125,22 +132,46 @@ RUN \
# STEP 2.4.5 - Move contents of 'root' dirs to root dir
cp -R /tmp/lscw/root/* / && \
cp -R /app/calibre-web-automated/root/* / && \
# STEP 2.4.6 - Remove the temp files
rm -R /app/calibre-web-automated/root/ && \
rm -R /tmp/lscw/root/ && \
# STEP 2.5 - ADD files referencing the verisons of the installed main packages
# CALIRBE_RELEASE already exists at root and stock CW already has a method of determiniing it's verison built in
# CALIRBE_RELEASE is placed in root by universal calibre below and containers the calibre version being used
echo "$VERSION" >| /app/CWA_RELEASE && \
echo "$LSCW_RELEASE" >| /app/LSCW_RELEASE && \
echo "$KEPUBIFY_RELEASE" >| /app/KEPUBIFY_RELEASE && \
# STEP 2.6 - Run CWA install script to make required dirs, set script permissions and add alliases for CLI commands ect.
chmod +x /app/calibre-web-automated/scripts/setup-cwa.sh && \
/app/calibre-web-automated/scripts/setup-cwa.sh
/app/calibre-web-automated/scripts/setup-cwa.sh && \
# STEP 3 - Install Universal Calibre
# STEP 3.1 - Make a temporary directory for all the required files to download
mkdir -p \
/tmp/universal-calibre/root && \
# # STEP 3.2 - Download required files from the dockermod repo
# git clone https://github.com/linuxserver/docker-mods --branch universal-calibre /tmp/universal-calibre/root && \
# STEP 3.3 - Download the version of Calibre specified in the UNIVERSAL_CALIBRE_RELEASE arg variable
if [ "$(uname -m)" == "x86_64" ]; then \
curl -o \
/tmp/universal-calibre/root/calibre.txz -L \
"https://download.calibre-ebook.com/${UNIVERSAL_CALIBRE_RELEASE}/calibre-${UNIVERSAL_CALIBRE_RELEASE}-x86_64.txz"; \
elif [ "$(uname -m)" == "aarch64" ]; then \
curl -o \
/tmp/universal-calibre/root/calibre.txz -L \
"https://download.calibre-ebook.com/${UNIVERSAL_CALIBRE_RELEASE}/calibre-${UNIVERSAL_CALIBRE_RELEASE}-arm64.txz"; \
fi && \
# STEP 3.4 - Store the UNIVERSAL_CALIBRE_RELEASE in the root of the image in CALIBRE_RELEASE
echo $UNIVERSAL_CALIBRE_RELEASE > /tmp/universal-calibre/root/CALIBRE_RELEASE && \
# STEP 3.5 - Copy all files from the /tmp/universal-calibre/root directory to the root of the image
cp -R /tmp/universal-calibre/root/* / && \
# STEP 3.6 - Remove the temp files
rm -R /tmp/universal-calibre/root/

# Removes packages that are no longer required, also emptying dirs used to build the image that are no longer needed
RUN \
echo "**** cleanup ****" && \
apt-get -y purge \
build-essential \
git \
libldap2-dev \
libsasl2-dev \
python3-dev && \
Expand Down
166 changes: 166 additions & 0 deletions Dockerfile_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# syntax=docker/dockerfile:1

FROM ghcr.io/linuxserver/unrar:latest AS unrar
FROM ghcr.io/linuxserver/baseimage-ubuntu:jammy

# Set the default shell for the following RUN instructions to bash instead of sh
SHELL ["/bin/bash", "-c"]

# Simple Example Build Command:
# docker build \
# --tag crocodilestick/calibre-web-automated:dev \
# --build-arg="BUILD_DATE=27-09-2024 12:06" \
# --build-arg="VERSION=2.1.0-test-5" .

# Good guide on how to set up a buildx builder here:
# https://a-berahman.medium.com/simplifying-docker-multiplatform-builds-with-buildx-3d7efd670f58

# Multi-Platform Example Build & Push Command:
# docker buildx build \
# --push \
# --platform linux/amd64,linux/arm64, \
# --build-arg="BUILD_DATE=02-08-2024 20:52" \
# --build-arg="VERSION=2.1.0" \
# --tag crocodilestick/calibre-web-automated:latest .

ARG BUILD_DATE
ARG VERSION
ARG CALIBREWEB_RELEASE=0.6.23
ARG LSCW_RELEASE=0.6.23-ls291
LABEL build_version="Version:- ${VERSION}"
LABEL build_date="${BUILD_DATE}"
LABEL CW-Stock-version="${CALIBREWEB_RELEASE}"
LABEL LSCW_Image_Release="${LSCW_RELEASE}"
LABEL maintainer="CrocodileStick"

# Copy local files into the container
COPY --chown=abc:abc . /app/calibre-web-automated/

# STEP 1 - Install stock Calibre-Web
RUN \
# STEP 1.1 - Installs required build & runtime packages
echo "**** install build packages ****" && \
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libldap2-dev \
libsasl2-dev \
python3-dev && \
echo "**** install runtime packages ****" && \
apt-get install -y --no-install-recommends \
imagemagick \
ghostscript \
libldap-2.5-0 \
libmagic1 \
libsasl2-2 \
libxi6 \
libxslt1.1 \
python3-venv && \
echo "**** install calibre-web ****" && \
# STEP 1.2 - Check that $CALIBREWEB_RELEASE ARG is not none and if it is, sets the variables value to the most recent tag name
if [ -z ${CALIBREWEB_RELEASE+x} ]; then \
CALIBREWEB_RELEASE=$(curl -sX GET "https://api.github.com/repos/janeczku/calibre-web/releases/latest" \
| awk '/tag_name/{print $4;exit}' FS='[""]'); \
fi && \
# STEP 1.3 - Downloads the tarball of the release stored in $CALIBREWEB_RELEASE from CW's GitHub Repo, saving it into /tmp
curl -o \
/tmp/calibre-web.tar.gz -L \
https://github.com/janeczku/calibre-web/archive/${CALIBREWEB_RELEASE}.tar.gz && \
# STEP 1.4 - Makes /app/calibre-web to extract the downloaded files from the repo to, -p to ignore potential errors that could arise if the folder already existed
mkdir -p \
/app/calibre-web && \
# STEP 1.5 - Extracts the contents of the tar.gz file downloaded from the repo to the /app/calibre-web dir previously created
tar xf \
/tmp/calibre-web.tar.gz -C \
/app/calibre-web --strip-components=1 && \
# STEP 1.6 - Sets up a python virtual enviroment and installs pip and wheel packages
cd /app/calibre-web && \
python3 -m venv /lsiopy && \
pip install -U --no-cache-dir \
pip \
wheel && \
# STEP 1.7 - Installing the required python packages listed in 'requirements.txt' and 'optional-requirements.txt'
# HOWEVER, they are not pulled from PyPi directly, they are pulled from linuxserver's Ubuntu Wheel Index
# This is essentially a repository of precompiled some of the most popular packages with C/C++ source code
# This provides the install maximum compatibility with multiple different architectures including: x86_64, armv71 and aarch64
# You can read more about python wheels here: https://realpython.com/python-wheels/
pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/ubuntu/ -r \
requirements.txt -r \
optional-requirements.txt && \
# STEP 1.8 - Installs the latest release of kepubify
echo "***install kepubify" && \
if [ -z ${KEPUBIFY_RELEASE+x} ]; then \
KEPUBIFY_RELEASE=$(curl -sX GET "https://api.github.com/repos/pgaskin/kepubify/releases/latest" \
| awk '/tag_name/{print $4;exit}' FS='[""]'); \
fi && \
curl -o \
/usr/bin/kepubify -L \
https://github.com/pgaskin/kepubify/releases/download/${KEPUBIFY_RELEASE}/kepubify-linux-64bit && \
# STEP 2 - Install Calibre-Web Automated
echo "~~~~ CWA Install - installing additional required packages ~~~~" && \
# STEP 2.1 - Install additional required packages
apt-get update && \
apt-get install -y --no-install-recommends \
xdg-utils \
inotify-tools \
python3 \
python3-pip \
nano \
sqlite3 && \
# STEP 2.2 - Install additional required python packages
pip install -r /app/calibre-web-automated/requirements.txt && \
# STEP 2.3 - Get required 'root' dir from the linuxserver/docker-calibre-web repo
echo "~~~~ Getting required files from linuxserver/docker-calibre-web... ~~~~" && \
# STEP 2.4.1 - Check the most recent release of linuxserver/docker-calibre-web and store it's tag in LSCW_RELEASE if one was not specified as an ARG
if [[ $LSCW_RELEASE == 'newest' ]]; then \
LSCW_RELEASE=$(curl -sX GET "https://api.github.com/repos/linuxserver/docker-calibre-web/releases/latest" \
| awk '/tag_name/{print $4;exit}' FS='[""]'); \
fi && \
# STEP 2.4.2 - Download the most recent LSCW release to /tmp
curl -o \
/tmp/lscw.tar.gz -L \
https://github.com/linuxserver/docker-calibre-web/archive/refs/tags/${LSCW_RELEASE}.tar.gz && \
# STEP 2.4.3 - Makes /app/calibre-web to extract the downloaded files from the repo to, -p to ignore potential errors that could arise if the folder already existed
mkdir -p \
/tmp/lscw && \
# STEP 2.4.4 - Extract contents of lscw.tat.gz to /tmp/lscw
tar xf \
/tmp/lscw.tar.gz -C \
/tmp/lscw --strip-components=1 && \
# STEP 2.4.5 - Move contents of 'root' dirs to root dir
cp -R /tmp/lscw/root/* / && \
cp -R /app/calibre-web-automated/root/* / && \
rm -R /app/calibre-web-automated/root/ && \
rm -R /tmp/lscw/root/ && \
# STEP 2.5 - ADD files referencing the verisons of the installed main packages
# CALIRBE_RELEASE already exists at root and stock CW already has a method of determiniing it's verison built in
echo "$VERSION" >| /app/CWA_RELEASE && \
echo "$LSCW_RELEASE" >| /app/LSCW_RELEASE && \
echo "$KEPUBIFY_RELEASE" >| /app/KEPUBIFY_RELEASE && \
# STEP 2.6 - Run CWA install script to make required dirs, set script permissions and add alliases for CLI commands ect.
chmod +x /app/calibre-web-automated/scripts/setup-cwa.sh && \
/app/calibre-web-automated/scripts/setup-cwa.sh

# Removes packages that are no longer required, also emptying dirs used to build the image that are no longer needed
RUN \
echo "**** cleanup ****" && \
apt-get -y purge \
build-essential \
libldap2-dev \
libsasl2-dev \
python3-dev && \
apt-get -y autoremove && \
rm -rf \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/* \
/root/.cache

# add unrar
COPY --from=unrar /usr/bin/unrar-ubuntu /usr/bin/unrar

# ports and volumes
EXPOSE 8083
VOLUME /config
VOLUME /cwa-book-ingest
VOLUME /calibre-library
Empty file.
Empty file.
81 changes: 81 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/universal-calibre-add-packages/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/with-contenv bash

if [[ "$(uname -m)" == "armv7l" ]]; then
cat <<-EOF
********************************************************
********************************************************
* *
* !!!! *
* universal-calibre mod is not supported on armhf. *
* *
********************************************************
********************************************************
EOF
exit 0
fi

if [ ! -f /usr/bin/apt ]; then
cat <<-EOF
********************************************************
********************************************************
* *
* !!!! *
* universal-calibre mod is only supported on images *
* using an Ubuntu base image. *
* *
********************************************************
********************************************************
EOF
exit 0
fi

if ! dpkg -s xz-utils >/dev/null 2>&1; then
PACKAGES="xz-utils ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libGL.so.1 ]; then
PACKAGES="libgl1 libglx-mesa0 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libxdamage.so.1 ]; then
PACKAGES="libxdamage1 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libEGL.so.1 ]; then
PACKAGES="libegl1 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0 ]; then
PACKAGES="libxkbcommon0 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libnss3.so ]; then
PACKAGES="libnss3 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libOpenGL.so.0 ]; then
PACKAGES="libopengl0 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 ]; then
PACKAGES="libxcomposite1 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libxkbfile.so.1 ]; then
PACKAGES="libxkbfile1 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libXrandr.so.2 ]; then
PACKAGES="libxrandr2 ${PACKAGES}"
fi

if [ ! -L /usr/lib/x86_64-linux-gnu/libXtst.so.6 ]; then
PACKAGES="libxtst6 ${PACKAGES}"
fi

if [ -n "${PACKAGES}" ]; then
echo "${PACKAGES}" >> /mod-repo-packages-to-install.list
echo "**** Adding calibre dependencies to package install list ****"
else
echo "**** Calibre dependencies already installed, skipping ****"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/universal-calibre-add-packages/run
Empty file.
Loading

1 comment on commit b9764e6

@Fuckingnameless
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand this commit, it drops arm64 support?

Please sign in to comment.