mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 15:33:22 +00:00
feat: Dockerisation d'un serveur docuseal + initialisation d'un compte
par défaut
This commit is contained in:
14
Dockerfile
Normal file
14
Dockerfile
Normal 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"]
|
||||||
@ -22,7 +22,7 @@ services:
|
|||||||
docuseal:
|
docuseal:
|
||||||
image: docuseal/docuseal:latest
|
image: docuseal/docuseal:latest
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
ports:
|
ports:
|
||||||
- 3001:3000
|
- 3001:3000
|
||||||
environment:
|
environment:
|
||||||
@ -49,17 +49,34 @@ services:
|
|||||||
- docuseal
|
- docuseal
|
||||||
command: python start.py
|
command: python start.py
|
||||||
|
|
||||||
# frontend:
|
init_docuseal_users:
|
||||||
# build:
|
build:
|
||||||
# context: ./Front-End
|
context: .
|
||||||
# args:
|
dockerfile: Dockerfile
|
||||||
# - BUILD_MODE=development
|
depends_on:
|
||||||
# ports:
|
- docuseal
|
||||||
# - 3000:3000
|
environment:
|
||||||
# volumes:
|
POSTGRES_USER: postgres
|
||||||
# - ./Front-End:/app
|
POSTGRES_PASSWORD: postgres
|
||||||
# environment:
|
USER_FIRST_NAME: n3wt
|
||||||
# - TZ=Europe/Paris
|
USER_LAST_NAME: school
|
||||||
# depends_on:
|
USER_COMPANY: n3wt.innov
|
||||||
# - backend
|
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
41
initDocusealUsers.sh
Normal 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
|
||||||
Reference in New Issue
Block a user