Add checking if the project is based on Laravel

This commit is contained in:
2022-06-21 10:04:42 +02:00
parent 8bf3e8fc29
commit 5aafe76222
4 changed files with 94 additions and 44 deletions

View File

@@ -1,4 +1,4 @@
FROM php:8.1-fpm
FROM php:8.1.0-fpm
ENV WORKDIR=/var/www
ENV STORAGE_DIR=/var/www/storage
# Install system dependencies
@@ -33,6 +33,11 @@ RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\
&& make all -j 5 \
&& make install
# Install Rdkafka and enable it
RUN docker-php-ext-enable rdkafka \
&& cd .. \
&& rm -rf /php-rdkafka
# Install PHP extensions zip, mbstring, exif, bcmath, intl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl
@@ -40,9 +45,7 @@ RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl
# Install Redis and enable it
RUN pecl install redis && docker-php-ext-enable redis
# Install Rdkafka and enable it
RUN docker-php-ext-enable rdkafka \
&& rm -rf /php-rdkafka
# Install the php memcached extension
RUN pecl install memcached && docker-php-ext-enable memcached
@@ -61,7 +64,8 @@ COPY php.ini $PHP_INI_DIR/conf.d/
# Install Laravel Envoy
RUN composer global require "laravel/envoy=~1.0"
# Set working directory
WORKDIR $WORKDIR
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
@@ -69,13 +73,14 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
ENTRYPOINT ["entrypoint.sh"]
# Set working directory
WORKDIR $WORKDIR
RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data
RUN chmod 755 $WORKDIR
EXPOSE 9000
# Run Supervisor
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# entrypoint
CMD [ "entrypoint" ]

View File

@@ -1,3 +1,8 @@
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/jkaninda/laravel-php-fpm?style=flat-square)
![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/jkaninda/laravel-php-fpm?style=flat-square)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/laravel-php-fpm?style=flat-square)
![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/laravel-php-fpm?style=flat-square)
# Laravel PHP-FPM Docker image
> 🐳 Docker image for a PHP-FPM container crafted to run Laravel or any php based applications.
@@ -30,7 +35,7 @@
version: '3'
services:
php-fpm:
image: jkaninda/laravel-php-fpm:<Tagname> or latest
image: jkaninda/laravel-php-fpm:<tagname> or latest
container_name: php-fpm
restart: unless-stopped
volumes:
@@ -44,13 +49,13 @@ services:
```
## Laravel `artisan` command usage:
### Open php-fpm
```bash
```sh
docker-compose exec php-fpm /bin/bash
```
### Laravel migration
```bash
```sh
php atisan migrate
```
@@ -60,14 +65,17 @@ php atisan migrate
version: '3'
services:
php-fpm:
image: jkaninda/laravel-php-fpm:<Tagname> or latest
image: jkaninda/laravel-php-fpm
container_name: php-fpm
working_dir: /var/www #Optional If you want to use a custom directory
restart: unless-stopped
volumes:
#Project root
- ./:/var/www/
- ~/.ssh:/root/.ssh # If you use private CVS
environment:
- APP_ENV=development # or production
- WORKDIR=/var/www #Optional If you want to use a custom directory
networks:
- default #if you're using networks between containers
#Nginx server
@@ -79,13 +87,13 @@ services:
- 80:80
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
- ./default.conf:/etc/nginx/conf.d/default.conf
networks:
- default
```
## Simple Nginx config file content
### nginx/conf.d/default.conf
### default.conf
```conf
@@ -94,12 +102,12 @@ server {
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
##Root directory
##Public directory
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## PHP FPM ( php-fpm:9000 )
## PHP FPM ( php-fpm:9000 ) or [servicename:9000]
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
@@ -123,8 +131,11 @@ server {
```
## Docker run
```bash
```sh
docker-compose up -d
```
> P.S. please give a star if you like it :wink:

3
build.sh Normal file → Executable file
View File

@@ -6,4 +6,5 @@ if [ $# -eq 0 ]
tag=$1
fi
docker build -t jkaninda/laravel-php-fpm:$tag .
#docker build -t jkaninda/laravel-php-fpm:$tag .
docker build -t jkaninda/php-fpm:$tag .

View File

@@ -1,11 +1,15 @@
#!/bin/sh
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
echo ""
echo "***********************************************************"
echo " Starting LARAVEL PHP-FPM Docker Container "
echo " Starting LARAVEL PHP-FPM Docker Container "
echo "***********************************************************"
set -e
## Create PHP-FPM worker process
TASK=/etc/supervisor/conf.d/worker.conf
touch $TASK
cat > "$TASK" <<EOF
@@ -22,28 +26,57 @@ stderr_logfile=/var/log/php-fpm_consumer.err.log
stdout_logfile=/var/log/php-fpm_consumer.out.log
user=root
priority=100
[program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/bin/sh -c "while [ true ]; do (php /var/www/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
autostart=true
autorestart=true
numprocs=1
user=root
stdout_logfile=/var/log/laravel_scheduler.out.log
redirect_stderr=true
[program:Laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=2
user=root
redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log
EOF
## Check if the artisan file exists
if [ -f $WORKDIR/artisan ]; then
echo "${Green} artisan file found, creating laravel supervisor config"
##Create Laravel Scheduler process
TASK=/etc/supervisor/conf.d/laravel-worker.conf
touch $TASK
cat > "$TASK" <<EOF
[supervisord]
nodaemon=true
user=root
[program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/bin/sh -c "while [ true ]; do (php $WORKDIR/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
autostart=true
autorestart=true
numprocs=1
user=root
stdout_logfile=/var/log/laravel_scheduler.out.log
redirect_stderr=true
[program:Laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php $WORKDIR/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=2
user=root
redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log
EOF
echo "${Green} Laravel supervisor config created"
else
echo "${Red} artisan file not found"
fi
#check if storage directory exists
echo "Checking if storage directory exists"
if [ -d "$STORAGE_DIR" ]; then
echo "Directory $STORAGE_DIR exist. Fixing permissions..."
chown -R www-data:www-data $STORAGE_DIR
chmod -R 775 $STORAGE_DIR
echo "${Green} Permissions fixed"
else
echo "${Red} Directory $STORAGE_DIR does not exist"
echo "Fixing permissions from $WORKDIR"
chown -R www-data:www-data $WORKDIR/storage
chmod -R 775 $WORKDIR/storage
echo "${Green} Permissions fixed"
fi
supervisord -c /etc/supervisor/supervisord.conf