From c9b8aad459fca1557c72710ad10a78d573cb980d Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 9 May 2023 11:55:26 -0500 Subject: [PATCH] Add .env config --- .cpanel.yml | 33 --------------------------------- .env.example | 3 +++ .gitignore | 2 ++ deploy.sh | 24 ++++++------------------ package.json | 1 + pnpm-lock.yaml | 3 +++ src/app.module.ts | 6 +++--- src/main.ts | 3 +++ 8 files changed, 21 insertions(+), 54 deletions(-) delete mode 100644 .cpanel.yml create mode 100644 .env.example diff --git a/.cpanel.yml b/.cpanel.yml deleted file mode 100644 index c50ae5e..0000000 --- a/.cpanel.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -deployment: - tasks: - - export DEPLOY_PATH=/home4/educa7ls/staging.eegsac.com - # Install dependencies - - pnpm i --frozen-lockfile - # Build Nestjs - - pnpm build - # Build JSX files - - node ./esbuild-prod.js - # Build hydration script - - node ./esbuild-client-prod.js - # Build tailwind - - ./node_modules/.bin/tailwindcss -i static/tailwind.css -o ./static/styles.css --minify - - # Remove previous deployments - - rm -rf $DEPLOY_PATH/* - - # Move files to deploy path - - /bin/cp -r ./dist $DEPLOY_PATH - - /bin/cp -r ./static $DEPLOY_PATH - - /bin/cp ./package.json $DEPLOY_PATH - - /bin/cp ./pnpm-lock.yaml $DEPLOY_PATH - - /bin/cp ./.htaccess $DEPLOY_PATH - - # Remove build dependencies - - rm -rf ./node_modules - - # Install prod deps - - cd $DEPLOY_PATH - - pnpm i --frozen-lockfile --prod - - # Success?? diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..243096a --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +MY_SQL_USER=root +MY_SQL_PASSWORD=1234567890 +MY_SQL_DB=educa7ls diff --git a/.gitignore b/.gitignore index 173b685..09a2726 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ .rollup.cache +.env.production + # Logs logs *.log diff --git a/deploy.sh b/deploy.sh index c094e3b..32faf69 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,6 +1,8 @@ -export DEPLOY_PATH=/home4/educa7ls/staging.eegsac.com +# TO BE RUN IN LOCAL MACHINE, REMOTE CANNOT BUILD + + # Install dependencies -pnpm i --frozen-lockfile +pnpm i # Build Nestjs pnpm build # Build JSX files @@ -10,19 +12,5 @@ node ./esbuild-client-prod.js # Build tailwind ./node_modules/.bin/tailwindcss -i static/tailwind.css -o ./static/styles.css --minify -# Remove previous deployments -rm -rf $DEPLOY_PATH/* - -# Move files to deploy path -/bin/cp -r ./dist $DEPLOY_PATH -/bin/cp -r ./static $DEPLOY_PATH -/bin/cp ./package.json $DEPLOY_PATH -/bin/cp ./pnpm-lock.yaml $DEPLOY_PATH -/bin/cp ./.htaccess $DEPLOY_PATH - -# Remove build dependencies -rm -rf ./node_modules - -# Install prod deps -cd $DEPLOY_PATH -pnpm i --frozen-lockfile --prod \ No newline at end of file +# Send to remote +scp -r /home/mario/carpeta usuario@dominio.com:/home/usuario diff --git a/package.json b/package.json index 37cba4c..c77f1ed 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "axios": "^1.4.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", + "dotenv": "^16.0.3", "mysql2": "^3.2.4", "reflect-metadata": "^0.1.13", "rxjs": "^7.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ecf6e0..ed7fc83 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,9 @@ dependencies: class-validator: specifier: ^0.14.0 version: 0.14.0 + dotenv: + specifier: ^16.0.3 + version: 16.0.3 mysql2: specifier: ^3.2.4 version: 3.3.0 diff --git a/src/app.module.ts b/src/app.module.ts index a7736dc..147e228 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -16,9 +16,9 @@ import { SubjectService } from "./controller/subject/subject.service"; type: "mysql", host: "localhost", port: 3306, - username: "root", - password: "1234567890", - database: "educa7ls_plataforma", + username: process.env.MY_SQL_USER, + password: process.env.MY_SQL_PASSWORD, + database: process.env.MY_SQL_DB, entities: [ Persona, CursoGIE, diff --git a/src/main.ts b/src/main.ts index 00b2727..7404b86 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,9 @@ import { NestFactory } from "@nestjs/core"; import { AppModule } from "./app.module"; import * as express from "express"; import * as path from "path"; +import * as dotenv from "dotenv"; + +dotenv.config(); async function bootstrap() { const app = await NestFactory.create(AppModule);