From 70376a8b059d115e359a80b1732efd7f42c5790b Mon Sep 17 00:00:00 2001 From: "a.shamavov" <a.shamavov@iqdev.digital> Date: Mon, 22 Apr 2024 14:18:47 +0500 Subject: [PATCH] =?UTF-8?q?STA-929=20|=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20nginx=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 3 +++ docker-compose.yaml | 44 +++++++++++++++++++++++++++++++++++++ docker/nginx/Dockerfile | 6 +++++ docker/nginx/default.conf | 31 ++++++++++++++++++++++++++ docker/{ => php}/Dockerfile | 12 ++++++---- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yaml create mode 100644 docker/nginx/Dockerfile create mode 100644 docker/nginx/default.conf rename docker/{ => php}/Dockerfile (61%) diff --git a/.env b/.env index a7ae4fc..416d31f 100644 --- a/.env +++ b/.env @@ -39,3 +39,6 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 ###> symfony/mailer ### # MAILER_DSN=null://null ###< symfony/mailer ### +DATABASE_PORT="5432" +NGINX_PORT="80" +APP_BASE_DIR="./" diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9a33442 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,44 @@ +version: "3" + +services: + database: + container_name: postgres + image: postgres:16.2-alpine + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 12345 + POSTGRES_HOST_AUTH_METHOD: trust + ports: + - "${DATABASE_PORT}:${DATABASE_PORT}" + networks: + - internal + nginx: + build: + dockerfile: ./docker/nginx/Dockerfile + args: + COMPOSER_AUTH: "{}" + APP_BASE_DIR: ${APP_BASE_DIR-.} + volumes: + - ".:/app" + - './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf' + ports: + - '${NGINX_PORT}:${NGINX_PORT}' + networks: + - internal + app: + build: + dockerfile: ./docker/php/Dockerfile + args: + COMPOSER_AUTH: "{}" + APP_BASE_DIR: ${APP_BASE_DIR-.} + volumes: + - ".:/app" + ports: + - "9000:9000" + restart: unless-stopped + networks: + - internal + +networks: + internal: + driver: bridge \ No newline at end of file diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..4ea2c80 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:alpine + +WORKDIR "/app" + +ARG APP_BASE_DIR +COPY $APP_BASE_DIR . diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..e282987 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,31 @@ +server { + #This config is based on https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf + + # The location of our project's public directory. + root /app/public; + + # Point index to the Laravel front controller. + index index.php; + + location / { + # URLs to attempt, including pretty ones. + try_files $uri $uri/ /index.php?$query_string; + } + + # Remove trailing slash to please routing system. + if (!-d $request_filename) { + rewrite ^/(.+)/$ /$1 permanent; + } + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini + # # With php5-fpm: + fastcgi_pass app:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} \ No newline at end of file diff --git a/docker/Dockerfile b/docker/php/Dockerfile similarity index 61% rename from docker/Dockerfile rename to docker/php/Dockerfile index 2fca0d5..e4b730f 100644 --- a/docker/Dockerfile +++ b/docker/php/Dockerfile @@ -2,11 +2,13 @@ FROM php:fpm-alpine WORKDIR "/app" -COPY .. . +ARG APP_BASE_DIR +COPY $APP_BASE_DIR . + +RUN apk update && \ + apk add libpq-dev && \ + docker-php-ext-install pdo pdo_pgsql pgsql -RUN set -ex \ - && apk --no-cache add \ - postgresql-dev RUN docker-php-ext-install pdo pdo_pgsql @@ -16,4 +18,6 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local RUN composer install +RUN chmod -R 777 /app/var + CMD ["php-fpm"] -- GitLab