/ Dockerfile
Dockerfile
  1  FROM php:8.2.28-fpm-bullseye
  2  
  3  # Set environment variables
  4  ENV DEBIAN_FRONTEND=noninteractive
  5  ARG WWWUSER
  6  ARG WWWGROUP
  7  
  8  ENV UID=${WWWUSER}
  9  ENV GID=${WWWGROUP}
 10  
 11  # Set working directory
 12  WORKDIR /home/sgoc/sgoc
 13  
 14  # Install PHP extension installer
 15  RUN curl -sSLf -o /usr/local/bin/install-php-extensions \
 16      https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
 17      chmod +x /usr/local/bin/install-php-extensions
 18  
 19  # Install system dependencies
 20  RUN apt-get update && apt-get install -y --no-install-recommends \
 21      git \
 22      gosu \
 23      htop \
 24      default-mysql-client \
 25      build-essential \
 26      libldap2-dev \
 27      openssl \
 28      libfreetype6-dev \
 29      libjpeg-dev \
 30      libpng-dev \
 31      libwebp-dev \
 32      zlib1g-dev \
 33      libzip-dev \
 34      gcc \
 35      g++ \
 36      make \
 37      vim \
 38      unzip \
 39      curl \
 40      jpegoptim \
 41      optipng \
 42      pngquant \
 43      gifsicle \
 44      locales \
 45      libonig-dev \
 46      cifs-utils \
 47      smbclient \
 48      nfs-common \
 49      cron \
 50      supervisor \
 51      libreoffice-writer \
 52      libreoffice-calc \
 53      default-jre \
 54      libreoffice-java-common \
 55      poppler-utils \
 56      pdftk-java \
 57      swig \
 58      python3-dev \
 59      python3-pip \
 60      libaio1 \
 61      nginx \
 62      && rm -rf /var/lib/apt/lists/*
 63  
 64  # Install Node.js
 65  RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - \
 66      && apt-get install -y nodejs \
 67      && npm install -g npm@10.8 \
 68      && npm cache clean --force
 69  
 70  # Install PHP extensions
 71  RUN install-php-extensions \
 72      bcmath \
 73      pdo_mysql \
 74      zip \
 75      opcache \
 76      gd \
 77      gnupg \
 78      redis \
 79      oci8
 80  
 81  # Install Composer
 82  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
 83  
 84  # Install Python packages
 85  RUN pip3 install --no-cache-dir \
 86      requests \
 87      python-decouple \
 88      endesive
 89  
 90  # Install Oracle Client
 91  RUN mkdir /opt/oracle \
 92      && curl -o /opt/oracle/instantclient-basic.zip https://download.oracle.com/otn_software/linux/instantclient/2114000/instantclient-basic-linux.x64-21.14.0.0.0dbru.zip \
 93      && curl -o /opt/oracle/instantclient-sdk.zip https://download.oracle.com/otn_software/linux/instantclient/2114000/instantclient-sdk-linux.x64-21.14.0.0.0dbru.zip \
 94      && unzip /opt/oracle/instantclient-basic.zip -d /opt/oracle \
 95      && unzip /opt/oracle/instantclient-sdk.zip -d /opt/oracle \
 96      && rm /opt/oracle/instantclient-*.zip \
 97      && echo /opt/oracle/instantclient_21_14 > /etc/ld.so.conf.d/oracle-instantclient.conf \
 98      && ldconfig
 99  
100  # Install Grype
101  RUN curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
102  
103  # Copy dependency configuration files early to leverage Docker's cache
104  COPY --chown=sgoc:sgoc pypdftools/requirements.txt ./
105  RUN pip3 install --no-cache-dir -r requirements.txt
106  
107  # Create application user and group with dynamic IDs
108  RUN groupadd -r -g ${GID} sgoc && \
109      useradd -r -u ${UID} -g sgoc -G sgoc -s /bin/bash -d /home/sgoc sgoc \
110      && mkdir -p /home/sgoc \
111      && chown -R sgoc:sgoc /home/sgoc
112  
113  
114  # Configure php.ini uploads
115  COPY uploads.ini /usr/local/etc/php/conf.d/uploads.ini
116  
117  # Configure PHP-FPM
118  COPY ./deploy/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
119  
120  # Configure Nginx
121  COPY ./deploy/nginx /etc/nginx/conf.d/
122  COPY ./deploy/certs /etc/nginx/ssl/
123  
124  
125  # Setup supervisor
126  COPY ./deploy/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
127  
128  # Create necessary directories and set permissions
129  RUN mkdir -p /var/log/nginx /var/log/supervisor /var/run/nginx /var/lib/nginx \
130      && mkdir -p /home/sgoc/sgoc/storage/framework/{sessions,views,cache} \
131      && mkdir -p /home/sgoc/sgoc/storage/logs \
132      && touch /var/log/php-fpm.log /var/log/php-fpm.access.log /var/log/php-fpm.slow.log \
133      && chown -R sgoc:sgoc /var/log/nginx /var/log/supervisor /var/run/nginx /var/lib/nginx \
134      && chown -R sgoc:sgoc /home/sgoc/sgoc/storage \
135      && chown -R sgoc:sgoc /var/log/php-fpm* \
136      && chmod -R 775 /var/log/nginx /var/log/supervisor /var/run/nginx /var/lib/nginx \
137      && chmod -R 775 /home/sgoc/sgoc/storage \
138      && chmod 664 /var/log/php-fpm*
139  
140  # Copy application files first
141  COPY --chown=sgoc:sgoc . .
142  
143  # Composer
144  RUN composer install --no-interaction \
145      && composer dump-autoload --optimize
146  
147  # npm
148  RUN npm install --unsafe-perm
149  
150  RUN chown -R sgoc:sgoc /home/sgoc/sgoc/storage \
151      && chmod -R 775 /home/sgoc/sgoc/storage
152  
153  # Create supervisor log file and set permissions
154  RUN touch /home/sgoc/sgoc/supervisord.log && \
155      chown sgoc:sgoc /home/sgoc/sgoc/supervisord.log && \
156      chmod 664 /home/sgoc/sgoc/supervisord.log
157  
158  # Make post_deploy.sh executable
159  RUN chmod +x /home/sgoc/sgoc/post_deploy.sh
160  
161  # Set the entrypoint to use post_deploy.sh
162  ENTRYPOINT ["/home/sgoc/sgoc/post_deploy.sh"]