From d3fc227c4025c80f34c6b56d552176a85cd8ebf6 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Thu, 7 Jul 2022 20:35:00 +0100 Subject: [PATCH] refactor dashboard api. --- DashboardAPI/.greenlockrc | 1 - DashboardAPI/.nycrc.json | 4 -- DashboardAPI/Dockerfile | 5 +- DashboardAPI/Dockerfile.dev | 27 +++------ DashboardAPI/db-changes.md | 10 ---- DashboardAPI/package.json | 116 +++++++----------------------------- docker-compose.dev.yml | 58 ++++++++++-------- 7 files changed, 65 insertions(+), 156 deletions(-) delete mode 100644 DashboardAPI/.greenlockrc delete mode 100644 DashboardAPI/.nycrc.json delete mode 100755 DashboardAPI/db-changes.md diff --git a/DashboardAPI/.greenlockrc b/DashboardAPI/.greenlockrc deleted file mode 100644 index cd9961a46b..0000000000 --- a/DashboardAPI/.greenlockrc +++ /dev/null @@ -1 +0,0 @@ -{"manager":"oneuptime-gl-manager","configDir":"./greenlock.d"} \ No newline at end of file diff --git a/DashboardAPI/.nycrc.json b/DashboardAPI/.nycrc.json deleted file mode 100644 index d2b709eb3f..0000000000 --- a/DashboardAPI/.nycrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "include": "test", - "exclude": "backend" -} diff --git a/DashboardAPI/Dockerfile b/DashboardAPI/Dockerfile index 4e47767f60..9b76e5bc63 100755 --- a/DashboardAPI/Dockerfile +++ b/DashboardAPI/Dockerfile @@ -1,5 +1,5 @@ # -# OneUptime-backend Dockerfile +# OneUptime-DashboardAPI Dockerfile # # Pull base image nodejs image. @@ -41,9 +41,6 @@ RUN mkdir /usr/src/app WORKDIR /usr/src/app -# Install trivy for container scanning -RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sh -s -- -b /usr/local/bin - # Install app dependencies COPY ./DashboardAPI/package*.json /usr/src/app/ RUN npm install diff --git a/DashboardAPI/Dockerfile.dev b/DashboardAPI/Dockerfile.dev index 700a6790cc..11d0c810d5 100644 --- a/DashboardAPI/Dockerfile.dev +++ b/DashboardAPI/Dockerfile.dev @@ -1,5 +1,5 @@ # -# OneUptime-backend Dockerfile +# OneUptime-DashboardAPI Dockerfile # # Pull base image nodejs image. @@ -35,27 +35,18 @@ RUN npm install COPY ./CommonServer /usr/src/CommonServer RUN npm run compile -#SET ENV Variables - -WORKDIR /usr/src/app - -# Install trivy for container scanning -RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sh -s -- -b /usr/local/bin - +WORKDIR /usr/src/app/ # Install app dependencies -RUN cd /usr/src/app - -RUN mkdir -p greenlock.d || echo "Directory already exists" - -# Copy package.json files -COPY ./DashboardAPI/package.json /usr/src/app/package.json -COPY ./DashboardAPI/package-lock.json /usr/src/app/package-lock.json - - +COPY ./DashboardAPI/package*.json /usr/src/app/ RUN npm install +RUN npm install -g ts-node + + +# Bundle app source +COPY ./DashboardAPI /usr/src/app # Expose ports. -# - 3002: OneUptime-backend +# - 3002: OneUptime-DashboardAPI EXPOSE 3002 EXPOSE 9229 diff --git a/DashboardAPI/db-changes.md b/DashboardAPI/db-changes.md deleted file mode 100755 index cd85f4063c..0000000000 --- a/DashboardAPI/db-changes.md +++ /dev/null @@ -1,10 +0,0 @@ -# Changes to Production DB - -- Make current Project Admin to Project Owners. -- Add a default Sub Project to every Project. - -# ToDo: - -- Add Sub Projects in Alerts. -- Add Sub Projects in Incidents. -- Add Monitor name when you create incidents. diff --git a/DashboardAPI/package.json b/DashboardAPI/package.json index d5ac67587d..2620e208cc 100644 --- a/DashboardAPI/package.json +++ b/DashboardAPI/package.json @@ -1,98 +1,28 @@ { - "name": "oneuptime-backend", - "version": "3.0.0", - "private": false, - "type": "module", - "dependencies": { - "airtable": "^0.11.2", - "async-mutex": "^0.3.2", - "axios": "^0.26.1", - "bcrypt": "^5.0.1", - "body-parser": "^1.19.2", - "cheerio": "^1.0.0-rc.10", - "CommonServer": "file:../CommonServer", - "Common": "file:../Common", - "cors": "^2.8.5", - "cross-env": "^7.0.3", - "crypto-js": "^4.1.1", - "dotenv": "^16.0.0", - "date-fns": "^2.28.0", - "dompurify": "^2.3.6", - "ejs": "^3.1.6", - "express": "^4.17.3", - "express-rate-limit": "^6.3.0", - "express-request-id": "^2.0.1", - "geoip-lite": "^1.4.4", - "greenlock": "^4.0.4", - "gridfs-stream": "^1.1.1", - "ipaddr.js": "^2.0.1", - "iplocation": "^7.2.0", - "js-base64": "^3.7.2", - "jsdom": "^19.0.0", - "jsonwebtoken": "^8.5.1", - "jstoxml": "^3.2.0", - "lodash": "^4.17.21", - "moment": "^2.29.2", - "moment-timezone": "^0.5.34", - "mongoose": "^6.2.7", - "morgan": "^1.10.0", - "multer": "^1.4.4", - "multer-gridfs-storage": "^5.0.2", - "nanoid": "^3.3.1", - "node-cron": "^3.0.0", - "node-device-detector": "^1.4.4", - "node-html-parser": "^5.3.3", - "nodemailer": "^6.7.3", - "nodemailer-express-handlebars": "^5.0.0", - "oneuptime-acme-http-01": "^4.0.43", - "oneuptime-gl-manager": "^4.0.43", - "oneuptime-le-store": "^4.0.43", - "otplib": "^12.0.1", - "p-iteration": "^1.1.8", - "psl": "^1.8.0", - "query-string": "^7.1.1", - "rand-token": "^1.0.1", - "rate-limit-redis": "^3.0.1", - "redis": "^4.0.4", - "request": "^2.88.2", - "saml2-js": "^3.0.1", - "slugify": "^1.6.5", - "socket.io": "^4.4.1", - "socket.io-redis": "^6.1.1", - "speakeasy": "^2.0.0", - "stripe": "^8.210.0", - "twilio": "^3.75.1", - "urldecode": "^1.0.1", - "uuid": "^8.3.2", - "valid-url": "^1.0.9", - "vm2": "^3.9.9", - "web-push": "^3.4.5", - "winston": "^3.6.0", - "winston-logstash-transport": "^2.0.0", - "winston-slack-webhook-transport": "^2.1.0" - }, + "name": "dashboard-api", + "version": "1.0.0", + "description": "", + "main": "index.js", "scripts": { - "start": "ts-node Index.ts", - "compile": "tsc", - "dev": "nodemon", - "test": "nyc --reporter=lcov --reporter=text mocha --exit test/index.ts", - "enterprise-test": "IS_TESTING=true nyc --reporter=lcov --reporter=text mocha --exit test/enterprise.js", - "audit": "npm audit --audit-level=low", - "preinstall": "npx npm-force-resolutions || echo 'No package-lock.json file. Skipping force resolutions'", - "dep-check": "depcheck ./ --skip-missing=true --ignores='ejs,oneuptime-acme-http-01,oneuptime-gl-manager,oneuptime-le-store'" + "start": "ts-node Index.ts", + "compile": "tsc", + "dev": "nodemon", + "audit": "npm audit --audit-level=low", + "dep-check": "depcheck ./ --skip-missing=true", + "test": "jest" + }, + "author": "", + "license": "ISC", + "dependencies": { + "Common": "file:../Common", + "CommonServer": "file:../CommonServer", + "ejs": "^3.1.8" }, "devDependencies": { - "chai": "^4.3.6", - "chai-http": "^4.3.0", - "chai-subset": "^1.6.0", - "depcheck": "^1.4.3", - "mocha": "^9.2.2", - "npm-force-resolutions": "0.0.10", - "nyc": "^15.1.0", - "sinon": "^13.0.1", - "ts-node-dev": "^1.1.8" - }, - "resolutions": { - "xml-crypto": "2.0.0" + "@types/jest": "^27.5.0", + "@types/node": "^17.0.31", + "jest": "^28.1.0", + "ts-jest": "^28.0.2" } -} \ No newline at end of file + } + \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0a80d2ae71..8123a55357 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -314,32 +314,38 @@ services: # - /usr/src/CommonUI/node_modules/ # - /usr/src/CommonServer/node_modules/ - # dashboard-api: - # ports: - # - '3002:3002' # Service Port. - # - '9232:9229' # Debugging port. - # build: - # network: host - # context: . - # dockerfile: ./DashboardAPI/Dockerfile.dev - # env_file: - # - ./Common/.env - # - ./CommonServer/.env - # - ./DashboardAPI/.env - # environment: *common-variables - # depends_on: - # - redis - # volumes: - # - ./DashboardAPI:/usr/src/app - # # Use node modules of the container and not host system. - # # https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder - # - /usr/src/app/node_modules/ - # - ./Common:/usr/src/Common - # - ./CommonServer:/usr/src/CommonServer - # - ./CommonUI:/usr/src/CommonUI - # - /usr/src/Common/node_modules/ - # - /usr/src/CommonUI/node_modules/ - # - /usr/src/CommonServer/node_modules/ + dashboard-api: + ports: + - '3002:3002' + - '9232:9229' # Debugging port. + build: + network: host + context: . + dockerfile: ./DashboardAPI/Dockerfile.dev + env_file: + - ./Common/.env + - ./CommonServer/.env + - ./DashboardAPI/.env + environment: *common-variables + depends_on: + - redis + - postgres + - mail + links: + - redis + - postgres + - mail + volumes: + - ./DashboardAPI:/usr/src/app + # Use node modules of the container and not host system. + # https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder + - /usr/src/app/node_modules/ + - ./Common:/usr/src/Common + - ./CommonServer:/usr/src/CommonServer + - ./CommonUI:/usr/src/CommonUI + - /usr/src/Common/node_modules/ + - /usr/src/CommonUI/node_modules/ + - /usr/src/CommonServer/node_modules/ identity: ports: