Last active
July 1, 2024 23:03
-
-
Save clandestine8/2a35a31855209ceb7305eaa3be22e051 to your computer and use it in GitHub Desktop.
UNIT3D Dockerfile - WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:8.1-fpm-alpine | |
# ENV & Build ARGS | |
ENV LARAVEL_DIR /var/www | |
ARG BRANCH=master | |
WORKDIR ${LARAVEL_DIR} | |
# Install Deps | |
RUN apk add --no-cache git sed nginx nodejs npm openssh-client libzip-dev libsodium-dev icu-dev mysql-client supervisor freetype-dev libjpeg-turbo-dev libpng-dev | |
RUN apk add --no-cache $PHPIZE_DEPS | |
# install modules | |
RUN docker-php-ext-install zip | |
RUN docker-php-ext-install sodium | |
RUN docker-php-ext-install pdo_mysql | |
RUN docker-php-ext-install intl | |
RUN docker-php-ext-install bcmath | |
RUN docker-php-ext-install sockets | |
RUN docker-php-ext-install pcntl | |
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ | |
RUN chmod +x /usr/local/bin/install-php-extensions | |
RUN install-php-extensions imagick | |
RUN install-php-extensions redis | |
RUN install-php-extensions @composer | |
RUN install-php-extensions opcache | |
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ | |
RUN docker-php-ext-install gd | |
# Configure NGINX | |
RUN rm /etc/nginx/http.d/default.conf | |
RUN touch /etc/nginx/http.d/default.conf | |
RUN echo 'server {' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' listen 80 default_server;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' listen [::]:80 default_server;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' root /var/www/public;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' index index.php;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' client_max_body_size 25M;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' location ~* \.php$ {' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' fastcgi_pass unix:/tmp/php-fpm.sock;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' include fastcgi_params;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' fastcgi_param SCRIPT_NAME $fastcgi_script_name;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' }' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' location / {' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' try_files $uri $uri/ /index.php?$query_string;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' }' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' location /socket.io {' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header X-Forwarded-Proto https;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header X-VerifiedViaNginx yes;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header Host $http_host;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header X-NginX-Proxy false;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_pass http://127.0.0.1:8443;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_http_version 1.1;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' proxy_set_header Connection "Upgrade";' >> /etc/nginx/http.d/default.conf \ | |
&& echo ' }' >> /etc/nginx/http.d/default.conf \ | |
&& echo '}' >> /etc/nginx/http.d/default.conf | |
#Laravel Echo Server Install | |
RUN npm install -g laravel-echo-server | |
#Configure PHP-FPM | |
RUN rm /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo '[global]' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'daemonize = no' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo '[www]' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'listen.owner = www-data' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'listen.group = www-data' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'listen = /tmp/php-fpm.sock' >> /usr/local/etc/php-fpm.d/zz-docker.conf | |
#PHP-FPM TUNING | |
RUN echo 'pm = dynamic' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'pm.max_children = 20' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'pm.start_servers = 2' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'pm.min_spare_servers = 2' >> /usr/local/etc/php-fpm.d/zz-docker.conf \ | |
&& echo 'pm.max_spare_servers = 5' >> /usr/local/etc/php-fpm.d/zz-docker.conf | |
# Configure PHP.ini | |
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" | |
RUN sed -i 's/memory_limit = 128M/memory_limit = -1/g' $PHP_INI_DIR/php.ini | |
RUN sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 25M/g' $PHP_INI_DIR/php.ini | |
RUN sed -i 's/post_max_size = 8M/post_max_size = 25M/g' $PHP_INI_DIR/php.ini | |
RUN sed -i 's/max_execution_time = 30/max_execution_time = 600/g' $PHP_INI_DIR/php.ini | |
#Enable OPCache | |
RUN echo 'opcache.enable=1' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.memory_consumption=2048' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.interned_strings_buffer=1024' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.max_accelerated_files=32531' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.validate_timestamps=0' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.save_comments=1' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.jit_buffer_size=2G' >> $PHP_INI_DIR/php.ini \ | |
&& echo 'opcache.jit=tracing' >> $PHP_INI_DIR/php.ini | |
# Configure Supervisor | |
RUN mkdir /etc/supervisor.d/ \ | |
&& touch /etc/supervisor.d/unit3d.ini \ | |
&& echo '[supervisord]' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'nodaemon=false' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'logfile=/var/log/supervisor/supervisord.log' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'pidfile=/var/run/supervisord.pid' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'childlogdir=/var/log/supervisor' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo '[program:unit3d-queue]' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'process_name=%(program_name)s_%(process_num)02d' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'command=php /var/www/artisan queue:work' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'startsecs = 0' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'autostart=true' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'autorestart=true' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'numprocs=10' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo '[program:unit3d-chat-server]' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'process_name=%(program_name)s_%(process_num)02d' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'command=laravel-echo-server start --dir=/var/www' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'autostart=true' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'autorestart=true' >> /etc/supervisor.d/unit3d.ini \ | |
&& echo 'numprocs=1' >> /etc/supervisor.d/unit3d.ini | |
RUN mkdir /var/log/supervisor/ \ | |
&& touch /var/log/supervisor/supervisord.log | |
#Configure crond | |
RUN echo '* * * * php /app/artisan schedule:run >> /dev/null 2>&1' > /etc/crontabs/root | |
#Configure Entry | |
RUN touch /usr/bin/entry \ | |
&& touch /usr/bin/start \ | |
&& touch /usr/bin/first \ | |
&& echo '#!/bin/sh' >> /usr/bin/entry \ | |
&& echo 'umask 0002' >> /usr/bin/entry \ | |
&& echo '/usr/bin/start' >> /usr/bin/entry \ | |
&& echo '#!/bin/sh' >> /usr/bin/start \ | |
&& echo 'supervisord -c /etc/supervisord.conf' >> /usr/bin/start \ | |
&& echo 'supervisorctl reload' >> /usr/bin/start \ | |
&& echo "nginx -g 'pid /tmp/nginx.pid; daemon off;' & php-fpm & /usr/sbin/crond -f" >> /usr/bin/start \ | |
&& echo '#!/bin/sh' >> /usr/bin/first \ | |
&& echo 'cd /var/www/' >> /usr/bin/first \ | |
&& echo 'php artisan storage:link' >> /usr/bin/first \ | |
&& echo 'php artisan key:generate' >> /usr/bin/first \ | |
&& echo 'php artisan migrate:fresh --seed' >> /usr/bin/first \ | |
&& chmod +x,o+x,g+x /usr/bin/start \ | |
&& chmod +x,o+x,g+x /usr/bin/entry \ | |
&& chmod +x,o+x,g+x /usr/bin/first | |
RUN rm -rf /var/www/* && chown www-data:www-data -R /var/www | |
#Switch to www-data user | |
USER www-data | |
#Clone Branch - Master by Default (to change use --build-arg BRANCH=branch-name) | |
RUN git clone https://github.com/HDInnovations/UNIT3D-Community-Edition.git . | |
RUN git --work-tree=/var/www checkout $BRANCH | |
#Laravel Echo Configuration | |
RUN touch /var/www/laravel-echo-server.json | |
RUN echo '{' >> /var/www/laravel-echo-server.json \ | |
&& echo '"authEndpoint": "/broadcasting/auth",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "clients": [],' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "database": "redis",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "databaseConfig": {' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "redis" : {' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "port": "6379",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "host": "service_redis"' >> /var/www/laravel-echo-server.json\ | |
&& echo ' }' >> /var/www/laravel-echo-server.json\ | |
&& echo '},' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "devMode": true,' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "host": null,' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "port": "8443",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "protocol": "http",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "socketio": {},' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "sslPassphrase": "",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "apiOriginAllow": {' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "allowCors": false,' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "allowOrigin": "",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "allowMethods": "",' >> /var/www/laravel-echo-server.json\ | |
&& echo ' "allowHeaders": ""' >> /var/www/laravel-echo-server.json\ | |
&& echo ' }' >> /var/www/laravel-echo-server.json\ | |
&& echo '}' >> /var/www/laravel-echo-server.json | |
RUN composer install | |
RUN npm install | |
RUN npx mix -p | |
STOPSIGNAL SIGTERM | |
EXPOSE 80 | |
USER root | |
ENTRYPOINT ["/usr/bin/entry"] | |
CMD ["/usr/bin/entry"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment