From 5aafe76222e7881292de8fa6218bb8ea01f3be0a Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 21 Jun 2022 10:04:42 +0200 Subject: [PATCH] Add checking if the project is based on Laravel --- Dockerfile | 25 ++++++++++------- README.md | 33 ++++++++++++++-------- build.sh | 3 +- entrypoint.sh | 77 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 94 insertions(+), 44 deletions(-) mode change 100644 => 100755 build.sh diff --git a/Dockerfile b/Dockerfile index 78fdd6f..bc24e2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -31,7 +31,12 @@ RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\ && phpize \ && ./configure \ && make all -j 5 \ - && make install + && 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 @@ -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" ] diff --git a/README.md b/README.md index 5df262a..00942cd 100644 --- a/README.md +++ b/README.md @@ -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: or latest + image: jkaninda/laravel-php-fpm: 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: or latest + image: jkaninda/laravel-php-fpm container_name: php-fpm - restart: unless-stopped + 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: + + diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 106b73e..9ea5138 --- a/build.sh +++ b/build.sh @@ -6,4 +6,5 @@ if [ $# -eq 0 ] tag=$1 fi -docker build -t jkaninda/laravel-php-fpm:$tag . \ No newline at end of file +#docker build -t jkaninda/laravel-php-fpm:$tag . +docker build -t jkaninda/php-fpm:$tag . diff --git a/entrypoint.sh b/entrypoint.sh index b33efe8..4b3e8e0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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" < "$TASK" <