Refactoring

This commit is contained in:
2023-01-04 18:04:25 +02:00
parent a8d5124256
commit d25ff2068d
8 changed files with 355 additions and 34 deletions

View File

@@ -1,33 +1,15 @@
name: ci
name: Build
on:
push:
branches:
- '**'
pull_request:
types:
- closed
branches:
- '**'
- develop
env:
#BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
BUILDKIT_IMAGE: jkaninda/nginx-php-fpm
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set environment for branch
run: |
set -x
if [[ $GITHUB_REF == 'refs/heads/main' ]]; then
echo "TAG_NAME=latest" >> "$GITHUB_ENV"
echo "runs-on: main branch"
else
echo "TAG_NAME=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_ENV"
echo "runs-on: ${{ github.head_ref || github.ref_name }} branch"
fi
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
@@ -41,8 +23,32 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
name: Build and push 7.4
uses: docker/build-push-action@v3
with:
file: "./docker/7.4/Dockerfile"
push: true
tags: "${{env.BUILDKIT_IMAGE}}:${{env.TAG_NAME}}"
tags: "${{env.BUILDKIT_IMAGE}}:7.4"
-
name: Build and push 8.0
uses: docker/build-push-action@v3
with:
file: "./docker/8.0/Dockerfile"
push: true
tags: "${{env.BUILDKIT_IMAGE}}:8.0"
-
name: Build and push 8.1
uses: docker/build-push-action@v3
with:
file: "./docker/8.1/Dockerfile"
push: true
tags: "${{env.BUILDKIT_IMAGE}}:8.1"
-
name: Build and push 8.2
uses: docker/build-push-action@v3
with:
file: "./docker/8.2/Dockerfile"
push: true
tags: |
"${{env.BUILDKIT_IMAGE}}:8.2"
"${{env.BUILDKIT_IMAGE}}:latest"

View File

