Skip to content

Commit

Permalink
Merge pull request #12 from KarlsonComplete/add-docker-structure
Browse files Browse the repository at this point in the history
Add docker containers
  • Loading branch information
mesilov authored Oct 6, 2024
2 parents 0bb8c41 + 6473c92 commit 4c2f9b9
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 1 deletion.
File renamed without changes.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ test-unit:
vendor/bin/phpunit --testsuite unit_tests --display-warnings

test-integration:
vendor/bin/phpunit --testsuite integration_tests --display-warnings
vendor/bin/phpunit --testsuite integration_tests --display-warnings


# docker file

docker-up:
docker compose up --build -d

docker-down:
docker compose down --remove-orphans
25 changes: 25 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
php-fpm:
build:
context: ./docker/php-fpm
volumes:
- ./:/var/www/bitrix24-php-lib
nginx:
build:
context: ./docker/nginx
volumes:
- ./:/var/www/bitrix24-php-lib
ports:
- "8081:80"
depends_on:
- php-fpm
postgres-container:
image: postgres
build:
context: ./docker/postgres
ports:
- "5432:5432"
volumes:
- ./docker/postgres/data:/var/lib/postgresql/data
restart: always

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.27-alpine

RUN rm /etc/nginx/conf.d/default.conf

COPY ./conf.d/nginx.conf /etc/nginx/conf.d/
20 changes: 20 additions & 0 deletions docker/nginx/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;
server_name localhost;

root /var/www/bitrix24-php-lib;
index index.html index.htm index.php;

# Redirects requests to index.php if the file is not found
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# Passes PHP requests to PHP-FPM container
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm:9000; # Replace with your PHP-FPM container name
fastcgi_index index.php;
}
}
13 changes: 13 additions & 0 deletions docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:8.2-fpm-alpine

RUN set -ex \
&& apk --no-cache add \
postgresql-dev \
oniguruma-dev \
libzip-dev \
curl-dev \
&& docker-php-ext-install pdo pdo_pgsql mbstring zip curl bcmath

WORKDIR /bitrix24-php-lib

COPY ./ ./
12 changes: 12 additions & 0 deletions docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM postgres:16.4-alpine

# Устанавливаем переменные окружения для настройки базы данных
ENV POSTGRES_USER=kirill
ENV POSTGRES_PASSWORD=bitrix24lib
ENV POSTGRES_DB=bitrixAppDb

# Копируем SQL-скрипты для инициализации базы данных (если есть)
# COPY init.sql /docker-entrypoint-initdb.d/

# Открываем порт PostgreSQL
EXPOSE 5432
17 changes: 17 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
echo 'Hello123';
echo "<br>";
$conn_string = "pgsql:host=localhost;port=5432;dbname=bitrixAppDb;user=kirill;password=bitrix24lib";
try {
$db = new PDO($conn_string);

// Установка режима обработки ошибок
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

echo "Подключение к базе данных успешно установлено.";
}catch (PDOException $error)
{
echo "Ошибка :". $error->getMessage();
}

?>

0 comments on commit 4c2f9b9

Please sign in to comment.