Docker - Smooth installation conditions

This commit is contained in:
Fatih Alp 2023-05-07 19:21:55 +03:00
parent bbf3877959
commit 1d1d08ea07
8 changed files with 58 additions and 67 deletions

View File

@ -7,9 +7,9 @@ DEBUG_BAR=false
DB_CONNECTION=mysql DB_CONNECTION=mysql
#DB_HOST=mysql #DB_HOST=mysql
DB_HOST=hostdocker.internal DB_HOST=hostdocker.internal
DB_DATABASE=oopenclassify DB_DATABASE=oc
DB_USERNAME=root DB_USERNAME=oc
DB_PASSWORD= DB_PASSWORD=oc
APPLICATION_NAME=Default APPLICATION_NAME=Default
APPLICATION_REFERENCE=default APPLICATION_REFERENCE=default
APPLICATION_DOMAIN=http://localhost APPLICATION_DOMAIN=http://localhost

View File

@ -1,4 +1,5 @@
#docker compose build --no-cache && docker compose up --force-recreate -d #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 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_VALIDATE_TIMESTAMPS=1
ENV PHP_OPCACHE_REVALIDATE_FREQ=1 ENV PHP_OPCACHE_REVALIDATE_FREQ=1
RUN usermod -u 1000 www-data RUN usermod -u 1000 www-data
RUN apt-get update -y RUN apt-get update -y
RUN apt-get install -y unzip libpq-dev libcurl4-gnutls-dev nginx 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 \ RUN docker-php-ext-enable opcache
# && rm -rf /tmp/pear \
# && docker-php-ext-enable redis
WORKDIR /var/www 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.ini /usr/local/etc/php/php.ini
COPY ./docker/php/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf COPY ./docker/php/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
COPY ./docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf COPY ./docker/nginx/site.conf /etc/nginx/default.conf
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV PORT=8000 RUN chmod -R 755 /var/www/storage
ENTRYPOINT [ "docker/entrypoint.sh" ] RUN chmod -R 755 /var/www/bootstrap
# ============================================================================== #ENTRYPOINT [ "docker/entrypoint.sh" ]
# node
# FROM node:14-alpine as node
# WORKDIR /var/www CMD ["docker/entrypoint.sh","php-fpm","-F"]
# COPY . .
#RUN npm install --global cross-env
#RUN npm install
#VOLUME /var/www/node_modules

View File

@ -2,6 +2,7 @@ version: '3'
networks: networks:
webapp: webapp:
driver: bridge
services: services:
nginx: nginx:
@ -12,7 +13,7 @@ services:
links: links:
- php - php
volumes: volumes:
- ./:/var/www/html - ./:/var/www
- ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf:rw - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf:rw
- ./docker/logs/nginx:/var/logs/nginx:rw - ./docker/logs/nginx:/var/logs/nginx:rw
depends_on: depends_on:
@ -28,14 +29,21 @@ services:
environment: environment:
- CONTAINER_ROLE=app - CONTAINER_ROLE=app
volumes: volumes:
- ./:/var/www/html - ./:/var/www
ports: ports:
- "9001:9000" - "9001:9000"
networks: networks:
- webapp - webapp
links:
- database
depends_on:
database:
condition: service_healthy
# Database Server # Database Server
database: database:
image: mysql:8.0 image: mysql:8.0
container_name: database
ports: ports:
- 3306:3306 - 3306:3306
command: --max_allowed_packet=32505856 # Set max_allowed_packet to 256M (or any other value) command: --max_allowed_packet=32505856 # Set max_allowed_packet to 256M (or any other value)
@ -44,8 +52,13 @@ services:
- MYSQL_USER=oc - MYSQL_USER=oc
- MYSQL_PASSWORD=oc - MYSQL_PASSWORD=oc
- MYSQL_ROOT_PASSWORD=oc - MYSQL_ROOT_PASSWORD=oc
- DB_HOST=host.docker.internal
volumes: volumes:
- db-data:/var/lib/mysql - db-data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 5s
retries: 10
volumes: volumes:
db-data: ~ db-data: ~

19
docker/entrypoint.sh Normal file → Executable file
View File

@ -1,25 +1,35 @@
#!/bin/bash #!/bin/bash
echo "$APP_ENV"
if [ ! -f "vendor/autoload.php" ]; then if [ ! -f "vendor/autoload.php" ]; then
composer install --no-progress --no-interaction composer install --no-progress --no-interaction
else
echo " nothing to do."
fi fi
if [ ! -f ".env" ]; then 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 cp .env-sail .env
else else
echo "env file exists." echo "env file exists. nothing to do."
fi fi
# TODO make role based @fatihalp # TODO make role based @fatihalp
role=${CONTAINER_ROLE:-app} role=${CONTAINER_ROLE:-app}
if [ "$role" = "app" ]; then if [ "$role" = "app" ]; then
php artisan install --ready #INSTALLED=$(. ./.env; printf '%s' "$INSTALLED")
php artisan key:generate if [ "$INSTALLED" = "false" ]; then
echo ".env installed is false starting installing"
composer update
php artisan install --ready
fi
php artisan cache:clear php artisan cache:clear
php artisan config:clear php artisan config:clear
php artisan route:clear php artisan route:clear
chmod -R 777 /var/www/storage
chmod -R 777 /var/www/bootstrap
exec docker-php-entrypoint "$@" exec docker-php-entrypoint "$@"
elif [ "$role" = "queue" ]; then elif [ "$role" = "queue" ]; then
echo "Running the queue ... " echo "Running the queue ... "
@ -28,4 +38,3 @@ elif [ "$role" = "websocket" ]; then
echo "Running the websocket server ... " echo "Running the websocket server ... "
php artisan websockets:serve php artisan websockets:serve
fi fi

View File

@ -17,29 +17,4 @@ http {
upstream php-fpm { upstream php-fpm {
server php:9000; 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;
}
}
} }

View File

@ -4,7 +4,7 @@ server {
server_name localhost; server_name localhost;
error_log /var/log/nginx/error.log; error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log; access_log /var/log/nginx/access.log;
root /var/www/html/public; root /var/www/public;
client_max_body_size 100M; client_max_body_size 100M;
fastcgi_read_timeout 1800; fastcgi_read_timeout 1800;

11
docker/php/opcache.ini Normal file
View File

@ -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

View File

@ -1,6 +1 @@
zend_extension=opcache.so #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}