refactor(infra) : reorganize docker config into infra/dev and infra/prod
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Align project structure with Lesstime: move docker/ to infra/dev/ and deploy/ to infra/prod/. Update all references in docker-compose, makefile, CI workflow, Dockerfile, .gitignore and .dockerignore. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
9
infra/dev/.env.docker
Normal file
9
infra/dev/.env.docker
Normal file
@@ -0,0 +1,9 @@
|
||||
DOCKER_APP_NAME=inventory
|
||||
DOCKER_PHP_VERSION=8.4.6
|
||||
DOCKER_NODE_VERSION=24.12.0
|
||||
APP_USER=www-data
|
||||
POSTGRES_DB=inventory
|
||||
POSTGRES_USER=root
|
||||
POSTGRES_PASSWORD=root
|
||||
POSTGRES_PORT=5432
|
||||
XDEBUG_CLIENT_HOST=host.docker.internal
|
||||
35
infra/dev/.env.docker.local
Normal file
35
infra/dev/.env.docker.local
Normal file
@@ -0,0 +1,35 @@
|
||||
DOCKER_APP_NAME=inventory
|
||||
DOCKER_PHP_VERSION=8.4.6
|
||||
DOCKER_NODE_VERSION=24.12.0
|
||||
APP_USER=www-data
|
||||
CURRENT_UID=1000
|
||||
CURRENT_GID=1000
|
||||
|
||||
# PostgreSQL
|
||||
POSTGRES_DB=inventory
|
||||
POSTGRES_USER=root
|
||||
POSTGRES_PASSWORD=root
|
||||
#
|
||||
# CORS
|
||||
CORS_ALLOW_ORIGIN=^https?://(localhost|127\\.0\\.0\\.1)(:[0-9]+)?$
|
||||
POSTGRES_PORT=5433
|
||||
|
||||
# pgAdmin
|
||||
PGADMIN_EMAIL=admin@admin.com
|
||||
PGADMIN_PASSWORD=admin
|
||||
PGADMIN_PORT=5050
|
||||
|
||||
# XDebug
|
||||
XDEBUG_CLIENT_HOST=host.docker.internal
|
||||
|
||||
# Symfony (pour future migration)
|
||||
APP_ENV=dev
|
||||
APP_SECRET=changeme_super_secret_key_123456789
|
||||
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
|
||||
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
|
||||
JWT_PASSPHRASE=your_jwt_passphrase_change_me
|
||||
|
||||
# NestJS
|
||||
NESTJS_PORT=3000
|
||||
SESSION_SECRET=changeme_session_secret
|
||||
CORS_ORIGIN=http://localhost:3001
|
||||
129
infra/dev/Dockerfile
Normal file
129
infra/dev/Dockerfile
Normal file
@@ -0,0 +1,129 @@
|
||||
ARG DOCKER_PHP_VERSION
|
||||
|
||||
FROM php:${DOCKER_PHP_VERSION}-apache-bullseye
|
||||
|
||||
ARG DOCKER_NODE_VERSION
|
||||
ENV DOCKER_NODE_VERSION="${DOCKER_NODE_VERSION}"
|
||||
|
||||
# Installer les dépendances et extensions PHP nécessaires
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libicu-dev \
|
||||
libpq-dev \
|
||||
libpng-dev \
|
||||
libzip-dev \
|
||||
libxml2-dev \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
libbz2-dev \
|
||||
libgmp-dev \
|
||||
libldap2-dev \
|
||||
libonig-dev \
|
||||
libsodium-dev \
|
||||
libxslt1-dev \
|
||||
unixodbc-dev \
|
||||
libsqlite3-dev \
|
||||
zlib1g-dev \
|
||||
libssl-dev \
|
||||
libc-client-dev \
|
||||
libkrb5-dev \
|
||||
freetds-dev \
|
||||
vim \
|
||||
tcpdump \
|
||||
dnsutils \
|
||||
wget \
|
||||
git \
|
||||
unzip \
|
||||
qpdf \
|
||||
&& docker-php-ext-install -j$(nproc) \
|
||||
intl \
|
||||
zip \
|
||||
bcmath \
|
||||
bz2 \
|
||||
calendar \
|
||||
exif \
|
||||
gd \
|
||||
gettext \
|
||||
gmp \
|
||||
ldap \
|
||||
# mysqli \
|
||||
pcntl \
|
||||
pdo_pgsql \
|
||||
# pdo_mysql \
|
||||
# pdo_sqlite \
|
||||
# pdo_sqlsrv \
|
||||
soap \
|
||||
sockets \
|
||||
sysvsem \
|
||||
xsl
|
||||
|
||||
|
||||
# Installation de node
|
||||
RUN wget -qO- "https://nodejs.org/dist/v${DOCKER_NODE_VERSION}/node-v${DOCKER_NODE_VERSION}-linux-x64.tar.xz" | tar xJC /tmp/ && \
|
||||
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/bin /usr/ && \
|
||||
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/include /usr/ && \
|
||||
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/lib /usr/ && \
|
||||
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/share /usr/ && \
|
||||
npm install --global yarn
|
||||
|
||||
# installation/activation d'extensions php
|
||||
RUN pecl install xdebug
|
||||
RUN docker-php-ext-enable xdebug && \
|
||||
docker-php-ext-install zip && \
|
||||
docker-php-ext-install gd && \
|
||||
docker-php-ext-install soap && \
|
||||
docker-php-ext-configure intl && \
|
||||
docker-php-ext-install intl
|
||||
|
||||
# Configuration spéciale pour quelques extensions
|
||||
# RUN docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && \
|
||||
# docker-php-ext-install pdo_odbc \
|
||||
RUN docker-php-ext-enable opcache
|
||||
|
||||
# Configurer Oracle OCI8 (nécessite le SDK Oracle, à installer manuellement ou à lier via les dépendances)
|
||||
#RUN apt-get update && apt-get -y install wget unzip libaio1 && \
|
||||
# wget https://download.oracle.com/otn_software/linux/instantclient/2340000/instantclient-basic-linux.x64-23.4.0.24.05.zip && \
|
||||
# unzip -o instantclient-basic-linux.x64-23.4.0.24.05.zip -d /usr/local && \
|
||||
# wget https://download.oracle.com/otn_software/linux/instantclient/2340000/instantclient-sdk-linux.x64-23.4.0.24.05.zip && \
|
||||
# unzip -o instantclient-sdk-linux.x64-23.4.0.24.05.zip -d /usr/local
|
||||
#
|
||||
#RUN echo 'instantclient,/usr/local/instantclient_23_4' | pecl install oci8-3.4.0 \
|
||||
# && docker-php-ext-enable oci8
|
||||
#
|
||||
#ENV ORACLE_BASE /usr/local/instantclient_23_4
|
||||
#ENV LD_LIBRARY_PATH /usr/local/instantclient_23_4
|
||||
#ENV TNS_ADMIN /usr/local/instantclient_23_4
|
||||
#ENV ORACLE_HOME /usr/local/instantclient_23_4
|
||||
|
||||
|
||||
# Configuration pour utiliser Kerberos avec IMAP (si nécessaire)
|
||||
# RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
|
||||
# && docker-php-ext-install imap
|
||||
|
||||
# installation de composer
|
||||
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/* && \
|
||||
curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
|
||||
|
||||
# Création de la structure du projet
|
||||
RUN mkdir /var/www/html/LOG
|
||||
|
||||
# Activation du module pour Apache2 proxy_http et rewrite
|
||||
RUN a2enmod proxy_http && \
|
||||
a2enmod rewrite
|
||||
|
||||
###> User ###
|
||||
ARG CURRENT_UID
|
||||
ARG CURRENT_GID
|
||||
# mapping du user host avec www-data
|
||||
RUN usermod -o -u ${CURRENT_UID} www-data && groupmod -o -g ${CURRENT_GID} www-data
|
||||
RUN chown www-data:www-data -R /var/www/*
|
||||
RUN chown www-data:www-data -R /var/www/.*
|
||||
###< User ###
|
||||
|
||||
RUN rm -rf \
|
||||
/var/lib/apt/lists/* \
|
||||
/tmp/* \
|
||||
/var/tmp/*
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
EXPOSE 80
|
||||
2
infra/dev/pgadmin/pgpass
Normal file
2
infra/dev/pgadmin/pgpass
Normal file
@@ -0,0 +1,2 @@
|
||||
db:5432:inventory:root:root
|
||||
db:5432:*:root:root
|
||||
15
infra/dev/pgadmin/servers.json
Normal file
15
infra/dev/pgadmin/servers.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Servers": {
|
||||
"1": {
|
||||
"Name": "Inventory PostgreSQL",
|
||||
"Group": "Servers",
|
||||
"Host": "db",
|
||||
"Port": 5432,
|
||||
"MaintenanceDB": "inventory",
|
||||
"Username": "root",
|
||||
"SSLMode": "prefer",
|
||||
"PassFile": "/var/lib/pgadmin/pgpass",
|
||||
"Comment": "Serveur PostgreSQL du projet Inventory"
|
||||
}
|
||||
}
|
||||
}
|
||||
4
infra/dev/php.ini
Normal file
4
infra/dev/php.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
[Date]
|
||||
; Defines the default timezone used by the date functions
|
||||
; http://php.net/date.timezone
|
||||
date.timezone = Europe/Paris
|
||||
15
infra/dev/vhost.conf
Normal file
15
infra/dev/vhost.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost
|
||||
DocumentRoot /var/www/html/public
|
||||
|
||||
# API Symfony
|
||||
<Directory /var/www/html/public>
|
||||
Options +FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
# Logs
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
9
infra/dev/xdebug.ini
Normal file
9
infra/dev/xdebug.ini
Normal file
@@ -0,0 +1,9 @@
|
||||
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so
|
||||
xdebug.mode=debug
|
||||
xdebug.idekey=PHPSTORM
|
||||
xdebug.start_with_request=yes
|
||||
xdebug.discover_client_host=1
|
||||
xdebug.client_port=9003
|
||||
xdebug.log="/var/www/html/LOG/xdebug.log"
|
||||
xdebug.log_level=0
|
||||
xdebug.connect_timeout_ms=2
|
||||
10
infra/prod/.env.example
Normal file
10
infra/prod/.env.example
Normal file
@@ -0,0 +1,10 @@
|
||||
# Symfony
|
||||
APP_ENV=prod
|
||||
APP_DEBUG=0
|
||||
APP_SECRET=change-me
|
||||
|
||||
# Database (use host.docker.internal to reach bare-metal PostgreSQL)
|
||||
DATABASE_URL="postgresql://inventory_user:password@host.docker.internal:5432/inventory_prod?serverVersion=16&charset=utf8"
|
||||
|
||||
# CORS
|
||||
CORS_ALLOW_ORIGIN='^https?://inventory\.malio-dev\.fr$'
|
||||
83
infra/prod/Dockerfile
Normal file
83
infra/prod/Dockerfile
Normal file
@@ -0,0 +1,83 @@
|
||||
# --- Stage 1: Build backend ---
|
||||
FROM php:8.4-cli AS backend-build
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libicu-dev libpq-dev libpng-dev libzip-dev libxml2-dev \
|
||||
unzip curl git \
|
||||
&& docker-php-ext-install -j$(nproc) intl pdo_pgsql zip gd opcache \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
WORKDIR /app
|
||||
COPY composer.json composer.lock symfony.lock ./
|
||||
RUN APP_ENV=prod APP_DEBUG=0 composer install --no-dev --no-scripts --no-interaction
|
||||
|
||||
COPY bin bin/
|
||||
COPY config config/
|
||||
COPY migrations migrations/
|
||||
COPY public public/
|
||||
COPY src src/
|
||||
COPY templates templates/
|
||||
|
||||
RUN composer dump-autoload --optimize --no-dev
|
||||
|
||||
# --- Stage 2: Build frontend ---
|
||||
FROM node:lts-alpine AS frontend-build
|
||||
|
||||
WORKDIR /app/frontend
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
COPY frontend/ ./
|
||||
COPY config/version.yaml /app/config/version.yaml
|
||||
ENV CI=1 \
|
||||
NUXT_TELEMETRY_DISABLED=1 \
|
||||
NUXT_PUBLIC_API_BASE_URL=/api \
|
||||
NUXT_PUBLIC_APP_BASE=/
|
||||
RUN npm run generate
|
||||
|
||||
# --- Stage 3: Production image ---
|
||||
FROM php:8.4-fpm AS production
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libicu-dev libpq-dev libpng-dev libzip-dev libxml2-dev \
|
||||
nginx supervisor \
|
||||
&& docker-php-ext-install -j$(nproc) intl pdo_pgsql zip gd opcache \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# PHP production config
|
||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||
|
||||
# PHP-FPM: forward worker output to stderr for docker logs
|
||||
RUN echo "catch_workers_output = yes" >> /usr/local/etc/php-fpm.d/www.conf \
|
||||
&& echo "decorate_workers_output = no" >> /usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
# Nginx: log to stdout/stderr
|
||||
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
|
||||
# Remove default nginx site
|
||||
RUN rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Configs
|
||||
COPY infra/prod/supervisord.conf /etc/supervisor/conf.d/app.conf
|
||||
COPY infra/prod/nginx.conf /etc/nginx/sites-enabled/inventory.conf
|
||||
|
||||
# Backend from stage 1
|
||||
COPY --from=backend-build /app /var/www/html
|
||||
|
||||
# Frontend from stage 2
|
||||
COPY --from=frontend-build /app/frontend/.output/public /var/www/html/frontend/.output/public
|
||||
|
||||
# Symfony needs a .env file to boot (variables are overridden by env_file in docker-compose)
|
||||
RUN echo "APP_ENV=prod" > /var/www/html/.env
|
||||
|
||||
# Permissions
|
||||
RUN mkdir -p /var/www/html/var /var/www/html/var/uploads \
|
||||
&& chown -R www-data:www-data /var/www/html/var
|
||||
|
||||
WORKDIR /var/www/html
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/app.conf"]
|
||||
28
infra/prod/deploy.sh
Executable file
28
infra/prod/deploy.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
TAG="${1:-latest}"
|
||||
export INVENTORY_IMAGE_TAG="$TAG"
|
||||
|
||||
echo "==> Deploying inventory:${TAG}..."
|
||||
|
||||
echo "==> Pulling image..."
|
||||
sudo docker compose pull
|
||||
|
||||
echo "==> Starting container..."
|
||||
sudo docker compose up -d
|
||||
|
||||
echo "==> Waiting for container to be ready..."
|
||||
sleep 3
|
||||
|
||||
echo "==> Running migrations..."
|
||||
sudo docker compose exec -T -u www-data app php bin/console doctrine:migrations:migrate --no-interaction
|
||||
|
||||
echo "==> Clearing cache..."
|
||||
sudo docker compose exec -T -u www-data app php bin/console cache:clear --env=prod
|
||||
sudo docker compose exec -T -u www-data app php bin/console cache:warmup --env=prod
|
||||
|
||||
VERSION=$(sudo docker compose exec -T app cat config/version.yaml | grep 'app.version' | awk -F"'" '{print $2}')
|
||||
echo "==> Deployed v${VERSION}"
|
||||
12
infra/prod/docker-compose.yml
Normal file
12
infra/prod/docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
app:
|
||||
image: gitea.malio.fr/malio-dev/inventory:${INVENTORY_IMAGE_TAG:-latest}
|
||||
container_name: inventory-app
|
||||
env_file: .env
|
||||
ports:
|
||||
- "8082:80"
|
||||
volumes:
|
||||
- ./storage:/var/www/html/var/storage/documents
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
restart: unless-stopped
|
||||
13
infra/prod/nginx-proxy.conf
Normal file
13
infra/prod/nginx-proxy.conf
Normal file
@@ -0,0 +1,13 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name inventory.malio-dev.fr;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
36
infra/prod/nginx.conf
Normal file
36
infra/prod/nginx.conf
Normal file
@@ -0,0 +1,36 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /var/www/html/frontend/.output/public;
|
||||
index index.html;
|
||||
|
||||
access_log /dev/stdout;
|
||||
error_log /dev/stderr;
|
||||
|
||||
location ^~ /api/ {
|
||||
root /var/www/html/public;
|
||||
try_files $uri /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ^~ /bundles/ {
|
||||
root /var/www/html/public;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ~ ^/index\.php(/|$) {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
||||
fastcgi_param DOCUMENT_ROOT /var/www/html/public;
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
internal;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
28
infra/prod/supervisord.conf
Normal file
28
infra/prod/supervisord.conf
Normal file
@@ -0,0 +1,28 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
logfile=/dev/null
|
||||
logfile_maxbytes=0
|
||||
pidfile=/var/run/supervisord.pid
|
||||
|
||||
[program:php-fpm]
|
||||
command=php-fpm -F
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
stopasgroup=true
|
||||
stopsignal=QUIT
|
||||
|
||||
[program:nginx]
|
||||
command=nginx -g "daemon off;"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
stopasgroup=true
|
||||
stopsignal=QUIT
|
||||
Reference in New Issue
Block a user