mirror of
https://github.com/sasjs/server.git
synced 2026-01-14 17:30:05 +00:00
chore: provide sas executable to docker
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ build/
|
|||||||
certificates/
|
certificates/
|
||||||
executables/
|
executables/
|
||||||
.env
|
.env
|
||||||
|
sas
|
||||||
@@ -79,7 +79,6 @@
|
|||||||
"typescript": "^4.3.2"
|
"typescript": "^4.3.2"
|
||||||
},
|
},
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"sasPath": "/opt/sas/sas9/SASHome/SASFoundation/9.4/sas",
|
"sasPath": "/opt/sas/sas9/SASHome/SASFoundation/9.4/sas"
|
||||||
"sasJsPort": 5000
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import cors from 'cors'
|
|||||||
|
|
||||||
import webRouter from './routes/web'
|
import webRouter from './routes/web'
|
||||||
import apiRouter from './routes/api'
|
import apiRouter from './routes/api'
|
||||||
import { getWebBuildFolderPath } from './utils'
|
import { connectDB, getWebBuildFolderPath } from './utils'
|
||||||
import { connectDB } from './routes/api/auth'
|
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { Session } from '../../types'
|
import { Session } from '../../types'
|
||||||
import { configuration } from '../../../package.json'
|
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { execFile } from 'child_process'
|
import { execFile } from 'child_process'
|
||||||
import { getTmpSessionsFolderPath, generateUniqueFileName } from '../../utils'
|
import { getTmpSessionsFolderPath, generateUniqueFileName } from '../../utils'
|
||||||
@@ -65,8 +64,8 @@ export class SessionController {
|
|||||||
// update the session array to say that it is currently running
|
// update the session array to say that it is currently running
|
||||||
// however we also need a promise so that we can update the
|
// however we also need a promise so that we can update the
|
||||||
// session array to say that it has (eventually) finished.
|
// session array to say that it has (eventually) finished.
|
||||||
const sasLoc = process.sasLoc ?? configuration.sasPath
|
|
||||||
execFilePromise(sasLoc, [
|
execFilePromise(process.sasLoc, [
|
||||||
'-SYSIN',
|
'-SYSIN',
|
||||||
codePath,
|
codePath,
|
||||||
'-LOG',
|
'-LOG',
|
||||||
@@ -84,7 +83,7 @@ export class SessionController {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
session.completed = true
|
session.completed = true
|
||||||
session.crashed = err.toString()
|
session.crashed = err.toString()
|
||||||
console.log('session crashed', session.id, err)
|
console.log('session crashed', session.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
// we have a triggered session - add to array
|
// we have a triggered session - add to array
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import mongoose from 'mongoose'
|
|
||||||
|
|
||||||
import { AuthController } from '../../controllers/'
|
import { AuthController } from '../../controllers/'
|
||||||
import Client from '../../model/Client'
|
import Client from '../../model/Client'
|
||||||
@@ -28,32 +27,6 @@ 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) => {
|
authRouter.post('/authorize', async (req, res) => {
|
||||||
const { error, value: body } = authorizeValidation(req.body)
|
const { error, value: body } = authorizeValidation(req.body)
|
||||||
if (error) return res.status(400).send(error.details[0].message)
|
if (error) return res.status(400).send(error.details[0].message)
|
||||||
|
|||||||
2
api/src/types/Process.d.ts
vendored
2
api/src/types/Process.d.ts
vendored
@@ -1,6 +1,6 @@
|
|||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
export interface Process {
|
export interface Process {
|
||||||
sasLoc?: string
|
sasLoc: string
|
||||||
driveLoc?: string
|
driveLoc?: string
|
||||||
sessionController?: import('../controllers/internal').SessionController
|
sessionController?: import('../controllers/internal').SessionController
|
||||||
}
|
}
|
||||||
|
|||||||
36
api/src/utils/connectDB.ts
Normal file
36
api/src/utils/connectDB.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import path from 'path'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
import { configuration } from '../../package.json'
|
||||||
|
import { getDesktopFields } from '.'
|
||||||
|
import { populateClients } from '../routes/api/auth'
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from './connectDB'
|
||||||
export * from './file'
|
export * from './file'
|
||||||
export * from './generateAccessToken'
|
export * from './generateAccessToken'
|
||||||
export * from './generateAuthCode'
|
export * from './generateAuthCode'
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ services:
|
|||||||
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
||||||
AUTH_CODE_SECRET: ${AUTH_CODE_SECRET}
|
AUTH_CODE_SECRET: ${AUTH_CODE_SECRET}
|
||||||
DB_CONNECT: mongodb://mongodb:27017/sasjs
|
DB_CONNECT: mongodb://mongodb:27017/sasjs
|
||||||
|
SAS_EXEC: ${SAS_EXEC}
|
||||||
expose:
|
expose:
|
||||||
- ${PORT_API}
|
- ${PORT_API}
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
23
startProduction.sh
Executable file
23
startProduction.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
sasjsPath=$(grep sasPath 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
|
||||||
|
|
||||||
|
cp $sasjsPath ./
|
||||||
|
sasjs=$(basename $sasjsPath)
|
||||||
|
|
||||||
|
echo "SAS Executable name:" $sasjs
|
||||||
|
|
||||||
|
SAS_EXEC=$sasjs docker-compose -f docker-compose.prod.yml up --build -d
|
||||||
Reference in New Issue
Block a user