From 455367f10a0f24aad7990d8ce823ddff55bbc5b2 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Wed, 17 Nov 2021 07:49:02 +0500 Subject: [PATCH] chore: reverted 4 commits related to copying exe scripts --- .gitignore | 1 - DockerfileApi | 1 - api/package.json | 3 +- api/src/app.ts | 3 +- api/src/controllers/internal/Session.ts | 7 +++-- api/src/routes/api/auth.ts | 27 +++++++++++++++++ api/src/types/Process.d.ts | 2 +- api/src/utils/connectDB.ts | 40 ------------------------- api/src/utils/index.ts | 1 - docker-compose.prod.yml | 1 - docker-compose.yml | 1 - dockerSASexe.sh | 21 ------------- dockerStartDev.sh | 6 ---- dockerStartProd.sh | 6 ---- 14 files changed, 36 insertions(+), 84 deletions(-) delete mode 100644 api/src/utils/connectDB.ts delete mode 100755 dockerSASexe.sh delete mode 100755 dockerStartDev.sh delete mode 100755 dockerStartProd.sh diff --git a/.gitignore b/.gitignore index 0457868..4fe91fa 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ build/ certificates/ executables/ .env -sas \ No newline at end of file diff --git a/DockerfileApi b/DockerfileApi index aa0b6e1..aefb9e2 100644 --- a/DockerfileApi +++ b/DockerfileApi @@ -4,7 +4,6 @@ COPY ["package.json","package-lock.json", "./"] RUN npm ci COPY ./api . COPY ./certificates ../certificates -COPY ./sas_exe ../sas_exe # RUN chown -R node /usr/server/api # USER node CMD ["npm","start"] diff --git a/api/package.json b/api/package.json index 4278c44..bd25b43 100644 --- a/api/package.json +++ b/api/package.json @@ -79,6 +79,7 @@ "typescript": "^4.3.2" }, "configuration": { - "sasPath": "/opt/sas/sas9/SASHome/SASFoundation/9.4/sas" + "sasPath": "/opt/sas/sas9/SASHome/SASFoundation/9.4/sas", + "sasJsPort": 5000 } } diff --git a/api/src/app.ts b/api/src/app.ts index 6879eff..1b78f2f 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -6,7 +6,8 @@ import cors from 'cors' import webRouter from './routes/web' import apiRouter from './routes/api' -import { connectDB, getWebBuildFolderPath } from './utils' +import { getWebBuildFolderPath } from './utils' +import { connectDB } from './routes/api/auth' dotenv.config() diff --git a/api/src/controllers/internal/Session.ts b/api/src/controllers/internal/Session.ts index 56a6e58..c25daf5 100644 --- a/api/src/controllers/internal/Session.ts +++ b/api/src/controllers/internal/Session.ts @@ -1,5 +1,6 @@ import path from 'path' import { Session } from '../../types' +import { configuration } from '../../../package.json' import { promisify } from 'util' import { execFile } from 'child_process' import { getTmpSessionsFolderPath, generateUniqueFileName } from '../../utils' @@ -64,8 +65,8 @@ export class SessionController { // update the session array to say that it is currently running // however we also need a promise so that we can update the // session array to say that it has (eventually) finished. - - execFilePromise(process.sasLoc, [ + const sasLoc = process.sasLoc ?? configuration.sasPath + execFilePromise(sasLoc, [ '-SYSIN', codePath, '-LOG', @@ -83,7 +84,7 @@ export class SessionController { .catch((err) => { session.completed = true session.crashed = err.toString() - console.log('session crashed', session.id) + console.log('session crashed', session.id, err) }) // we have a triggered session - add to array diff --git a/api/src/routes/api/auth.ts b/api/src/routes/api/auth.ts index df359bc..32929ef 100644 --- a/api/src/routes/api/auth.ts +++ b/api/src/routes/api/auth.ts @@ -1,4 +1,5 @@ import express from 'express' +import mongoose from 'mongoose' import { AuthController } from '../../controllers/' import Client from '../../model/Client' @@ -27,6 +28,32 @@ export const populateClients = async () => { }) } +export const connectDB = async () => { + const { MODE } = process.env + if (MODE?.trim() !== 'server') { + console.log('Running in Destop Mode, no DB to connect.') + + const { sasLoc, driveLoc } = await getDesktopFields() + + process.sasLoc = sasLoc + process.driveLoc = driveLoc + + return + } + + // NOTE: when exporting app.js as agent for supertest + // we should exlcude connecting to the real database + if (process.env.NODE_ENV !== 'test') { + mongoose.connect(process.env.DB_CONNECT as string, async (err) => { + if (err) throw err + + console.log('Connected to db!') + + await populateClients() + }) + } +} + authRouter.post('/authorize', async (req, res) => { const { error, value: body } = authorizeValidation(req.body) if (error) return res.status(400).send(error.details[0].message) diff --git a/api/src/types/Process.d.ts b/api/src/types/Process.d.ts index dbd7f0f..f90ae02 100644 --- a/api/src/types/Process.d.ts +++ b/api/src/types/Process.d.ts @@ -1,6 +1,6 @@ declare namespace NodeJS { export interface Process { - sasLoc: string + sasLoc?: string driveLoc?: string sessionController?: import('../controllers/internal').SessionController } diff --git a/api/src/utils/connectDB.ts b/api/src/utils/connectDB.ts deleted file mode 100644 index 0c36b2f..0000000 --- a/api/src/utils/connectDB.ts +++ /dev/null @@ -1,40 +0,0 @@ -import path from 'path' -import mongoose from 'mongoose' -import { configuration } from '../../package.json' -import { getDesktopFields } from '.' -import { populateClients } from '../routes/api/auth' -import { fileExists } from '@sasjs/utils' - -export const connectDB = async () => { - const { MODE } = process.env - if (MODE?.trim() !== 'server') { - console.log('Running in Destop Mode, no DB to connect.') - - const { sasLoc, driveLoc } = await getDesktopFields() - - process.sasLoc = sasLoc - process.driveLoc = driveLoc - - return - } else { - const { SAS_EXEC } = process.env - process.sasLoc = SAS_EXEC - ? path.join(__dirname, '..', '..', '..', SAS_EXEC) - : configuration.sasPath - } - - console.log('SAS_EXEC: ', process.sasLoc) - console.log('SAS_EXEC Exists: ', await fileExists(process.sasLoc)) - - // NOTE: when exporting app.js as agent for supertest - // we should exlcude connecting to the real database - if (process.env.NODE_ENV !== 'test') { - mongoose.connect(process.env.DB_CONNECT as string, async (err) => { - if (err) throw err - - console.log('Connected to db!') - - await populateClients() - }) - } -} diff --git a/api/src/utils/index.ts b/api/src/utils/index.ts index 3cf1039..ade03b5 100644 --- a/api/src/utils/index.ts +++ b/api/src/utils/index.ts @@ -1,4 +1,3 @@ -export * from './connectDB' export * from './file' export * from './generateAccessToken' export * from './generateAuthCode' diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 6934523..c809b32 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -14,7 +14,6 @@ services: REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET} AUTH_CODE_SECRET: ${AUTH_CODE_SECRET} DB_CONNECT: mongodb://mongodb:27017/sasjs - SAS_EXEC: ${SAS_EXEC} expose: - ${PORT_API} ports: diff --git a/docker-compose.yml b/docker-compose.yml index 4a80908..cc80121 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,6 @@ services: REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET} AUTH_CODE_SECRET: ${AUTH_CODE_SECRET} DB_CONNECT: mongodb://mongodb:27017/sasjs - SAS_EXEC: ${SAS_EXEC} expose: - ${PORT_API} ports: diff --git a/dockerSASexe.sh b/dockerSASexe.sh deleted file mode 100755 index 8ae7c4c..0000000 --- a/dockerSASexe.sh +++ /dev/null @@ -1,21 +0,0 @@ -sasjsPath=$(grep sasPath ./api/package.json | sed 's/.*"sasPath": "\(.*\)".*/\1/') - -if [ -z "$sasjsPath" ] -then - echo "Please enter path to SAS executable:" - read sasjsPath - -fi - -if [ -e $sasjsPath ] -then - echo "Using sas executable:" \"$sasjsPath\" -else - echo "No file present at:" \"$sasjsPath\" - exit 1 -fi - -# copy sas executable to current directory, because docker cannot copy files outside of context. -rm -rf sas_exe -mkdir sas_exe -cp $sasjsPath ./sas_exe/sas \ No newline at end of file diff --git a/dockerStartDev.sh b/dockerStartDev.sh deleted file mode 100755 index fff9a8c..0000000 --- a/dockerStartDev.sh +++ /dev/null @@ -1,6 +0,0 @@ - -# Copy SAS executable from source to current folder to make it available to docker -./dockerSASexe.sh - -# Run docker-compose with default docker compose file i.e. docker-compose.yml -SAS_EXEC=sas_exe/sas docker-compose up --build -d diff --git a/dockerStartProd.sh b/dockerStartProd.sh deleted file mode 100755 index cb93455..0000000 --- a/dockerStartProd.sh +++ /dev/null @@ -1,6 +0,0 @@ - -# Copy SAS executable from source to current folder to make it available to docker -./dockerSASexe.sh - -# Build & Run docker-compose with docker compose file i.e. docker-compose.prod.yml -SAS_EXEC=sas_exe/sas docker-compose -f docker-compose.prod.yml up --build -d