mediacms-io / mediacms

MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API.
https://mediacms.io
GNU Affero General Public License v3.0
2.7k stars 498 forks source link

Multi-arch builds #302

Closed thebiblelover7 closed 1 year ago

thebiblelover7 commented 2 years ago

Could it be possible to have a build for arm64? I want to run this on my Raspberry Pi, but this is currently not possible as the container is only available for x86_64 and whenever I run the container it says exec format error. Thanks ahead of time!

simao-silva commented 2 years ago

I've build successfully an image to run on a Raspberry Pi. However, when uploading the videos, multiple ffmpeg processes start for the different video qualities, which results in resource exhaustion and the upload stops. Unless the number of processes in parallel is limited, it is unfeasible to use on devices like the Raspberry Pi.

swiftugandan commented 2 years ago

Running on a raspberry-pi then possible, but without the transcoding processes. See here - https://github.com/mediacms-io/mediacms/discussions/285 to disable transcoding. @simao-silva please share your raspberry pi build instructions if you don't mind.

simao-silva commented 2 years ago

@swiftugandan Check my repository. The image is already built in Docker Hub if you would like to try it.

mgogoulos commented 2 years ago

I've build successfully an image to run on a Raspberry Pi. However, when uploading the videos, multiple ffmpeg processes start for the different video qualities, which results in resource exhaustion and the upload stops. Unless the number of processes in parallel is limited, it is unfeasible to use on devices like the Raspberry Pi.

ffmpeg starts after the uploading has completed, so if you see ffmpeg running it should mean that at least the file got uploaded. Which Raspberry Pi's are you using btw?

mgogoulos commented 2 years ago

@swiftugandan Check my repository. The image is already built in Docker Hub if you would like to try it.

I will have to get one of these to try it myself!

simao-silva commented 2 years ago

ffmpeg starts after the uploading has completed, so if you see ffmpeg running it should mean that at least the file got uploaded. Which Raspberry Pi's are you using btw?

Yes, that true. What I meant was that while waiting for the video to be ready (upload + transcoding) I often get the ffmpeg process stopped and the video only available on the original quality. While this has happen with v1.5, I am now using v1.6 and seems more stable. I am using a Raspberry Pi 4B 8GB.

mgogoulos commented 2 years ago

Hi @simao-silva , can you write the steps to get MediaCMS working on the Raspberry Pi? Would you also be interested to write a post for the blog - https://medium.com/@MediaCMS.io ?

simao-silva commented 2 years ago

@mgogoulos I just replace the default Dockerfile in the repository by the one below. Still, I am improving the building process.

ARG PYTHON_VERSION=3.9.7

############ BENTO COMPILATION ############
FROM python:${PYTHON_VERSION}-alpine AS bento-compiler

# LABEL source_code=https://github.com/axiomatic-systems/Bento4

# Setup environment variables
ARG BENTO4_VERSION=v1.6.0-639

# Install Dependencies
RUN apk update && \
    apk add --no-cache ca-certificates bash make cmake gcc g++ git

# Copy Sources and build
RUN set -eux && \
    ARCH=$(uname --m) && \
    if [ $(uname --m) = "aarch64" ]; then ARCH="arm"; fi && \
    git clone https://github.com/axiomatic-systems/Bento4 -b ${BENTO4_VERSION} /tmp/bento4 && \
    rm -rf /tmp/bento4/cmakebuild && \
    mkdir -p /tmp/bento4/cmakebuild/${ARCH} && \
    cd /tmp/bento4/cmakebuild/${ARCH} && \
    cmake -DCMAKE_BUILD_TYPE=Release ../.. && \
    make

# Install
RUN set -eux && \
    ARCH=$(uname --m) && \
    if [ $(uname --m) = "aarch64" ]; then ARCH="arm"; fi && \
    cd /tmp/bento4 && \
    python3 Scripts/SdkPackager.py ${ARCH} . cmake && \
    mkdir /opt/bento4 && \
    mv /tmp/bento4/SDK/Bento4-SDK-*/* /opt/bento4

############ OTHER COMPILATION ############
FROM python:${PYTHON_VERSION}-slim-buster AS compile-image

SHELL ["/bin/bash", "-c"]

# Set up virtualenv
ENV VIRTUAL_ENV=/home/mediacms.io
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PIP_NO_CACHE_DIR=1

RUN apt-get update && \
    apt-get install --no-install-recommends -y gcc libc6-dev libpq-dev

RUN set -eux && \
    mkdir -p /home/mediacms.io/mediacms/logs && \
    cd /home/mediacms.io && \ 
    python3 -m venv "$VIRTUAL_ENV"

# Install dependencies:
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . /home/mediacms.io/mediacms
WORKDIR /home/mediacms.io/mediacms

COPY --from=bento-compiler /opt/bento4 ../bento4

############ RUNTIME IMAGE ############
FROM python:${PYTHON_VERSION}-slim-buster as runtime-image

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV ADMIN_USER='admin'
ENV ADMIN_PASSWORD='mediacms'
ENV ADMIN_EMAIL='admin@localhost'

# See: https://github.com/celery/celery/issues/6285#issuecomment-715316219
ENV CELERY_APP='cms'

# Use these to toggle which processes supervisord should run
ENV ENABLE_UWSGI='yes'
ENV ENABLE_NGINX='yes'
ENV ENABLE_CELERY_BEAT='yes'
ENV ENABLE_CELERY_SHORT='yes'
ENV ENABLE_CELERY_LONG='yes'
ENV ENABLE_MIGRATIONS='yes'

# Set up virtualenv
ENV VIRTUAL_ENV=/home/mediacms.io
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

COPY --chown=www-data:www-data --from=compile-image /home/mediacms.io /home/mediacms.io

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        supervisor nginx ffmpeg imagemagick procps libpq-dev && \
    rm -rf /var/lib/apt/lists/* && \
    apt-get purge --auto-remove -y && \
    apt-get clean

WORKDIR /home/mediacms.io/mediacms

EXPOSE 9000 80

RUN chmod +x ./deploy/docker/entrypoint.sh

ENTRYPOINT ["./deploy/docker/entrypoint.sh"]

CMD ["./deploy/docker/start.sh"]