From 12b2ec8ce8a68d2f12e34dc304fb1c8fc09f6143 Mon Sep 17 00:00:00 2001 From: batche Date: Mon, 2 Jan 2023 22:43:09 +0100 Subject: [PATCH] toujours dans l'env --- make_env.sh | 124 +++++++++--------- srcs/requirements/svelte/.dockerignore | 1 + .../svelte/api_front/src/Constantes.ts | 3 - 3 files changed, 63 insertions(+), 65 deletions(-) delete mode 100644 srcs/requirements/svelte/api_front/src/Constantes.ts diff --git a/make_env.sh b/make_env.sh index 671ec3ae..f0e5b71a 100644 --- a/make_env.sh +++ b/make_env.sh @@ -1,6 +1,7 @@ #! /usr/bin/env bash - +ENV_FILE_DOCKER=./srcs/.env +ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env # Function to generate passwords # @@ -12,73 +13,72 @@ echo $(openssl rand -base64 32 | tr "/" "_" ); } - - -# This script is used to create a new environment for the project. -# - ENV_FILE_DOCKER=./srcs/.env - ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env - # Check for existing .env - if [ -f "$ENV_FILE_DOCKER" ]; then - echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)" - OVERWRITE="" - # Ask to overwrite the .env files - while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do - read -p "Enter your choice : " OVERWRITE + function make_env_for_docker_and_svelte + { + echo "Creating a new environment for docker" + NODE_ENV="" + # Ask if dev or prod environment + while [ "$NODE_ENV" != "1" ] && [ "$NODE_ENV" != "2" ]; do + read -p "Enter the env configuration for nestjs : \"1\" for development OR \"2\" for production : " NODE_ENV done - if [ "$OVERWRITE" = "y" ]; then - rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE" - docker rmi -f postgres + if [ "$NODE_ENV" = "1" ]; then + echo "NODE_ENV=development" > "$ENV_FILE_DOCKER" else - cp "$ENV_FILE_DOCKER" "$ENV_FILE_SVELTE" - echo "The file $ENV_FILE_DOCKER and $ENV_FILE_SVELTE will not be overwritten. The script will exit." - exit 0 + echo "NODE_ENV=production" > "$ENV_FILE_DOCKER" fi - fi + read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST + echo "WEBSITE_HOST=$PROJECT_HOST" >> "$ENV_FILE_DOCKER" + echo "WEBSITE_PORT=8080" >> "$ENV_FILE_DOCKER" + echo "POSTGRES_USER=postgres" >> "$ENV_FILE_DOCKER" + echo "#if change postgres pswd, do make destroy" >> "$ENV_FILE_DOCKER" + echo "POSTGRES_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" + echo "POSTGRES_DB=transcendance_db" >> "$ENV_FILE_DOCKER" + echo "POSTGRES_HOST=postgresql" >> "$ENV_FILE_DOCKER" + echo "POSTGRES_PORT=5432" >> "$ENV_FILE_DOCKER" + echo "REDIS_HOST=redis" >> "$ENV_FILE_DOCKER" + echo "REDIS_PORT=6379" >> "$ENV_FILE_DOCKER" + echo "REDIS_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" + # Connection to 42 + echo "In the next steps, we'll need to enter the client secret and client id of the 42 api" + read -p "Enter the client id of the 42 api : " CLIENT_ID + echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER" + read -p "Enter the client secret of the 42 api : " CLIENT_SECRET + echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER" + FT_CALLBACK="http://\$WEBSITE_HOST:\$WEBSITE_PORT/api/v2/auth/redirect" + echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER" + # Other configs + echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" + echo "PORT=3000" >> "$ENV_FILE_DOCKER" + echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER" + echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" + sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE" + } + function choose_options_and_process { + if [ -f "$ENV_FILE_DOCKER" ]; then + echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)" + OVERWRITE="" + # Ask to overwrite the .env files + while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do + read -p "Enter your choice : " OVERWRITE + done + if [ "$OVERWRITE" = "y" ]; then + rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE" + docker rmi -f postgres + make_env_for_docker_and_svelte + else + if [ ! -f "$ENV_FILE_SVELTE" ]; then + sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE" + + fi + echo "The file $ENV_FILE_DOCKER will not be overwritten. The script will exit." + exit 0 + fi + fi + } # Create a new environment for docker - echo "Creating a new environment for docker" - NODE_ENV="" - # Ask if dev or prod environment - while [ "$NODE_ENV" != "1" ] && [ "$NODE_ENV" != "2" ]; do - read -p "Enter the env configuration for nestjs : \"1\" for development OR \"2\" for production : " NODE_ENV - done - if [ "$NODE_ENV" = "1" ]; then - echo "NODE_ENV=development" > "$ENV_FILE_DOCKER" - else - echo "NODE_ENV=production" > "$ENV_FILE_DOCKER" - fi - # Env variables - read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST - echo "WEBSITE_HOST=$PROJECT_HOST" >> "$ENV_FILE_DOCKER" - echo "WEBSITE_PORT=8080" >> "$ENV_FILE_DOCKER" - cp "$ENV_FILE_DOCKER" "$ENV_FILE_SVELTE" - echo "POSTGRES_USER=postgres" >> "$ENV_FILE_DOCKER" - echo "#if change postgres pswd, do make destroy" >> "$ENV_FILE_DOCKER" - echo "POSTGRES_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" - echo "POSTGRES_DB=transcendance_db" >> "$ENV_FILE_DOCKER" - echo "POSTGRES_HOST=postgresql" >> "$ENV_FILE_DOCKER" - echo "POSTGRES_PORT=5432" >> "$ENV_FILE_DOCKER" - echo "REDIS_HOST=redis" >> "$ENV_FILE_DOCKER" - echo "REDIS_PORT=6379" >> "$ENV_FILE_DOCKER" - echo "REDIS_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" - # Connection to 42 - echo "In the next steps, we'll need to enter the client secret and client id of the 42 api" - read -p "Enter the client id of the 42 api : " CLIENT_ID - echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER" - read -p "Enter the client secret of the 42 api : " CLIENT_SECRET - echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER" - FT_CALLBACK="http://\$WEBSITE_HOST:\$WEBSITE_PORT/api/v2/auth/redirect" - echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER" - # Other configs - echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" - echo "PORT=3000" >> "$ENV_FILE_DOCKER" - echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER" - echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" + choose_options_and_process - -# it's finished ! -# echo "The environment has been created successfully. You can now wait for the docker to build the project." diff --git a/srcs/requirements/svelte/.dockerignore b/srcs/requirements/svelte/.dockerignore index 29c9a005..836f34cf 100644 --- a/srcs/requirements/svelte/.dockerignore +++ b/srcs/requirements/svelte/.dockerignore @@ -8,3 +8,4 @@ !api_front/*.json !api_front/*.html !api_front/*.lock +!api_front/.env diff --git a/srcs/requirements/svelte/api_front/src/Constantes.ts b/srcs/requirements/svelte/api_front/src/Constantes.ts deleted file mode 100644 index e2ead3eb..00000000 --- a/srcs/requirements/svelte/api_front/src/Constantes.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const Domain = "transcendance"; -export const Port = "8080"; -export const PortIo = Port;