Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Chore) docker installation method for fresns #22

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ composer.lock
/config/markets.php
/extensions/*
fresns-dev.json

# Docker
!docker/volumes/redis
docker/volumes/redis/*
!docker/volumes/redis/.gitkeep
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM php:8.2-fpm as Api

ADD ./docker/services/php/www.conf /usr/local/etc/php-fpm.d/www.conf

ARG USER_ID=1000
RUN usermod -u $USER_ID www-data
RUN usermod -G staff www-data

RUN mkdir -p /var/www/html

ADD . /var/www/html

RUN chmod -R 775 /var/www/html/storage
RUN chmod -R 775 /var/www/html/bootstrap/cache

# Install PHP extensions
RUN apt-get update && apt-get install -y \
build-essential \
curl \
libzip-dev \
libpq-dev \
git \
jpegoptim optipng pngquant gifsicle \
locales \
unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Graphics Draw
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd

# Multibyte String
RUN apt-get update && apt-get install -y libonig-dev && docker-php-ext-install mbstring

# Miscellaneous
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install exif
RUN docker-php-ext-install zip
RUN docker-php-ext-install -j$(nproc) fileinfo opcache
RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql

# Enable PHP extensions
RUN docker-php-ext-enable bcmath pdo_pgsql pdo_mysql zip


RUN chown -R . /var/www/html

# Install Composer dependencies
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --no-dev --optimize-autoloader

# Install Cron
RUN apt-get update && apt-get install -y cron
RUN echo "* * * * * root php /var/www/html/artisan schedule:run >> /var/log/cron.log 2>&1" >> /etc/crontab
RUN touch /var/log/cron.log

CMD bash -c "cron && php-fpm"
37 changes: 37 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.9'

services:
fresns.postgres:
container_name: fs.database
image: postgres:latest
restart: always
ports:
- '${FORWARD_DB_PORT:-6432}:5432'
environment:
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD}'
volumes:
- 'fresns-postgres:/var/lib/postgresql/data'
networks:
- fresns
healthcheck:
test: [
"CMD",
"pg_isready",
"-q",
"-d",
"${DB_DATABASE}",
"-U",
"${DB_USERNAME}"
]
retries: 3
timeout: 5s

networks:
fresns:
driver: bridge

volumes:
fresns-postgres:
driver: local
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: "3.9"

services:

fresns.nginx:
build:
context: ./docker
dockerfile: nginx.dockerfile
depends_on:
- fresns.php
- fresns.postgres
- fresns.redis
environment:
DB_HOST: fresns.postgres
REDIS_HOST: fresns.redis
container_name: fs.nginx
ports:
- '${APP_PORT:-80}:80'
- '${APP_PORT:-443}:443'
volumes:
- ./:/var/www/html
networks:
- fresns

fresns.php:
build:
context: .
dockerfile: Dockerfile
container_name: fs.php
volumes:
- ./:/var/www/html
networks:
- fresns

fresns.redis:
image: 'redis:7.0'
container_name: fs.cache
volumes:
- ./docker/volumes/redis:/data
ports:
- '${FORWARD_REDIS_PORT:-6380}:6379'
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
retries: 3
timeout: 5s
networks:
- fresns

networks:
fresns:
driver: bridge

volumes:
fresns-db:
driver: local
5 changes: 5 additions & 0 deletions docker/nginx.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.25

ADD ./services/nginx/default.conf /etc/nginx/conf.d/default.conf

RUN mkdir -p /var/www/html
20 changes: 20 additions & 0 deletions docker/services/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;
index index.php index.html;
server_name localhost local.fresns.cloud api.fresns.cloud;
root /var/www/html/public;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass fresns.php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
13 changes: 13 additions & 0 deletions docker/services/php/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[www]

user = www-data
group = www-data

listen = 127.0.0.1:9000

pm = dynamic

pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3