Skip to content

Commit

Permalink
Merge pull request #472 from mchangrh/web-ui
Browse files Browse the repository at this point in the history
make dockerfile more cacheable
  • Loading branch information
CollinHeist authored Aug 4, 2024
2 parents 7a46336 + 42aaa73 commit 4a58f65
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 63 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: python3 build cache for docker
uses: actions/cache@v4
with:
path: python-build-cache
key: ${{ runner.os }}-python-build-cache-${{ hashFiles('Pipfile.lock') }}

- name: inject python-build-cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3 # v2.1.4
with:
cache-map: |
{
"python-build-cache" : "/root/.cache"
}
# Build container
- name: Build Container
uses: docker/build-push-action@v5
Expand Down
59 changes: 27 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
# syntax=docker/dockerfile:1
# Create pipenv image to convert Pipfile to requirements.txt
FROM python:3.11-slim AS pipenv

# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./

# Install pipenv and convert to requirements.txt
RUN pip3 install --no-cache-dir --upgrade pipenv; \
pipenv requirements > requirements.txt

FROM python:3.11-slim AS python-reqs
# run static install
# Install gcc for building python dependencies
RUN apt-get update && \
apt-get install -y gcc
RUN pip3 install --no-cache-dir --upgrade pipenv

# Copy requirements.txt from pipenv stage
COPY --from=pipenv /requirements.txt requirements.txt
# Install pipenv and convert to requirements.txt
COPY Pipfile Pipfile.lock ./
RUN pipenv requirements > requirements.txt

# Install gcc for building python dependencies; install TCM dependencies
RUN apt-get update && \
apt-get install -y gcc && \
pip3 install --no-cache-dir -r requirements.txt
# install TCM dependencies
RUN --mount=type=cache,target=/root/.cache \
pip3 install -r requirements.txt

# Set base image for running TCM
FROM python:3.11-slim
FROM python:3.11-slim AS final
LABEL maintainer="CollinHeist" \
description="Automated Title card maker for Emby, Jellyfin, and Plex" \
version="v2.0-alpha.10.0"

# Set working directory, copy source into container
WORKDIR /maker
COPY . /maker

# Copy python packages from python-reqs
COPY --from=python-reqs /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Script environment variables
ENV TCM_IS_DOCKER=TRUE \
TZ=UTC

# Finalize setup
# Install static dependencies
RUN \
# Create user and group to run TCM
set -eux && \
rm -f Pipfile Pipfile.lock && \
groupadd -g 314 titlecardmaker && \
useradd -u 314 -g 314 titlecardmaker && \
# Install imagemagick and curl (for healthcheck)
apt-get update && \
useradd -u 314 -g 314 titlecardmaker
# Install imagemagick and curl (for healthcheck)
RUN apt-get update && \
apt-get install -y --no-install-recommends curl imagemagick libmagickcore-6.q16-6-extra && \
cp modules/ref/policy.xml /etc/ImageMagick-6/policy.xml && \
# Remove apt cache and setup files
rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/*

# Copy python packages from python-reqs
COPY --from=python-reqs /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Set working directory, copy source into container
WORKDIR /maker
COPY . /maker

# Finalize setup
RUN cp modules/ref/policy.xml /etc/ImageMagick-6/policy.xml && \
rm -f Pipfile Pipfile.lock
# Expose TCM Port
EXPOSE 4242

Expand All @@ -60,4 +55,4 @@ HEALTHCHECK --interval=3m --timeout=10s --start-period=3m \

# Entrypoint
CMD ["python3", "-u", "-m", "uvicorn", "app-main:app", "--host", "0.0.0.0", "--port", "4242"]
ENTRYPOINT ["bash", "./start.sh"]
ENTRYPOINT ["bash", "./start.sh"]
56 changes: 25 additions & 31 deletions Dockerfile.armv7
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# syntax=docker/dockerfile:1
# Create pipenv image to convert Pipfile to requirements.txt
FROM python:3.11-slim as pipenv

# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./

# Install pipenv and convert to requirements.txt
RUN pip3 install --no-cache-dir --upgrade pipenv; \
pipenv requirements > requirements.txt

FROM python:3.11-slim as python-reqs

# Copy requirements.txt from pipenv stage
COPY --from=pipenv /requirements.txt requirements.txt

# Install dependencies for building python dependencies; install TCM dependencies
# cffi: libffi-dev
# bcrypt: build-essential, cargo
Expand All @@ -27,44 +14,51 @@ RUN apt-get update && \
apt-get install -y \
build-essential curl libffi-dev libssl-dev pkg-config python3-dev python3-setuptools \
libtiff5-dev libjpeg62-turbo-dev libopenjp2-7-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk libharfbuzz-dev libfribidi-dev libxcb1-dev
RUN curl https://sh.rustup.rs | sh -s -- -y

RUN curl https://sh.rustup.rs | sh -s -- -y
# add manual dockerfile cachine
# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./
# Install pipenv and convert to requirements.txt
RUN pip3 install --no-cache-dir --upgrade pipenv; \
pipenv requirements > requirements.txt

# add manual dockerfile caching
RUN --mount=type=cache,target=/root/.cache \
. "$HOME/.cargo/env" && \
pip3 install -r requirements.txt

# Set base image for running TCM
FROM python:3.11-slim
FROM python:3.11-slim AS final
LABEL maintainer="CollinHeist" \
description="Automated Title card maker for Emby, Jellyfin, and Plex" \
version="v2.0-alpha.10.0"

# Set working directory, copy source into container
WORKDIR /maker
COPY . /maker

# Copy python packages from python-reqs
COPY --from=python-reqs /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Script environment variables
ENV TCM_IS_DOCKER=TRUE \
TZ=UTC

# Finalize setup
# Install static dependencies
RUN \
# Create user and group to run TCM
set -eux && \
rm -f Pipfile Pipfile.lock && \
groupadd -g 314 titlecardmaker && \
useradd -u 314 -g 314 titlecardmaker && \
# Install imagemagick and curl (for healthcheck)
apt-get update && \
useradd -u 314 -g 314 titlecardmaker
# Install imagemagick and curl (for healthcheck)
RUN apt-get update && \
apt-get install -y --no-install-recommends curl imagemagick libmagickcore-6.q16-6-extra && \
cp modules/ref/policy.xml /etc/ImageMagick-6/policy.xml && \
# Remove apt cache and setup files
rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/*

# Copy python packages from python-reqs
COPY --from=python-reqs /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Set working directory, copy source into container
WORKDIR /maker
COPY . /maker

# Finalize setup
RUN cp modules/ref/policy.xml /etc/ImageMagick-6/policy.xml && \
rm -f Pipfile Pipfile.lock && \

# Expose TCM Port
EXPOSE 4242

Expand All @@ -75,4 +69,4 @@ HEALTHCHECK --interval=3m --timeout=10s --start-period=3m \

# Entrypoint
CMD ["python3", "-u", "-m", "uvicorn", "app-main:app", "--host", "0.0.0.0", "--port", "4242"]
ENTRYPOINT ["bash", "./start.sh"]
ENTRYPOINT ["bash", "./start.sh"]

0 comments on commit 4a58f65

Please sign in to comment.