Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c62f054da1 | ||
|
|
be57451d29 | ||
|
|
bcfecb2281 | ||
|
|
90147bd93b | ||
|
|
4d106e9625 | ||
|
|
9748862684 | ||
|
|
1904c999ec | ||
|
|
81266dd64b | ||
|
|
c5e2800e4c | ||
|
|
ef1c14f8da | ||
|
|
7e5080859d | ||
|
|
414916a20d | ||
|
|
70c05946bd | ||
|
|
ede55b9f08 | ||
|
|
c61b24bea3 | ||
|
|
389bfbef13 |
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.20'
|
app.version: '0.1.28'
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
ports:
|
ports:
|
||||||
- "3003:3003"
|
- "3004:3003"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:1.27-alpine
|
image: nginx:1.27-alpine
|
||||||
|
|||||||
26501
frontend/package-lock.json
generated
26501
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,7 @@ APP_ENV=prod
|
|||||||
APP_DEBUG=0
|
APP_DEBUG=0
|
||||||
APP_SECRET=CHANGE_ME_IN_PRODUCTION
|
APP_SECRET=CHANGE_ME_IN_PRODUCTION
|
||||||
|
|
||||||
POSTGRES_DB=coltura
|
DATABASE_URL="postgresql://coltura:CHANGE_ME@host.docker.internal:5432/coltura?serverVersion=16&charset=utf8"
|
||||||
POSTGRES_USER=coltura
|
|
||||||
POSTGRES_PASSWORD=CHANGE_ME_IN_PRODUCTION
|
|
||||||
|
|
||||||
JWT_PASSPHRASE=CHANGE_ME_IN_PRODUCTION
|
JWT_PASSPHRASE=CHANGE_ME_IN_PRODUCTION
|
||||||
JWT_COOKIE_SECURE=1
|
JWT_COOKIE_SECURE=1
|
||||||
|
|||||||
@@ -1,88 +1,84 @@
|
|||||||
ARG DOCKER_PHP_VERSION=8.4.6
|
# --- Stage 1: Build backend ---
|
||||||
|
FROM php:8.4-cli AS backend-build
|
||||||
|
|
||||||
FROM php:${DOCKER_PHP_VERSION}-fpm-bullseye AS php-base
|
|
||||||
|
|
||||||
ARG DOCKER_NODE_VERSION=24.12.0
|
|
||||||
ENV DOCKER_NODE_VERSION="${DOCKER_NODE_VERSION}"
|
|
||||||
|
|
||||||
# Installer les dépendances et extensions PHP nécessaires
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
libicu-dev \
|
libicu-dev libpq-dev libpng-dev libzip-dev libxml2-dev \
|
||||||
libpq-dev \
|
unzip curl git \
|
||||||
libpng-dev \
|
&& docker-php-ext-install -j$(nproc) intl pdo_pgsql zip gd opcache \
|
||||||
libzip-dev \
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
libxml2-dev \
|
|
||||||
ca-certificates \
|
|
||||||
gnupg \
|
|
||||||
libbz2-dev \
|
|
||||||
libgmp-dev \
|
|
||||||
libldap2-dev \
|
|
||||||
libonig-dev \
|
|
||||||
libsodium-dev \
|
|
||||||
libxslt1-dev \
|
|
||||||
zlib1g-dev \
|
|
||||||
libssl-dev \
|
|
||||||
wget \
|
|
||||||
git \
|
|
||||||
unzip \
|
|
||||||
&& docker-php-ext-install -j$(nproc) \
|
|
||||||
intl \
|
|
||||||
zip \
|
|
||||||
bcmath \
|
|
||||||
bz2 \
|
|
||||||
calendar \
|
|
||||||
exif \
|
|
||||||
gd \
|
|
||||||
gettext \
|
|
||||||
gmp \
|
|
||||||
ldap \
|
|
||||||
pcntl \
|
|
||||||
pdo_pgsql \
|
|
||||||
soap \
|
|
||||||
sockets \
|
|
||||||
sysvsem \
|
|
||||||
xsl \
|
|
||||||
&& docker-php-ext-enable opcache \
|
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/*
|
|
||||||
|
|
||||||
# Installation de node
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
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/ && \
|
|
||||||
rm -rf /tmp/*
|
|
||||||
|
|
||||||
# Installation de composer
|
WORKDIR /app
|
||||||
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
|
COPY composer.json composer.lock ./
|
||||||
|
RUN APP_ENV=prod APP_DEBUG=0 composer install --no-dev --no-scripts --no-interaction
|
||||||
|
|
||||||
WORKDIR /var/www/html
|
COPY bin bin/
|
||||||
|
COPY config config/
|
||||||
|
COPY migrations migrations/
|
||||||
|
COPY public public/
|
||||||
|
COPY src src/
|
||||||
|
|
||||||
ENV APP_ENV=prod
|
RUN composer dump-autoload --optimize --no-dev
|
||||||
|
|
||||||
# Copier les fichiers projet
|
# --- Stage 2: Build frontend ---
|
||||||
COPY . /var/www/html
|
FROM node:22-alpine AS frontend-build
|
||||||
|
|
||||||
# Installation des dépendances PHP (prod)
|
WORKDIR /app/frontend
|
||||||
RUN composer install --no-dev --optimize-autoloader --no-interaction
|
COPY frontend/package.json frontend/package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
# Génération des clés JWT si absentes
|
COPY frontend/ ./
|
||||||
RUN php bin/console lexik:jwt:generate-keypair --skip-if-exists
|
ENV CI=1 \
|
||||||
|
NUXT_TELEMETRY_DISABLED=1 \
|
||||||
|
NUXT_PUBLIC_API_BASE=/api \
|
||||||
|
NUXT_PUBLIC_APP_BASE=/
|
||||||
|
RUN npm run generate
|
||||||
|
|
||||||
# Build du frontend
|
# --- Stage 3: Production image ---
|
||||||
RUN cd frontend && npm ci && npm run build:dist && rm -rf node_modules
|
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/coltura.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
|
||||||
|
|
||||||
|
# Maintenance page
|
||||||
|
COPY infra/prod/maintenance.html /var/www/html/public/maintenance.html
|
||||||
|
|
||||||
|
# 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
|
# Permissions
|
||||||
RUN chown -R www-data:www-data /var/www/html/var /var/www/html/frontend/dist
|
RUN mkdir -p /var/www/html/var /var/www/html/config/jwt \
|
||||||
|
&& chown -R www-data:www-data /var/www/html/var
|
||||||
|
|
||||||
# PHP prod config
|
WORKDIR /var/www/html
|
||||||
COPY infra/prod/php-prod.ini /usr/local/etc/php/php.ini
|
EXPOSE 80
|
||||||
|
|
||||||
EXPOSE 9000
|
CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/app.conf"]
|
||||||
|
|
||||||
# ── Nginx stage ──
|
|
||||||
FROM nginx:1.27-alpine AS nginx
|
|
||||||
|
|
||||||
COPY infra/prod/nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
COPY --from=php-base /var/www/html/public /var/www/html/public
|
|
||||||
COPY --from=php-base /var/www/html/frontend/dist /var/www/html/frontend/dist
|
|
||||||
|
|||||||
39
infra/prod/deploy.sh
Executable file
39
infra/prod/deploy.sh
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
TAG="${1:-latest}"
|
||||||
|
export COLTURA_IMAGE_TAG="$TAG"
|
||||||
|
|
||||||
|
echo "==> Deploying coltura:${TAG}..."
|
||||||
|
|
||||||
|
echo "==> Enabling maintenance mode..."
|
||||||
|
touch maintenance.on
|
||||||
|
|
||||||
|
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 "==> Extracting maintenance page..."
|
||||||
|
mkdir -p public
|
||||||
|
sudo docker compose cp app:/var/www/html/public/maintenance.html public/maintenance.html
|
||||||
|
sudo chown -R www-data:www-data public
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
echo "==> Disabling maintenance mode..."
|
||||||
|
rm -f maintenance.on
|
||||||
|
|
||||||
|
VERSION=$(sudo docker compose exec -T app cat config/version.yaml | grep 'app.version' | awk -F"'" '{print $2}')
|
||||||
|
echo "==> Deployed v${VERSION}"
|
||||||
@@ -1,42 +1,12 @@
|
|||||||
services:
|
services:
|
||||||
php:
|
app:
|
||||||
container_name: php-coltura-fpm
|
image: gitea.malio.fr/malio-dev/coltura:${COLTURA_IMAGE_TAG:-latest}
|
||||||
build:
|
container_name: coltura-app
|
||||||
context: ../../
|
env_file: .env
|
||||||
dockerfile: infra/prod/Dockerfile
|
|
||||||
target: php-base
|
|
||||||
environment:
|
|
||||||
APP_ENV: prod
|
|
||||||
APP_DEBUG: 0
|
|
||||||
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?serverVersion=16&charset=utf8"
|
|
||||||
volumes:
|
|
||||||
- uploads_data:/var/www/html/var/uploads
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
nginx:
|
|
||||||
container_name: nginx-coltura
|
|
||||||
build:
|
|
||||||
context: ../../
|
|
||||||
dockerfile: infra/prod/Dockerfile
|
|
||||||
target: nginx
|
|
||||||
depends_on:
|
|
||||||
- php
|
|
||||||
ports:
|
ports:
|
||||||
- "8086:80"
|
- "8086:80"
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:16-alpine
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB}
|
|
||||||
POSTGRES_USER: ${POSTGRES_USER}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
||||||
volumes:
|
volumes:
|
||||||
- pg_data:/var/lib/postgresql/data
|
- ./config/jwt:/var/www/html/config/jwt:ro
|
||||||
|
extra_hosts:
|
||||||
|
- "host.docker.internal:host-gateway"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
volumes:
|
|
||||||
pg_data:
|
|
||||||
uploads_data:
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://127.0.0.1:8083;
|
proxy_pass http://127.0.0.1:8086;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|||||||
@@ -2,16 +2,24 @@ server {
|
|||||||
listen 80;
|
listen 80;
|
||||||
server_name _;
|
server_name _;
|
||||||
|
|
||||||
root /var/www/html/frontend/dist;
|
root /var/www/html/frontend/.output/public;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
client_max_body_size 55m;
|
client_max_body_size 55m;
|
||||||
|
|
||||||
|
access_log /dev/stdout;
|
||||||
|
error_log /dev/stderr;
|
||||||
|
|
||||||
location ^~ /api/ {
|
location ^~ /api/ {
|
||||||
root /var/www/html/public;
|
root /var/www/html/public;
|
||||||
try_files $uri /index.php?$query_string;
|
try_files $uri /index.php?$query_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location ^~ /bundles/ {
|
||||||
|
root /var/www/html/public;
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
location = /api/login_check {
|
location = /api/login_check {
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
||||||
@@ -19,19 +27,15 @@ server {
|
|||||||
fastcgi_param SCRIPT_NAME /index.php;
|
fastcgi_param SCRIPT_NAME /index.php;
|
||||||
fastcgi_param PATH_INFO /login_check;
|
fastcgi_param PATH_INFO /login_check;
|
||||||
fastcgi_param REQUEST_URI /login_check;
|
fastcgi_param REQUEST_URI /login_check;
|
||||||
fastcgi_pass php:9000;
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
}
|
|
||||||
|
|
||||||
location ^~ /bundles/ {
|
|
||||||
root /var/www/html/public;
|
|
||||||
try_files $uri =404;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ ^/index\.php(/|$) {
|
location ~ ^/index\.php(/|$) {
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
||||||
fastcgi_param DOCUMENT_ROOT /var/www/html/public;
|
fastcgi_param DOCUMENT_ROOT /var/www/html/public;
|
||||||
fastcgi_pass php:9000;
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
|
internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
|
|||||||
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
|
||||||
62
src/Command/CreateUserCommand.php
Normal file
62
src/Command/CreateUserCommand.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:create-user',
|
||||||
|
description: 'Create a new user',
|
||||||
|
)]
|
||||||
|
class CreateUserCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $em,
|
||||||
|
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addArgument('username', InputArgument::REQUIRED, 'Username')
|
||||||
|
->addArgument('password', InputArgument::REQUIRED, 'Plain password')
|
||||||
|
->addOption('admin', null, InputOption::VALUE_NONE, 'Grant ROLE_ADMIN')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$username = $input->getArgument('username');
|
||||||
|
$plainPassword = $input->getArgument('password');
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->setUsername($username);
|
||||||
|
$user->setPassword($this->passwordHasher->hashPassword($user, $plainPassword));
|
||||||
|
|
||||||
|
if ($input->getOption('admin')) {
|
||||||
|
$user->setRoles(['ROLE_ADMIN']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em->persist($user);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
$io->success(sprintf('User "%s" created%s.', $username, $input->getOption('admin') ? ' with ROLE_ADMIN' : ''));
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user