From b20d6ec59ca03b41993d410208ec894af21e02e5 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Tue, 16 Nov 2021 06:12:22 +0500 Subject: [PATCH] chore: copy sas exe script extracted common --- DockerfileApi | 1 + api/src/utils/connectDB.ts | 6 +++++- docker-compose.yml | 1 + dockerSASexe.sh | 21 +++++++++++++++++++++ dockerStartDev.sh | 31 ++++--------------------------- dockerStartProd.sh | 31 ++++--------------------------- 6 files changed, 36 insertions(+), 55 deletions(-) create mode 100755 dockerSASexe.sh diff --git a/DockerfileApi b/DockerfileApi index aefb9e2..aa0b6e1 100644 --- a/DockerfileApi +++ b/DockerfileApi @@ -4,6 +4,7 @@ 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/src/utils/connectDB.ts b/api/src/utils/connectDB.ts index 660d727..0c36b2f 100644 --- a/api/src/utils/connectDB.ts +++ b/api/src/utils/connectDB.ts @@ -3,6 +3,7 @@ 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 @@ -18,10 +19,13 @@ export const connectDB = async () => { } else { const { SAS_EXEC } = process.env process.sasLoc = SAS_EXEC - ? path.join(__dirname, '..', '..', '...', 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') { diff --git a/docker-compose.yml b/docker-compose.yml index cc80121..4a80908 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ 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 new file mode 100755 index 0000000..8ae7c4c --- /dev/null +++ b/dockerSASexe.sh @@ -0,0 +1,21 @@ +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 index 774dd3f..ed8b0c4 100755 --- a/dockerStartDev.sh +++ b/dockerStartDev.sh @@ -1,29 +1,6 @@ -sasjsPath=$(grep sasPath ./api/package.json | sed 's/.*"sasPath": "\(.*\)".*/\1/') -if [ -z "$sasjsPath" ] -then - echo "Please enter path to SAS executable:" - read sasjsPath +# Copy SAS executable from source to current folder to make it available to docker +./dockerSASexe.sh -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. -cp $sasjsPath ./ - -# name of the sas executable file, placed at root of repository -sasjs=$(basename $sasjsPath) -echo "SAS Executable name:" $sasjs - -# build and run docker-compose -SAS_EXEC=$sasjs docker-compose up --build -d - -# remove copied sas executable -rm $sasjs \ No newline at end of file +# Run docker-compose with default docker compose file i.e. docker-compose.yml +# SAS_EXEC=sas_exe/sas docker-compose up -d diff --git a/dockerStartProd.sh b/dockerStartProd.sh index 5deb6d5..f58d4c8 100755 --- a/dockerStartProd.sh +++ b/dockerStartProd.sh @@ -1,29 +1,6 @@ -sasjsPath=$(grep sasPath ./api/package.json | sed 's/.*"sasPath": "\(.*\)".*/\1/') -if [ -z "$sasjsPath" ] -then - echo "Please enter path to SAS executable:" - read sasjsPath +# Copy SAS executable from source to current folder to make it available to docker +./dockerSASexe.sh -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. -cp $sasjsPath ./ - -# name of the sas executable file, placed at root of repository -sasjs=$(basename $sasjsPath) -echo "SAS Executable name:" $sasjs - -# build and run docker-compose -SAS_EXEC=$sasjs docker-compose -f docker-compose.prod.yml up --build -d - -# remove copied sas executable -rm $sasjs \ No newline at end of file +# 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