fix dirs
fix dirs

FROM ubuntu
LABEL maintainer="sboulema@gmail.com"

ENV PHP_VERSION=8.0
ENV DEBIAN_FRONTEND=noninteractive 

RUN useradd ttrss

# add PHP repository
RUN apt-get update && \
  apt-get install -y software-properties-common && \
  add-apt-repository ppa:ondrej/php

# install PHP and extensions
RUN apt-get update && apt-get install -y \
  git nginx supervisor php${PHP_VERSION}-fpm php${PHP_VERSION}-cli php${PHP_VERSION}-curl php${PHP_VERSION}-gd \
  php${PHP_VERSION}-pgsql php${PHP_VERSION}-mysql php${PHP_VERSION}-mbstring php${PHP_VERSION}-xml php${PHP_VERSION}-intl \
  && apt-get clean && rm -rf /var/lib/apt/lists/* && mkdir -p /var/run/php

# enable mbstring modules
RUN phpenmod -v ${PHP_VERSION} mbstring && phpenmod -v ${PHP_VERSION} xml

# add ttrss as the only nginx site
ADD ttrss.nginx.conf /etc/nginx/sites-available/ttrss
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/" /etc/nginx/sites-available/ttrss
RUN ln -s /etc/nginx/sites-available/ttrss /etc/nginx/sites-enabled/ttrss
RUN rm /etc/nginx/sites-enabled/default

# install ttrss
WORKDIR /var/www
RUN rm -rf *
RUN git clone https://git.tt-rss.org/fox/tt-rss.git .

# expose only nginx HTTP port
EXPOSE 80

# set configuration to look at Docker ENV variables
ADD config.docker.php config.php

# set default settings
ENV TTRSS_SELF_URL_PATH http://localhost
ENV TTRSS_DB_NAME ttrss
ENV TTRSS_DB_USER ttrss
ENV TTRSS_DB_PASS ttrss
ENV TTRSS_SESSION_COOKIE_LIFETIME 86400000
ENV TTRSS_ICONS_DIR feed-icons
ENV TTRSS_LOCK_DIRECTORY lock
ENV TTRSS_PLUGINS auth_internal
ENV TTRSS_CONFIG_VERSION 26

# set permissions on directories
RUN chown www-data:www-data -R /var/www && \ 
    chmod -R 777 images && \
    chmod -R 777 upload && \
    chmod -R 777 export && \
    chmod -R 777 feed-icons && \
    chmod -R 777 lock

# always re-configure database with current ENV when RUNning container, then monitor all services
ADD configure-db.php /configure-db.php
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/" /etc/supervisor/conf.d/supervisord.conf
CMD php /configure-db.php && supervisord -c /etc/supervisor/conf.d/supervisord.conf

FROM ubuntu
LABEL maintainer="sboulema@gmail.com"

ENV PHP_VERSION=8.0
ENV DEBIAN_FRONTEND=noninteractive 

RUN useradd ttrss

# add PHP repository
RUN apt-get update && \
  apt-get install -y software-properties-common && \
  add-apt-repository ppa:ondrej/php

# install PHP and extensions
RUN apt-get update && apt-get install -y \
  git nginx supervisor php${PHP_VERSION}-fpm php${PHP_VERSION}-cli php${PHP_VERSION}-curl php${PHP_VERSION}-gd \
  php${PHP_VERSION}-pgsql php${PHP_VERSION}-mysql php${PHP_VERSION}-mbstring php${PHP_VERSION}-xml php${PHP_VERSION}-intl \
  && apt-get clean && rm -rf /var/lib/apt/lists/* && mkdir -p /var/run/php

# enable mbstring modules
RUN phpenmod -v ${PHP_VERSION} mbstring && phpenmod -v ${PHP_VERSION} xml

# add ttrss as the only nginx site
ADD ttrss.nginx.conf /etc/nginx/sites-available/ttrss
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/" /etc/nginx/sites-available/ttrss
RUN ln -s /etc/nginx/sites-available/ttrss /etc/nginx/sites-enabled/ttrss
RUN rm /etc/nginx/sites-enabled/default

# install ttrss
WORKDIR /var/www
RUN rm -rf *
RUN git clone https://git.tt-rss.org/fox/tt-rss.git .

# expose only nginx HTTP port
EXPOSE 80

# set configuration to look at Docker ENV variables
ADD config.docker.php config.php

# set default settings
ENV TTRSS_SELF_URL_PATH http://localhost
ENV TTRSS_DB_NAME ttrss
ENV TTRSS_DB_USER ttrss
ENV TTRSS_DB_PASS ttrss
ENV TTRSS_SESSION_COOKIE_LIFETIME 86400000
ENV TTRSS_CACHE_DIR cache
ENV TTRSS_ICONS_DIR feed-icons
ENV TTRSS_LOCK_DIRECTORY lock
ENV TTRSS_PLUGINS auth_internal
ENV TTRSS_CONFIG_VERSION 26

# set permissions on directories
RUN chown www-data:www-data -R /var/www && \ 
    chmod -R 777 ${TTRSS_CACHE_DIR}/images && \
    chmod -R 777 ${TTRSS_CACHE_DIR}/upload && \
    chmod -R 777 ${TTRSS_CACHE_DIR}/export && \
    chmod -R 777 feed-icons && \
    chmod -R 777 lock

# always re-configure database with current ENV when RUNning container, then monitor all services
ADD configure-db.php /configure-db.php
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/" /etc/supervisor/conf.d/supervisord.conf
CMD php /configure-db.php && supervisord -c /etc/supervisor/conf.d/supervisord.conf
