Skip to content

Commit

Permalink
Создание инфраструктуры Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
low-blow committed Feb 14, 2024
1 parent 18c6f3f commit f497447
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# PostgreSQL
POSTGRES_DB=project
POSTGRES_USER=ps_user
POSTGRES_PASSWORD=ps_password
POSTGRES_HOST=postgres

# Redis
REDIS_REPLICATION_MODE=master
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea/
/vendor/
.DS_Store
.AppleDouble
.LSOverride
.env
69 changes: 69 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3'

services:
nginx:
build:
context: .
dockerfile: docker/nginx/Dockerfile
restart: on-failure
ports:
- "80:80"
volumes:
- ./project:/var/www/project
- ./docker/sock:/sock
networks:
- project-network

php:
build:
context: .
dockerfile: docker/php-fpm/Dockerfile
restart: on-failure
volumes:
- ./project:/var/www/project
- ./docker/sock:/sock
networks:
- project-network

postgres:
build:
context: .
dockerfile: docker/postgres/Dockerfile
restart: on-failure
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PGDATA: /var/lib/postgresql/data
volumes:
- db-data:/var/lib/postgresql/data:rw
ports:
- "5432:5432"
networks:
- project-network

redis:
image: "redis:alpine"
command: redis-server
restart: on-failure
ports:
- "6379:6379"
environment:
- REDIS_REPLICATION_MODE=${REDIS_REPLICATION_MODE}
networks:
- project-network

memcached:
image: "memcached:alpine"
restart: on-failure
ports:
- "11211:11211"
networks:
- project-network

volumes:
db-data:

networks:
project-network:
driver: bridge
8 changes: 8 additions & 0 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG NGINX_VERSION=1.25.3

FROM nginx:${NGINX_VERSION}

COPY docker/nginx/default.conf /etc/nginx/conf.d/

EXPOSE 80
EXPOSE 443
27 changes: 27 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
server_name localhost;
root /var/www/project/public;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/sock/docker.sock;

fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

internal;
}

location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
42 changes: 42 additions & 0 deletions docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ARG PHP_VERSION=8.3-fpm

FROM php:${PHP_VERSION}

RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libpq-dev \
libonig-dev \
libzip-dev \
libmemcached-dev \
libssl-dev \
libmcrypt-dev \
&& pecl install mcrypt-1.0.7 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-install -j$(nproc) pgsql pdo pdo_pgsql opcache bcmath zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& pecl install memcached \
&& docker-php-ext-enable memcached \
&& pecl install redis \
&& docker-php-ext-enable redis

COPY docker/php-fpm/php.ini $PHP_INI_DIR/conf.d/php.ini
COPY docker/php-fpm/www.conf /usr/local/etc/php-fpm.d/zz-docker.conf

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php --install-dir=/usr/local/bin --filename=composer

RUN usermod -u 1000 www-data

COPY --chown=www-data:www-data project/ /var/www/project/

RUN chown -R www-data:www-data /var/www

WORKDIR /var/www/project

USER www-data

RUN export COMPOSER_HOME=$(pwd) && composer --no-progress --prefer-dist --no-interaction install;

CMD ["php-fpm"]
1 change: 1 addition & 0 deletions docker/php-fpm/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
date.timezone=Europe/Moscow
6 changes: 6 additions & 0 deletions docker/php-fpm/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[global]
daemonize = no

[www]
listen = /sock/docker.sock
listen.mode = 0666
3 changes: 3 additions & 0 deletions docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ARG POSTGRESQL_VERSION=16.2-alpine

FROM postgres:${POSTGRESQL_VERSION}
7 changes: 7 additions & 0 deletions project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/var/
/vendor/
/cache/
/.env.local
.env
/.env.*.local
.htaccess
16 changes: 16 additions & 0 deletions project/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "sfadeev/project",
"type": "project",
"autoload": {
"psr-4": {
"Sfadeev\\Project\\": "src/"
}
},
"authors": [
{
"name": "Sergey Fadeev",
"email": "[email protected]"
}
],
"require": {}
}
18 changes: 18 additions & 0 deletions project/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions project/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php

Check failure on line 1 in project/public/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
phpinfo();

0 comments on commit f497447

Please sign in to comment.