diff --git a/.env.example b/.env.example index e69de29..cc23e78 100644 --- a/.env.example +++ b/.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 diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..5c71e26 --- /dev/null +++ b/compose.yml @@ -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: diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile new file mode 100644 index 0000000..4bbb248 --- /dev/null +++ b/docker/base/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..05e04e1 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -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 \ No newline at end of file diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..804d415 --- /dev/null +++ b/docker/nginx/default.conf @@ -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; + } +} diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..baf9902 --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,49 @@ +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"; +} \ No newline at end of file diff --git a/src/public/ino.php b/src/public/ino.php new file mode 100644 index 0000000..bfd863b --- /dev/null +++ b/src/public/ino.php @@ -0,0 +1,2 @@ +