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

View File

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

View File

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

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

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

View File

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

View File

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

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
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}
#zend_extension=opcache.so