409 lines
13 KiB
Docker
409 lines
13 KiB
Docker
ARG LIBRETIME_VERSION
|
|
#======================================================================================#
|
|
# Python Builder #
|
|
#======================================================================================#
|
|
FROM python:3.10-slim-bullseye AS python-builder
|
|
|
|
WORKDIR /build
|
|
|
|
# Wheels
|
|
WORKDIR /build/shared
|
|
COPY shared .
|
|
RUN pip wheel --wheel-dir . --no-deps .
|
|
|
|
WORKDIR /build/api-client
|
|
COPY api-client .
|
|
RUN pip wheel --wheel-dir . --no-deps .
|
|
|
|
#======================================================================================#
|
|
# Python base #
|
|
#======================================================================================#
|
|
FROM python:3.10-slim-bullseye AS python-base
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Custom user
|
|
ARG USER=libretime
|
|
ARG UID=1000
|
|
ARG GID=1000
|
|
|
|
RUN set -eux \
|
|
&& adduser --disabled-password --uid=$UID --gecos '' --no-create-home ${USER} \
|
|
&& install --directory --owner=${USER} /etc/libretime /srv/libretime
|
|
|
|
ENV LIBRETIME_CONFIG_FILEPATH=/etc/libretime/config.yml
|
|
|
|
# Shared packages
|
|
COPY tools/packages.py /tmp/packages.py
|
|
COPY shared/packages.ini /tmp/packages.ini
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
$(python3 /tmp/packages.py --format=line --exclude=python bullseye /tmp/packages.ini) \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -f /tmp/packages.py /tmp/packages.ini
|
|
|
|
#======================================================================================#
|
|
# Python base with ffmpeg #
|
|
#======================================================================================#
|
|
FROM python-base AS python-base-ffmpeg
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
ffmpeg \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
#======================================================================================#
|
|
# Analyzer #
|
|
#======================================================================================#
|
|
FROM python-base-ffmpeg AS libretime-analyzer
|
|
|
|
COPY tools/packages.py /tmp/packages.py
|
|
COPY analyzer/packages.ini /tmp/packages.ini
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
$(python3 /tmp/packages.py --format=line --exclude=python bullseye /tmp/packages.ini) \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -f /tmp/packages.py /tmp/packages.ini
|
|
|
|
WORKDIR /src
|
|
|
|
COPY analyzer/requirements.txt .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile -r requirements.txt
|
|
|
|
COPY --from=python-builder /build/shared/*.whl .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile *.whl && rm -Rf *.whl
|
|
|
|
COPY analyzer .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --editable .[sentry]
|
|
|
|
# Run
|
|
USER ${UID}:${GID}
|
|
WORKDIR /app
|
|
|
|
CMD ["/usr/local/bin/libretime-analyzer"]
|
|
|
|
ARG LIBRETIME_VERSION
|
|
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION
|
|
|
|
#======================================================================================#
|
|
# Playout #
|
|
#======================================================================================#
|
|
FROM python-base-ffmpeg AS libretime-playout
|
|
|
|
COPY tools/packages.py /tmp/packages.py
|
|
COPY playout/packages.ini /tmp/packages.ini
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
$(python3 /tmp/packages.py --format=line --exclude=python bullseye /tmp/packages.ini) \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -f /tmp/packages.py /tmp/packages.ini
|
|
|
|
WORKDIR /src
|
|
|
|
COPY playout/requirements.txt .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile -r requirements.txt
|
|
|
|
COPY --from=python-builder /build/shared/*.whl .
|
|
COPY --from=python-builder /build/api-client/*.whl .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile *.whl && rm -Rf *.whl
|
|
|
|
COPY playout .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --editable .[sentry]
|
|
|
|
# Run
|
|
USER ${UID}:${GID}
|
|
WORKDIR /app
|
|
|
|
CMD ["/usr/local/bin/libretime-playout"]
|
|
|
|
ARG LIBRETIME_VERSION
|
|
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION
|
|
|
|
#======================================================================================#
|
|
# API #
|
|
#======================================================================================#
|
|
FROM python-base AS libretime-api
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
curl \
|
|
gcc \
|
|
libc6-dev \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /src
|
|
|
|
COPY api/requirements.txt .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile -r requirements.txt
|
|
|
|
COPY --from=python-builder /build/shared/*.whl .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile *.whl && rm -Rf *.whl
|
|
|
|
COPY api .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --editable .[prod,sentry]
|
|
|
|
# Run
|
|
USER ${UID}:${GID}
|
|
WORKDIR /app
|
|
|
|
CMD ["/usr/local/bin/gunicorn", \
|
|
"--workers=4", \
|
|
"--worker-class=libretime_api.gunicorn.Worker", \
|
|
"--log-file", "-", \
|
|
"--bind=0.0.0.0:9001", \
|
|
"libretime_api.asgi"]
|
|
|
|
ARG LIBRETIME_VERSION
|
|
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION
|
|
|
|
HEALTHCHECK CMD ["curl", "--fail", "http://localhost:9001/api/v2/version"]
|
|
|
|
#======================================================================================#
|
|
# Worker #
|
|
#======================================================================================#
|
|
FROM python-base AS libretime-worker
|
|
|
|
WORKDIR /src
|
|
|
|
COPY worker/requirements.txt .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile -r requirements.txt
|
|
|
|
COPY --from=python-builder /build/shared/*.whl .
|
|
COPY --from=python-builder /build/api-client/*.whl .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --no-compile *.whl && rm -Rf *.whl
|
|
|
|
COPY worker .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install --editable .[sentry]
|
|
|
|
# Run
|
|
USER ${UID}:${GID}
|
|
WORKDIR /app
|
|
|
|
CMD ["/usr/local/bin/libretime-worker"]
|
|
ARG LIBRETIME_VERSION
|
|
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION
|
|
|
|
#======================================================================================#
|
|
# Legacy #
|
|
#======================================================================================#
|
|
FROM php:7.4-fpm AS libretime-legacy
|
|
|
|
ENV LIBRETIME_CONFIG_FILEPATH=/etc/libretime/config.yml
|
|
ENV LIBRETIME_LOG_FILEPATH=php://stderr
|
|
|
|
# Custom user
|
|
ARG USER=libretime
|
|
ARG UID=1000
|
|
ARG GID=1000
|
|
|
|
RUN set -eux \
|
|
&& adduser --disabled-password --uid=$UID --gecos '' --no-create-home ${USER} \
|
|
&& install --directory --owner=${USER} /etc/libretime /srv/libretime
|
|
|
|
RUN set -eux \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
gettext \
|
|
libcurl4-openssl-dev \
|
|
libfreetype6-dev \
|
|
libjpeg62-turbo-dev \
|
|
libonig-dev \
|
|
libpng-dev \
|
|
libpq-dev \
|
|
libxml2-dev \
|
|
libyaml-dev \
|
|
libzip-dev \
|
|
locales \
|
|
unzip \
|
|
zlib1g-dev \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& pecl install apcu yaml \
|
|
&& docker-php-ext-enable apcu yaml \
|
|
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
|
&& docker-php-ext-install -j$(nproc) \
|
|
bcmath \
|
|
curl \
|
|
exif \
|
|
gd \
|
|
gettext \
|
|
mbstring \
|
|
opcache \
|
|
pdo_pgsql \
|
|
pgsql \
|
|
sockets \
|
|
xml
|
|
|
|
COPY legacy/locale/locale.gen /etc/locale.gen
|
|
RUN locale-gen
|
|
|
|
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
|
COPY "legacy/install/php/libretime-legacy.ini" "$PHP_INI_DIR/conf.d/"
|
|
|
|
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
|
|
|
|
WORKDIR /var/www/html
|
|
|
|
COPY legacy/composer.* ./
|
|
RUN composer --no-cache install --no-progress --no-interaction --no-dev --no-autoloader
|
|
|
|
COPY legacy .
|
|
RUN set -eux \
|
|
&& make locale-build \
|
|
&& composer --no-cache dump-autoload --no-interaction --no-dev
|
|
|
|
# Run
|
|
USER ${UID}:${GID}
|
|
|
|
ARG LIBRETIME_VERSION
|
|
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION
|
|
|
|
#======================================================================================#
|
|
# Sintonia #
|
|
#======================================================================================#
|
|
|
|
# Use PHP as the base
|
|
FROM php:8.2-cli AS sintonia-webapp-base
|
|
|
|
# Arguments defined in docker-compose-dev.yml
|
|
ARG sintonia_user=$SINTONIA_USER
|
|
ARG sintonia_uid=$SINTONIA_UID
|
|
ARG sintonia_node_version=$SINTONIA_NODE_VERSION
|
|
ARG sintonia_production=$SINTONIA_PRODUCTION
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# Install Additional System Dependencies and PHP Extensions
|
|
RUN set -eux && \
|
|
apt-get update -y && \
|
|
apt-get install -y --no-install-recommends \
|
|
libjpeg62-turbo-dev \
|
|
libfreetype6-dev \
|
|
libmcrypt-dev \
|
|
zlib1g-dev \
|
|
zip \
|
|
unzip \
|
|
libzip-dev \
|
|
libpng-dev \
|
|
git \
|
|
libonig-dev \
|
|
libpq-dev
|
|
|
|
RUN docker-php-ext-configure zip && \
|
|
docker-php-ext-configure gd --with-freetype --with-jpeg
|
|
|
|
RUN docker-php-ext-install gd exif pcntl bcmath mysqli pdo_mysql mbstring && \
|
|
docker-php-ext-install pdo_pgsql pgsql && \
|
|
apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create system user to run Composer and Artisan Commands
|
|
RUN set -eux && useradd -G www-data -u $sintonia_uid -d /home/$sintonia_user $sintonia_user && \
|
|
mkdir -p /home/$sintonia_user/.composer && \
|
|
mkdir -p /var/www/sintonia_webapp && \
|
|
chown -R $sintonia_user:$sintonia_user /home/$sintonia_user && \
|
|
chown -R $sintonia_user:$sintonia_user /var/www/sintonia_webapp
|
|
|
|
USER "$sintonia_user"
|
|
WORKDIR /home/$sintonia_user
|
|
# Install composer
|
|
RUN set -eux && curl -sS https://getcomposer.org/installer | php -- --filename=composer
|
|
|
|
# node and composer installation
|
|
# Download and install nvm:
|
|
RUN curl -fsSL https://nodejs.org/dist/v$sintonia_node_version/node-v$sintonia_node_version-linux-x64.tar.gz -o node.tar.gz && \
|
|
tar -xzvf node.tar.gz && \
|
|
rm node.tar.gz
|
|
|
|
ENV PATH="/home/$sintonia_user/node-v$sintonia_node_version-linux-x64/bin:/home/$sintonia_user/composer:${PATH}"
|
|
|
|
#Build
|
|
FROM sintonia-webapp-base AS sintonia-webapp-build-common
|
|
ARG sintonia_config_filepath=$SINTONIA_CONFIG_FILEPATH
|
|
ARG libretime_config_filepath=$LIBRETIME_CONFIG_FILEPATH
|
|
|
|
USER root
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install yq -y
|
|
USER "$sintonia_user"
|
|
|
|
WORKDIR $HOME
|
|
COPY --chown=$sintonia_user:$sintonia_user ./tools/populate-laravel-env-file.sh /home/$sintonia_user/
|
|
COPY --chown=$sintonia_user:$sintonia_user $sintonia_config_filepath /home/$sintonia_user/
|
|
COPY --chown=$sintonia_user:$sintonia_user $libretime_config_filepath /home/$sintonia_user/
|
|
RUN chmod +x ./populate-laravel-env-file.sh && \
|
|
./populate-laravel-env-file.sh /home/$sintonia_user/config.yml /home/$sintonia_user/.env
|
|
|
|
# DEV
|
|
FROM sintonia-webapp-build-common AS sintonia-webapp-dev
|
|
|
|
ARG sintonia_laravel_port
|
|
ARG sintonia_vite_port
|
|
|
|
ENV sintonia_laravel_port=${sintonia_laravel_port}
|
|
ENV sintonia_vite_port=${sintonia_vite_port}
|
|
|
|
USER root
|
|
RUN pecl install xdebug && docker-php-ext-enable xdebug;
|
|
USER $sintonia_user
|
|
|
|
WORKDIR /var/www/sintonia_webapp
|
|
#COPY --chown=$sintonia_user:$sintonia_user ./sintonia_webapp/ ./
|
|
|
|
#Package installation
|
|
#RUN git config --global --add safe.directory /var/www/sintonia_webapp && \
|
|
# /home/$sintonia_user/composer install --no-progress --no-interaction --no-dev --no-autoloader && \
|
|
# set -eux && \
|
|
# npm i
|
|
|
|
#RUN php artisan ziggy:generate && mv ziggy.js resources/utils/ziggy.js
|
|
#RUN cp $HOME/.env ./
|
|
ENV sintonia_user=${sintonia_user}
|
|
### Start server
|
|
CMD git config --global --add safe.directory /var/www/sintonia_webapp && \
|
|
/home/$sintonia_user/composer install --no-progress --no-interaction --no-dev --no-autoloader && \
|
|
/home/$sintonia_user/composer --no-cache dump-autoload --no-interaction --no-dev && \
|
|
php artisan key:generate && \
|
|
set -eux && \
|
|
npm i && \
|
|
npx vite --port $sintonia_vite_port --host & \
|
|
php artisan serve --host=0.0.0.0 --port=$sintonia_laravel_port & \
|
|
sleep infinity
|
|
|
|
|
|
|
|
FROM sintonia-webapp-build-common AS sintonia-webapp-production
|
|
|
|
RUN git clone https://git.congegni.net/sintonia_webapp && \
|
|
cd sintonia_webapp && \
|
|
php artisan ziggy:generate && \
|
|
php artisan key:generate && \
|
|
mv ziggy.js resources/utils/ziggy.js && \
|
|
npx vite build && \
|
|
cp -r dist/build/* /var/www/html/ && \
|
|
rm -rf /var/www/sintonia_webapp/node_modules /var/www/sintonia_webapp/.npm /var/www/sintonia_webapp/.composer /var/www/sintonia_webapp/.git && \
|
|
rm -rf /home/$sintonia_user/node* /home/$sintonia_user/composer
|
|
|
|
|
|
|