diff --git a/.gitignore b/.gitignore index 832d3c8..fe38b79 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ src/application/logs/* src/application/config/ src/application/application/logs/ src/logs/ +src/public/ ### CodeIgniter Patch ### @@ -41,3 +42,4 @@ src/logs/ /composer.json /composer.lock /docker-compose.yml + diff --git a/Dockerfile b/Dockerfile index 3f892f2..9aa9f3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,64 +1,39 @@ FROM php:7.4-fpm-alpine -# FROM alpine:latest ENV ACCEPT_EULA=Y WORKDIR /app -# Essentials -RUN echo "Asia/Jakarta" > /etc/timezone - # Install nginx -RUN apk add --no-cache nginx supervisor - -# Install prerequisites required for tools and extensions installed later on. -# RUN apk add --update bash gnupg less libpng-dev libzip-dev su-exec unzip - -# # Install prerequisites for the sqlsrv and pdo_sqlsrv PHP extensions. -# RUN curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.2.1-1_amd64.apk \ -# && curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_amd64.apk \ -# && curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.2.1-1_amd64.sig \ -# && curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_amd64.sig \ -# && curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import - \ -# && gpg --verify msodbcsql18_18.3.2.1-1_amd64.sig msodbcsql18_18.3.2.1-1_amd64.apk \ -# && gpg --verify mssql-tools18_18.3.1.1-1_amd64.sig mssql-tools18_18.3.1.1-1_amd64.apk \ -# && apk add --allow-untrusted msodbcsql18_18.3.2.1-1_amd64.apk mssql-tools18_18.3.1.1-1_amd64.apk \ -# && rm *.apk *.sig - -# # Retrieve the script used to install PHP extensions from the source container. -# COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/install-php-extensions - -# # Install required PHP extensions and all their prerequisites available via apt. -# RUN chmod uga+x /usr/bin/install-php-extensions \ -# && sync \ -# && install-php-extensions bcmath ds exif gd intl opcache pcntl pdo_sqlsrv redis sqlsrv zip +RUN apk add --no-cache nginx supervisor bash # Install PHP Extensions RUN set -ex && apk --no-cache add icu-dev postgresql-dev -RUN docker-php-ext-install opcache pdo mysqli pdo_mysql pgsql pdo_pgsql\ - && docker-php-ext-enable pdo_mysql pdo_pgsql +RUN docker-php-ext-install opcache pdo pgsql pdo_pgsql\ + && docker-php-ext-enable pdo_pgsql RUN docker-php-ext-configure intl && docker-php-ext-install intl + # Copy php-fpm configs -COPY ./_docker/php-fpm/www.conf /usr/local/etc/php-fpm.d/www.conf +COPY ./_docker/php-fpm/www.conf /usr/local/etc/php-fpm.d/zz-docker.conf COPY ./_docker/php-fpm/php.ini /usr/local/etc/php/conf.d COPY ./_docker/php-fpm/opcache.ini /usr/local/etc/php/conf.d/opcache.ini +COPY ./_docker/php-fpm/session.ini /usr/local/etc/php/conf.d/session.ini # Copy nginx-configs COPY ./_docker/nginx/app.conf /etc/nginx/conf.d/default.conf COPY ./_docker/nginx/nginx.conf /etc/nginx/nginx.conf +COPY ./_docker/nginx/footer.conf /etc/nginx/footer.conf # Copy supervisord config COPY ./_docker/supervisord/supervisord.conf /etc/supervisord.conf +COPY ./_docker/supervisord/init.sh /init.sh -# COPY --chown=www-data:www-data ./src/ . +COPY --chown=www-data:www-data ./src . -# RUN mkdir /mnt/media -# RUN chown -R www-data:www-data /mnt/media -# RUN mkdir /mnt/media/ris -# RUN chown -R www-data:www-data /mnt/media/ris -# COPY --chown=www-data:www-data ./media/ . - -EXPOSE 80 443 +ARG APP_VERSION +ENV APP_VERSION=$APP_VERSION +EXPOSE 80 +ENTRYPOINT [ "/init.sh" ] CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] \ No newline at end of file diff --git a/_docker/nginx/app.conf b/_docker/nginx/app.conf index 8eaf028..30f16e0 100644 --- a/_docker/nginx/app.conf +++ b/_docker/nginx/app.conf @@ -1,37 +1,82 @@ -server { - listen 80 default_server; - index index.php index.html; - root /app; - access_log /var/log/nginx/access.log; - error_log /var/log/nginx/error.log; - - # set client body size# - client_max_body_size 8M; - - location / { - try_files $uri $uri/ /index.php?$args; - } - location ~ \.php$ { - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - } - - try_files $uri $uri/ /index.php; - if (!-e $request_filename){ - rewrite ^/admin/(.*)$ /admin/index.php?/$1? last; - rewrite ^/api/(.*)$ /api/index.php?/$1? last; - rewrite ^/webhook/(.*)$ /webhook/index.php?/$1? last; - rewrite ^/(.*)$ /index.php?/$1? last; - } - - location ~* \.(jpe?g|gif|png|bmp|ico|pdf|zip|htm|html|docx?|xlsx?|pptx?|txt|wav|swf|avi|mp\d)$ { - access_log off; - log_not_found off; - try_files $uri $uri/ $document_root$uri /index.php?$args; - expires 1w; - } +server { + listen 80 default_server; + index index.php index.html; + root /app; + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + # set client body size# + client_max_body_size 8M; + + location / { + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + # + # Tell client that this pre-flight info is valid for 20 days + # + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; + } + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + # try_files $uri $uri/ /index.php?$args; + + } + location ~ \.php$ { + # include snippets/fastcgi-php.conf; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + # fastcgi_pass 127.0.0.1:9000; + fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + + fastcgi_buffers 4 4096k; + fastcgi_buffer_size 32k; + + fastcgi_connect_timeout 3000s; + fastcgi_send_timeout 3000s; + fastcgi_read_timeout 3000s; + } + + # try_files $uri $uri/ /index.php; + # if (!-e $request_filename){ + # rewrite ^/admin/(.*)$ /admin/index.php?/$1? last; + # rewrite ^/api/(.*)$ /api/index.php?/$1? last; + # rewrite ^/(.*)$ /index.php?/$1? last; + # } + + location ~* \.(jpe?g|gif|png|bmp|ico|pdf|zip|htm|html|docx?|xlsx?|pptx?|txt|wav|swf|avi|mp\d)$ { + access_log off; + log_not_found off; + try_files $uri $uri/ $document_root$uri /index.php?$args; + expires 1w; + } + + location ~ /\. { + access_log denied; + log_not_found off; + deny all; + } } \ No newline at end of file diff --git a/_docker/nginx/nginx.conf b/_docker/nginx/nginx.conf index f47cdf2..569375b 100644 --- a/_docker/nginx/nginx.conf +++ b/_docker/nginx/nginx.conf @@ -1,27 +1,60 @@ - user nginx; - - worker_processes 1; - - error_log /var/log/nginx/error.log warn; - pid /var/run/nginx.pid; - - events { - worker_connections 1024; - } - - http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - - keepalive_timeout 65; - - include /etc/nginx/conf.d/*.conf; + user nginx; + + worker_processes auto; + + error_log /var/log/nginx/error.log warn; + pid /var/run/nginx.pid; + + events { + worker_connections 1024; + } + + http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main buffer=16k; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + + # Timeout limit values + client_body_timeout 10; + client_header_timeout 10; + keepalive_timeout 13; + send_timeout 10; + + # Buffer size + client_body_buffer_size 80k; + client_max_body_size 9m; + client_header_buffer_size 1k; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 5; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + # config from simrs + # client_max_body_size 1500M; + # client_body_buffer_size 64M; + # keepalive_timeout 900; + + include /etc/nginx/conf.d/*.conf; + + # File Cache Opening + open_file_cache max=1024 inactive=10s; + open_file_cache_valid 60s; + open_file_cache_min_uses 2; + open_file_cache_errors on; + + #footer } \ No newline at end of file diff --git a/_docker/php-fpm/opcache.ini b/_docker/php-fpm/opcache.ini index 6eba8b2..6738084 100644 --- a/_docker/php-fpm/opcache.ini +++ b/_docker/php-fpm/opcache.ini @@ -1,9 +1,9 @@ -[opcache] -opcache.enable=1 -opcache.revalidate_freq=0 -opcache.validate_timestamps=0 -opcache.max_accelerated_files=10000 -opcache.memory_consumption=192 -opcache.max_wasted_percentage=10 -opcache.interned_strings_buffer=16 +[opcache] +opcache.enable=1 +opcache.revalidate_freq=0 +opcache.validate_timestamps=0 +opcache.max_accelerated_files=10000 +opcache.memory_consumption=192 +opcache.max_wasted_percentage=10 +opcache.interned_strings_buffer=16 opcache.fast_shutdown=1 \ No newline at end of file diff --git a/_docker/php-fpm/www.conf b/_docker/php-fpm/www.conf index a7919df..6f8cf91 100644 --- a/_docker/php-fpm/www.conf +++ b/_docker/php-fpm/www.conf @@ -1,15 +1,16 @@ -[global] -daemonize=no - -[www] -user=www-data -group=www-data - -listen=127.0.0.1:9000 - -pm=dynamic -pm.max_children=40 -pm.start_servers=2 -pm.min_spare_servers=2 -pm.max_spare_servers=4 +[global] +daemonize=no + +[www] +user=www-data +group=www-data + +listen=/run/php-fpm.sock +listen.mode = 0666 + +pm=dynamic +pm.max_children=40 +pm.start_servers=4 +pm.min_spare_servers=4 +pm.max_spare_servers=40 pm.max_requests=500 \ No newline at end of file diff --git a/_docker/supervisord/supervisord.conf b/_docker/supervisord/supervisord.conf index fbde2cf..e435765 100644 --- a/_docker/supervisord/supervisord.conf +++ b/_docker/supervisord/supervisord.conf @@ -1,9 +1,15 @@ -[program:php-fpm] -command=/usr/local/sbin/php-fpm - -[program:nginx] -command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;" - -[supervisord] -logfile=/var/log/supervisord.log -nodaemon=true \ No newline at end of file +[program:php-fpm] +command=/usr/local/sbin/php-fpm +startsecs = 1 +autorestart=true +process_name=php-fpm + +[program:nginx] +command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;" +startsecs = 1 +autorestart=true +process_name=nginx + +[supervisord] +logfile=/var/log/supervisord.log +nodaemon=true diff --git a/docker-compose.yml b/docker-compose.yml index eaaa7e0..fb3b480 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,5 @@ version: '3.8' -# services: -# web: -# build: . -# container_name: ${HOST} -# restart: unless-stopped -# networks: -# - proxy -# volumes: -# - ./src:/app services: app: build: . @@ -16,13 +7,7 @@ services: restart: always volumes: - ./src:/app - - ./media:/app/media - # environment: - # - "APP_PORT=8080" ports: - "8061:80" -# networks: -# - bridge2 -# networks: -# bridge2: -# external: true \ No newline at end of file + environment: + - APP_ENV=dev diff --git a/docker-push.sh b/docker-push.sh new file mode 100755 index 0000000..c977f40 --- /dev/null +++ b/docker-push.sh @@ -0,0 +1,28 @@ +!/bin/bash + +#get image name +remote_url=$(git remote get-url origin) +image=$(echo $remote_url | sed 's|https://||g; s|.git||g') + +#get branch name +branch_name=$(git rev-parse --abbrev-ref HEAD) +clean_branch_name=${branch_name##*/} + +#get timestamp for the tag +timestamp=$(date +%Y%m%d%H%M%S) + +app_version=$clean_branch_name-$timestamp +tag=$image:$timestamp-$clean_branch_name +latest=$image:latest-$clean_branch_name + +#build image +docker build --build-arg APP_VERSION=$app_version -t $tag . +docker tag $tag $latest + +#push to dockerhub +docker login git.rssa.top -u stim -p 2ad87eeef27b3ac1acd58271fdc1b4af934d180c +docker push $tag +docker push $latest + +#remove dangling images +docker system prune -f diff --git a/src/supervisord.pid b/src/supervisord.pid deleted file mode 100644 index d00491f..0000000 --- a/src/supervisord.pid +++ /dev/null @@ -1 +0,0 @@ -1