feat: Dockerisation d'un serveur docuseal + initialisation d'un compte

par défaut
This commit is contained in:
N3WT DE COMPET
2025-02-23 21:11:45 +01:00
parent 445cf35382
commit 8897d523dc
3 changed files with 86 additions and 14 deletions

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM postgres:latest
# Installer curl
RUN apt-get update && apt-get install -y curl ruby ruby-dev build-essential
RUN gem install bcrypt
# Copier le script d'initialisation
COPY initDocusealUsers.sh /docker-entrypoint-initdb.d/initDocusealUsers.sh
# Donner les permissions d'exécution au script
RUN chmod +x /docker-entrypoint-initdb.d/initDocusealUsers.sh
# Commande par défaut pour démarrer le conteneur
ENTRYPOINT ["/bin/bash", "/docker-entrypoint-initdb.d/initDocusealUsers.sh"]

View File

@ -49,17 +49,34 @@ services:
- docuseal
command: python start.py
# frontend:
# build:
# context: ./Front-End
# args:
# - BUILD_MODE=development
# ports:
# - 3000:3000
# volumes:
# - ./Front-End:/app
# environment:
# - TZ=Europe/Paris
# depends_on:
# - backend
init_docuseal_users:
build:
context: .
dockerfile: Dockerfile
depends_on:
- docuseal
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
USER_FIRST_NAME: n3wt
USER_LAST_NAME: school
USER_COMPANY: n3wt.innov
USER_EMAIL: n3wt.school@gmail.com
USER_PASSWORD: n3wt1234
volumes:
- ./initDocusealUsers.sh:/docker-entrypoint-initdb.d/initDocusealUsers.sh
frontend:
build:
context: ./Front-End
args:
- BUILD_MODE=development
ports:
- 3000:3000
volumes:
- ./Front-End:/app
environment:
- TZ=Europe/Paris
depends_on:
- backend

41
initDocusealUsers.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
set -e
# Attendre que le service docuseal soit prêt
until curl -s http://docuseal:3000 > /dev/null; do
echo "Waiting for docuseal to be ready..."
sleep 5
done
encrypt_password() {
local password=$1
ruby -e "require 'bcrypt'; puts BCrypt::Password.create('$password')"
}
# Mot de passe encrypté
ENCRYPTED_PASSWORD=$(encrypt_password "$USER_PASSWORD")
# Insérer les données dans les tables accounts et users si elles n'existent pas déjà
PGPASSWORD=$POSTGRES_PASSWORD psql -v ON_ERROR_STOP=1 --host=database --port=5432 --username="$POSTGRES_USER" --dbname=docuseal <<-EOSQL
-- Vérifier l'existence du compte
DO \$\$
BEGIN
IF NOT EXISTS (SELECT 1 FROM accounts WHERE name = '$USER_COMPANY') THEN
-- Insérer dans la table accounts
INSERT INTO accounts (name, timezone, locale, created_at, updated_at, uuid) VALUES
('$USER_COMPANY', 'UTC', 'en', NOW(), NOW(), gen_random_uuid());
END IF;
END
\$\$;
-- Vérifier l'existence de l'utilisateur
DO \$\$
BEGIN
IF NOT EXISTS (SELECT 1 FROM users WHERE email = '$USER_EMAIL') THEN
-- Insérer dans la table users
INSERT INTO users (first_name, last_name, email, encrypted_password, account_id, role, sign_in_count, failed_attempts, created_at, updated_at, uuid, otp_required_for_login) VALUES
('$USER_FIRST_NAME', '$USER_LAST_NAME', '$USER_EMAIL', '$ENCRYPTED_PASSWORD', (SELECT id FROM accounts WHERE name = '$USER_COMPANY'), 'admin', 1, 0, NOW(), NOW(), gen_random_uuid(), false);
END IF;
END
\$\$;
EOSQL