add docker
This commit is contained in:
parent
adb97d6668
commit
ec16ada9b0
11
.env.example
11
.env.example
@ -0,0 +1,11 @@
|
||||
PROJECT_NAME=js-manager
|
||||
|
||||
NGINX_PORT=8010
|
||||
|
||||
DB_CONNECTION=pgsql
|
||||
DB_HOST=postgres
|
||||
DB_PORT=5433
|
||||
DB_DATABASE=js-manager
|
||||
DB_USER=user
|
||||
DB_PASSWORD=password
|
||||
DB_ROOT_PASSWORD=init
|
||||
83
compose.yml
Normal file
83
compose.yml
Normal file
@ -0,0 +1,83 @@
|
||||
services:
|
||||
redis:
|
||||
container_name: ${PROJECT_NAME}-redis-local
|
||||
image: redis:latest
|
||||
ports:
|
||||
- '6379:6379'
|
||||
networks:
|
||||
redis_net:
|
||||
aliases:
|
||||
- redis
|
||||
restart: unless-stopped
|
||||
|
||||
base-svc:
|
||||
container_name: ${PROJECT_NAME}-base-local
|
||||
build:
|
||||
context: ./docker/base
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
- UID=${UID:-1000}
|
||||
- GID=${GID:-1000}
|
||||
- USER=${USER-laravel}
|
||||
volumes:
|
||||
- ./src:/app
|
||||
working_dir: /app
|
||||
networks:
|
||||
back_net:
|
||||
aliases:
|
||||
- base
|
||||
redis_net:
|
||||
aliases:
|
||||
- base
|
||||
|
||||
nginx:
|
||||
container_name: ${PROJECT_NAME}-nginx-local
|
||||
build:
|
||||
context: ./docker/nginx
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
- UID=${UID:-1000}
|
||||
- GID=${GID:-1000}
|
||||
- USER=${USER:-laravel}
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${NGINX_PORT}:8000
|
||||
volumes:
|
||||
- ./src:/app
|
||||
depends_on:
|
||||
- base-svc
|
||||
networks:
|
||||
back_net:
|
||||
aliases:
|
||||
- nginx
|
||||
|
||||
postgres:
|
||||
container_name: ${PROJECT_NAME}-postgress
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
||||
POSTGRES_USER: ${DB_USER}
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||
POSTGRES_DB: ${DB_DATABASE}
|
||||
networks:
|
||||
back_net:
|
||||
aliases:
|
||||
- postgres
|
||||
ports:
|
||||
- ${DB_PORT}:5432
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
- .docker/postgres:/docker-entrypoint-initdb.d/:rw
|
||||
|
||||
networks:
|
||||
back_net:
|
||||
name: back_net_local
|
||||
driver: bridge
|
||||
|
||||
redis_net:
|
||||
name: redis_net_local
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
36
docker/base/Dockerfile
Normal file
36
docker/base/Dockerfile
Normal file
@ -0,0 +1,36 @@
|
||||
FROM php:8.4-fpm-alpine
|
||||
|
||||
ARG UID
|
||||
ARG GID
|
||||
ARG USER
|
||||
|
||||
ENV UID=${UID}
|
||||
ENV GID=${GID}
|
||||
ENV USER=${USER}
|
||||
|
||||
RUN delgroup dialout
|
||||
|
||||
RUN addgroup -g ${GID} --system ${USER}
|
||||
RUN adduser -G ${USER} --system -D -s /bin/sh -u ${UID} ${USER}
|
||||
|
||||
RUN sed -i "s/user = www-data/user = ${USER}/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
RUN sed -i "s/group = www-data/group = ${USER}/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
RUN echo "php_admin_flag[log_errors] = on" >> /usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
RUN apk add --no-cache postgresql-libs
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS \
|
||||
postgresql-dev \
|
||||
linux-headers
|
||||
|
||||
RUN docker-php-ext-install pdo pgsql pdo_pgsql bcmath
|
||||
|
||||
RUN pecl install redis \
|
||||
&& docker-php-ext-enable redis
|
||||
|
||||
RUN apk del --no-cache .build-deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]
|
||||
25
docker/nginx/Dockerfile
Normal file
25
docker/nginx/Dockerfile
Normal file
@ -0,0 +1,25 @@
|
||||
FROM nginx:stable-alpine
|
||||
|
||||
# environment arguments
|
||||
ARG UID
|
||||
ARG GID
|
||||
ARG USER
|
||||
|
||||
ENV UID=${UID}
|
||||
ENV GID=${GID}
|
||||
ENV USER=${USER}
|
||||
|
||||
# Dialout group in alpine linux conflicts with MacOS staff group's gid, whis is 20. So we remove it.
|
||||
RUN delgroup dialout
|
||||
|
||||
# Creating user and group
|
||||
RUN addgroup -g ${GID} --system ${USER}
|
||||
RUN adduser -G ${USER} --system -D -s /bin/sh -u ${UID} ${USER}
|
||||
|
||||
# Modify nginx configuration to use the new user's priviledges for starting it.
|
||||
RUN sed -i "s/user nginx/user '${USER}'/g" /etc/nginx/nginx.conf
|
||||
|
||||
# Copies nginx configurations to override the default.
|
||||
ADD ./*.conf /etc/nginx/conf.d/
|
||||
|
||||
WORKDIR /app
|
||||
25
docker/nginx/default.conf
Normal file
25
docker/nginx/default.conf
Normal file
@ -0,0 +1,25 @@
|
||||
server {
|
||||
listen 8000;
|
||||
index index.php index.html;
|
||||
root /app/public;
|
||||
|
||||
error_log stderr warn;
|
||||
access_log /dev/stdout main;
|
||||
|
||||
# error_log /var/log/nginx/error.log;
|
||||
# access_log /var/log/nginx/access.log;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass base-svc:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
}
|
||||
49
src/public/index.php
Normal file
49
src/public/index.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// check_connections.php
|
||||
if (!extension_loaded('pgsql')) {
|
||||
die("❌ Расширение 'pgsql' не загружено!");
|
||||
}
|
||||
echo "✅ pgsql доступен.";
|
||||
|
||||
$pgHost = $_ENV['PG_HOST'] ?? 'postgres';
|
||||
$pgPort = $_ENV['PG_PORT'] ?? '5432';
|
||||
$pgDbname = $_ENV['PG_DBNAME'] ?? 'js-manager';
|
||||
$pgUser = $_ENV['PG_USER'] ?? 'user';
|
||||
$pgPassword = $_ENV['PG_PASSWORD'] ?? 'password';
|
||||
|
||||
$redisHost = $_ENV['REDIS_HOST'] ?? '127.0.0.1';
|
||||
$redisPort = $_ENV['REDIS_PORT'] ?? 6379;
|
||||
|
||||
echo "🔍 Проверка PostgreSQL...\n";
|
||||
try {
|
||||
$connStr = "host=$pgHost port=$pgPort dbname=$pgDbname user=$pgUser password=$pgPassword";
|
||||
$pgConn = pg_connect($connStr, PGSQL_CONNECT_FORCE_NEW);
|
||||
if ($pgConn) {
|
||||
echo "✅ PostgreSQL: OK\n";
|
||||
pg_close($pgConn);
|
||||
} else {
|
||||
throw new Exception('Неизвестная ошибка подключения');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "❌ PostgreSQL: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
echo "🔍 Проверка Redis...\n";
|
||||
try {
|
||||
$redis = new Redis();
|
||||
if (!$redis->connect($redisHost, $redisPort, 3)) {
|
||||
throw new Exception('Не удалось подключиться');
|
||||
}
|
||||
|
||||
// Простой пинг для проверки работоспособности
|
||||
if ($redis->ping() === '+PONG') {
|
||||
echo "✅ Redis: OK\n";
|
||||
} else {
|
||||
throw new Exception('Redis не отвечает корректно');
|
||||
}
|
||||
$redis->close();
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Redis: " . $e->getMessage() . "\n";
|
||||
}
|
||||
2
src/public/ino.php
Normal file
2
src/public/ino.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
phpinfo();
|
||||
Loading…
x
Reference in New Issue
Block a user