diff --git a/.env-sail b/.env-sail index 8a047b79a..442fa0764 100644 --- a/.env-sail +++ b/.env-sail @@ -7,9 +7,9 @@ DEBUG_BAR=false DB_CONNECTION=mysql #DB_HOST=mysql DB_HOST=hostdocker.internal -DB_DATABASE=oopenclassify -DB_USERNAME=root -DB_PASSWORD= +DB_DATABASE=oc +DB_USERNAME=oc +DB_PASSWORD=oc APPLICATION_NAME=Default APPLICATION_REFERENCE=default APPLICATION_DOMAIN=http://localhost diff --git a/Dockerfile b/Dockerfile index 75e923131..ae5ad7afe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ #docker compose build --no-cache && docker compose up --force-recreate -d +#docker compose down -v && docker compose up --build FROM php:7.4-fpm as php @@ -7,42 +8,29 @@ ENV PHP_OPCACHE_ENABLE_CLI=1 ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 ENV PHP_OPCACHE_REVALIDATE_FREQ=1 - - RUN usermod -u 1000 www-data RUN apt-get update -y RUN apt-get install -y unzip libpq-dev libcurl4-gnutls-dev nginx -RUN docker-php-ext-install pdo pdo_mysql bcmath +RUN docker-php-ext-install pdo pdo_mysql bcmath curl opcache -#RUN pecl install -o -f redis \ -# && rm -rf /tmp/pear \ -# && docker-php-ext-enable redis +RUN docker-php-ext-enable opcache WORKDIR /var/www -COPY --chown=www-data . . + +COPY --chown=www-data:www-data . . COPY ./docker/php/php.ini /usr/local/etc/php/php.ini COPY ./docker/php/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf - -COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf +COPY ./docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini +COPY ./docker/nginx/site.conf /etc/nginx/default.conf COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -ENV PORT=8000 -ENTRYPOINT [ "docker/entrypoint.sh" ] +RUN chmod -R 755 /var/www/storage +RUN chmod -R 755 /var/www/bootstrap -# ============================================================================== -# node -# FROM node:14-alpine as node +#ENTRYPOINT [ "docker/entrypoint.sh" ] -# WORKDIR /var/www - - -# COPY . . - -#RUN npm install --global cross-env -#RUN npm install - -#VOLUME /var/www/node_modules +CMD ["docker/entrypoint.sh","php-fpm","-F"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d1a464b3f..025afd405 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: '3' networks: webapp: + driver: bridge services: nginx: @@ -12,7 +13,7 @@ services: links: - php volumes: - - ./:/var/www/html + - ./:/var/www - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf:rw - ./docker/logs/nginx:/var/logs/nginx:rw depends_on: @@ -28,14 +29,21 @@ services: environment: - CONTAINER_ROLE=app volumes: - - ./:/var/www/html + - ./:/var/www ports: - "9001:9000" networks: - webapp + links: + - database + depends_on: + database: + condition: service_healthy + # Database Server database: image: mysql:8.0 + container_name: database ports: - 3306:3306 command: --max_allowed_packet=32505856 # Set max_allowed_packet to 256M (or any other value) @@ -44,8 +52,13 @@ services: - MYSQL_USER=oc - MYSQL_PASSWORD=oc - MYSQL_ROOT_PASSWORD=oc + - DB_HOST=host.docker.internal volumes: - db-data:/var/lib/mysql + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 5s + retries: 10 volumes: db-data: ~ \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh old mode 100644 new mode 100755 index 5363547e3..15a04953f --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,25 +1,35 @@ #!/bin/bash +echo "$APP_ENV" + if [ ! -f "vendor/autoload.php" ]; then composer install --no-progress --no-interaction +else + echo " nothing to do." fi if [ ! -f ".env" ]; then - echo "Creating env file for env $APP_ENV" + echo "Creating env file for env $APP_ENV from env-sail" cp .env-sail .env else - echo "env file exists." + echo "env file exists. nothing to do." fi # TODO make role based @fatihalp role=${CONTAINER_ROLE:-app} if [ "$role" = "app" ]; then - php artisan install --ready - php artisan key:generate + #INSTALLED=$(. ./.env; printf '%s' "$INSTALLED") + if [ "$INSTALLED" = "false" ]; then + echo ".env installed is false starting installing" + composer update + php artisan install --ready + fi php artisan cache:clear php artisan config:clear php artisan route:clear + chmod -R 777 /var/www/storage + chmod -R 777 /var/www/bootstrap exec docker-php-entrypoint "$@" elif [ "$role" = "queue" ]; then echo "Running the queue ... " @@ -27,5 +37,4 @@ elif [ "$role" = "queue" ]; then elif [ "$role" = "websocket" ]; then echo "Running the websocket server ... " php artisan websockets:serve -fi - +fi \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 9521b16aa..9e084633e 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -17,29 +17,4 @@ http { upstream php-fpm { server php:9000; } - - server { - listen 8000; - server_name example.com; - - root /var/www/public; - index index.php; - - error_log /var/log/nginx/error.log; - access_log /var/log/nginx/access.log; - - include /etc/nginx/mime.types; - - location / { - try_files $uri $uri/ /index.php?$query_string; - } - - location ~ \.php$ { - fastcgi_pass php-fpm; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SCRIPT_NAME $fastcgi_script_name; - include fastcgi_params; - } - } -} \ No newline at end of file +} \ No newline at end of file diff --git a/docker/nginx/site.conf b/docker/nginx/site.conf index 5000f032f..056260844 100644 --- a/docker/nginx/site.conf +++ b/docker/nginx/site.conf @@ -4,7 +4,7 @@ server { server_name localhost; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; - root /var/www/html/public; + root /var/www/public; client_max_body_size 100M; fastcgi_read_timeout 1800; diff --git a/docker/php/opcache.ini b/docker/php/opcache.ini new file mode 100644 index 000000000..fc9ed4d15 --- /dev/null +++ b/docker/php/opcache.ini @@ -0,0 +1,11 @@ +[opcache] +opcache.enable=1 +; 0 means it will check on every request +; 0 is irrelevant if opcache.validate_timestamps=0 which is desirable in production +opcache.revalidate_freq=0 +opcache.validate_timestamps=1 +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/php.ini b/docker/php/php.ini index 626b13ca6..aef30aa2f 100644 --- a/docker/php/php.ini +++ b/docker/php/php.ini @@ -1,6 +1 @@ -zend_extension=opcache.so - -opcache.enable=${PHP_OPCACHE_ENABLE} -opcache.enable_cli=${PHP_OPCACHE_ENABLE_CLI} -opcache.validate_timestamp=${PHP_OPCACHE_VALIDATE_TIMESTAMPS} -opcache.revalidate_freq=${PHP_OPCACHE_REVALIDATE_FREQ} \ No newline at end of file +#zend_extension=opcache.so \ No newline at end of file