@@ -1,5 +1,4 @@
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/jkaninda/nginx-php-fpm?style=flat-square)
![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/jkaninda/nginx-php-fpm?style=flat-square)
[![Build](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml/badge.svg)](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/nginx-php-fpm?style=flat-square)
![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/nginx-php-fpm?style=flat-square)
@@ -90,6 +89,27 @@ services:
docker-compose up -d
```
## Build from base
Dockerfile
```Dockerfile
FROM jkaninda/nginx-php-fpm:8.1
# Copy laravel project files
COPY . /var/www/html
# Storage Volume
VOLUME /var/www/html/storage
WORKDIR /var/www/html
# Custom cache invalidation
ARG CACHEBUST=1
RUN composer install
RUN chown -R www-data:www-data /var/www/html/storage
RUN chown -R www-data:www-data /var/www/html/bootstrap/cache
```
## Nginx custom config:
### Enable custom nginx config files
> /var/www/html/conf/nginx/nginx.conf

View File

@@ -1,9 +1,16 @@
#!/usr/bin/env bash
#!/bin/bash
if [ $# -eq 0 ]
then
tag='latest'
else
tag=$1
fi
if [ $tag != 'latest' ]
then
echo 'Build from tag'
docker build -f docker/${tag}/Dockerfile -t jkaninda/nginx-php-fpm:$tag .
else
echo 'Build latest'
docker build -f docker/8.2/Dockerfile -t jkaninda/nginx-php-fpm:$tag .
docker build -t jkaninda/nginx-php-fpm:$tag .
fi

87
docker/7.4/Dockerfile Normal file
View File

@@ -0,0 +1,87 @@
FROM php:7.4-fpm
ARG WORKDIR=/var/www/html
ENV DOCUMENT_ROOT=${WORKDIR}
ENV LARAVEL_PROCS_NUMBER=1
ENV DOMAIN=_
ENV CLIENT_MAX_BODY_SIZE=15M
ENV NODE_VERSION=17.x
ARG HOST_UID=1000
ENV USER=www-data
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmemcached-dev \
libzip-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
librdkafka-dev \
libpq-dev \
openssh-server \
zip \
unzip \
supervisor \
sqlite3 \
nano \
cron
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
# Install Node
RUN apt-get install -y nodejs
# Install nginx
RUN apt-get update && apt-get install -y nginx
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions zip, mbstring, exif, bcmath, intl
RUN docker-php-ext-configure gd
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 the php memcached extension
RUN pecl install memcached && docker-php-ext-enable memcached
# Install the PHP pdo_mysql extention
RUN docker-php-ext-install pdo_mysql
# Install the PHP pdo_pgsql extention
RUN docker-php-ext-install pdo_pgsql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR $WORKDIR
RUN rm -Rf /var/www/* && \
mkdir -p /var/www/html
ADD src/index.php $WORKDIR/index.php
ADD src/conf/nginx/default.conf /etc/nginx/sites-available/default
ADD src/php.ini $PHP_INI_DIR/conf.d/
ADD src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN ln -s /usr/local/bin/entrypoint.sh /
ENTRYPOINT ["entrypoint.sh"]
RUN usermod -u ${HOST_UID} www-data
RUN groupmod -g ${HOST_UID} www-data
RUN chmod -R 755 $WORKDIR
RUN chown -R www-data:www-data $WORKDIR
EXPOSE 9000 80
CMD [ "entrypoint" ]

View File

@@ -1,10 +1,12 @@
FROM php:8.1.11-fpm
FROM php:8.0-fpm
ARG WORKDIR=/var/www/html
ENV DOCUMENT_ROOT=${WORKDIR}
ENV LARAVEL_PROCS_NUMBER=1
ENV DOMAIN=_
ENV CLIENT_MAX_BODY_SIZE=15M
ENV NODE_VERSION=16.x
ENV NODE_VERSION=17.x
ARG HOST_UID=1000
ENV USER=www-data
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
@@ -88,11 +90,10 @@ ENTRYPOINT ["entrypoint.sh"]
RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data
RUN usermod -u ${HOST_UID} www-data
RUN groupmod -g ${HOST_UID} www-data
RUN chmod -R 755 $WORKDIR
RUN chown -R www-data:www-data $WORKDIR
EXPOSE 9000 80
CMD [ "entrypoint" ]

100
docker/8.1/Dockerfile Normal file
View File

@@ -0,0 +1,100 @@
FROM php:8.1.13-fpm
ARG WORKDIR=/var/www/html
ENV DOCUMENT_ROOT=${WORKDIR}
ENV LARAVEL_PROCS_NUMBER=1
ENV DOMAIN=_
ENV CLIENT_MAX_BODY_SIZE=15M
ENV NODE_VERSION=17.x
ARG HOST_UID=1000
ENV USER=www-data
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmemcached-dev \
libzip-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
librdkafka-dev \
libpq-dev \
openssh-server \
zip \
unzip \
supervisor \
sqlite3 \
nano \
cron
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
# Install Node
RUN apt-get install -y nodejs
# Install nginx
RUN apt-get update && apt-get install -y nginx
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Kafka
RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\
&& cd php-rdkafka \
&& phpize \
&& ./configure \
&& 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
# Install Redis and enable it
RUN pecl install redis && docker-php-ext-enable redis
# Install the php memcached extension
RUN pecl install memcached && docker-php-ext-enable memcached
# Install the PHP pdo_mysql extention
RUN docker-php-ext-install pdo_mysql
# Install the PHP pdo_pgsql extention
RUN docker-php-ext-install pdo_pgsql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR $WORKDIR
RUN rm -Rf /var/www/* && \
mkdir -p /var/www/html
ADD src/index.php $WORKDIR/index.php
ADD src/conf/nginx/default.conf /etc/nginx/sites-available/default
ADD src/php.ini $PHP_INI_DIR/conf.d/
ADD src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN ln -s /usr/local/bin/entrypoint.sh /
ENTRYPOINT ["entrypoint.sh"]
RUN usermod -u ${HOST_UID} www-data
RUN groupmod -g ${HOST_UID} www-data
RUN chmod -R 755 $WORKDIR
RUN chown -R www-data:www-data $WORKDIR
EXPOSE 80
CMD [ "entrypoint" ]

100
docker/8.2/Dockerfile Normal file
View File

@@ -0,0 +1,100 @@
FROM php:8.2.0-fpm
ARG WORKDIR=/var/www/html
ENV DOCUMENT_ROOT=${WORKDIR}
ENV LARAVEL_PROCS_NUMBER=1
ENV DOMAIN=_
ENV CLIENT_MAX_BODY_SIZE=15M
ENV NODE_VERSION=17.x
ARG HOST_UID=1000
ENV USER=www-data
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmemcached-dev \
libzip-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
librdkafka-dev \
libpq-dev \
openssh-server \
zip \
unzip \
supervisor \
sqlite3 \
nano \
cron
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
# Install Node
RUN apt-get install -y nodejs
# Install nginx
RUN apt-get update && apt-get install -y nginx
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Kafka
RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\
&& cd php-rdkafka \
&& phpize \
&& ./configure \
&& 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
# Install Redis and enable it
RUN pecl install redis && docker-php-ext-enable redis
# Install the php memcached extension
RUN pecl install memcached && docker-php-ext-enable memcached
# Install the PHP pdo_mysql extention
RUN docker-php-ext-install pdo_mysql
# Install the PHP pdo_pgsql extention
RUN docker-php-ext-install pdo_pgsql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR $WORKDIR
RUN rm -Rf /var/www/* && \
mkdir -p /var/www/html
ADD src/index.php $WORKDIR/index.php
ADD src/conf/nginx/default.conf /etc/nginx/sites-available/default
ADD src/php.ini $PHP_INI_DIR/conf.d/
ADD src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN ln -s /usr/local/bin/entrypoint.sh /
ENTRYPOINT ["entrypoint.sh"]
RUN usermod -u ${HOST_UID} www-data
RUN groupmod -g ${HOST_UID} www-data
RUN chmod -R 755 $WORKDIR
RUN chown -R www-data:www-data $WORKDIR
EXPOSE 80
CMD [ "entrypoint" ]

View File

@@ -26,7 +26,7 @@ if [ -f /var/www/html/artisan ]; then
autostart=true
autorestart=true
numprocs=1
user=root
user=www-data
stdout_logfile=/var/log/laravel_scheduler.out.log
redirect_stderr=true
@@ -36,7 +36,7 @@ if [ -f /var/www/html/artisan ]; then
autostart=true
autorestart=true
numprocs=$LARAVEL_PROCS_NUMBER
user=root
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log
EOF