Skip to content

Commit

Permalink
feat(version): push version 3.5 to Github
Browse files Browse the repository at this point in the history
  • Loading branch information
Boudaya committed Mar 15, 2024
1 parent 333d698 commit 2ed174c
Show file tree
Hide file tree
Showing 72 changed files with 722 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=raw,value=3.4
tags: type=raw,value=3.5
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
Expand Down
30 changes: 10 additions & 20 deletions EcoSonar-API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See : https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
FROM node:16-slim
FROM node:18-slim

# Uncomment if you need to configure proxy.
# Uncomment if you need to configure proxy.
# You can init these variables by using --build-args during docker build
# Example : docker build [...] --build-args http_proxy=http://<user>:<password>@<host>:<port>
#ENV HTTP_PROXY=$http_proxy
Expand All @@ -13,37 +13,27 @@ RUN apt-get update \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg \
fonts-kacst fonts-freefont-ttf libxss1 gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 \
libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget\
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libx11-xcb1 libnss3-tools curl \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Bundle app source
COPY . .

# Uncomment if you need to configure proxy.
#RUN npm config set proxy $HTTP_PROXY
# Uncomment if you need to configure proxy.
#RUN npm config set proxy $HTTP_PROXY

# If you are building your code for production
# RUN npm ci --only=production
# otherwise run npm install
RUN npm install \
RUN npm i \
&& npm link \
&& groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /app/

USER pptruser

# To avoid "Error: ENOENT: no such file or directory, open '/app/dist/bundle.js'"
RUN npm i
# To avoid "Error: ENOENT: no such file or directory, open '/app/dist/greenItBundle.js'"
RUN npm i \
&& node node_modules/puppeteer/install.mjs

ENV PORT=3000
EXPOSE 3000
Expand Down
6 changes: 3 additions & 3 deletions EcoSonar-API/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const concat = require('concat-files')
const glob = require('glob')
const fs = require('fs')
import concat from 'concat-files'
import { glob } from 'glob'
import fs from 'fs'

const DIR = './services/greenit-analysis/dist'

Expand Down
18 changes: 7 additions & 11 deletions EcoSonar-API/configuration/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require('mongoose')
const { retrievePassword } = require('./retrieveDatabasePasswordFromCloudProvider')
import mongoose from 'mongoose'
import retrievePassword from './retrieveDatabasePasswordFromCloudProvider.js'

mongoose.set('strictQuery', false)

Expand All @@ -18,9 +18,8 @@ Database.prototype.connection = async function () {
const port = process.env.ECOSONAR_ENV_DB_PORT || 27017
dbName = process.env.ECOSONAR_ENV_DB_NAME || ''
connectionString = `mongodb://${cluster}:${port}/${dbName}`
mongoose.connect(connectionString,
{ useNewUrlParser: true, useUnifiedTopology: true }
).then(() => console.log('Connection to MongoDB successful'))
mongoose.connect(connectionString)
.then(() => console.log('Connection to MongoDB successful'))
.catch((reason) => console.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
} else if (mongoDBType === 'MongoDB_Atlas') {
// connection to dataBase MongoDB Atlas for MongoDB API
Expand All @@ -29,9 +28,8 @@ Database.prototype.connection = async function () {
cluster = process.env.ECOSONAR_ENV_CLUSTER || ''
dbName = process.env.ECOSONAR_ENV_DB_NAME || ''
connectionString = `mongodb+srv://${user}:${password}@${cluster}/${dbName}?retryWrites=true&w=majority`
mongoose.connect(connectionString,
{ useNewUrlParser: true, useUnifiedTopology: true }
).then(() => console.log('Connection to MongoDB Atlas successful'))
mongoose.connect(connectionString)
.then(() => console.log('Connection to MongoDB Atlas successful'))
.catch((reason) => console.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
} else if (mongoDBType === 'CosmosDB') {
// connection to dataBase Azure CosmosDB for MongoDB API
Expand All @@ -46,8 +44,6 @@ Database.prototype.connection = async function () {
username: user,
password
},
useNewUrlParser: true,
useUnifiedTopology: true,
retryWrites: false
})
.then(() => console.log('Connection to CosmosDB successful'))
Expand All @@ -58,4 +54,4 @@ Database.prototype.connection = async function () {
}

const database = new Database()
module.exports = database
export default database
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { DefaultAzureCredential } = require('@azure/identity')
const { SecretClient } = require('@azure/keyvault-secrets')
import { DefaultAzureCredential } from '@azure/identity'
import { SecretClient } from '@azure/keyvault-secrets'

async function retrievePassword () {
export default async function retrievePassword () {
if (process.env.ECOSONAR_ENV_CLOUD_PROVIDER === 'AZURE') {
return retrievePasswordFromAzure()
} else if (process.env.ECOSONAR_ENV_CLOUD_PROVIDER === 'local') {
Expand All @@ -23,5 +23,3 @@ async function retrievePasswordFromAzure () {
const retrievedSecret = await client.getSecret(secretName)
return retrievedSecret.value
}

module.exports = { retrievePassword }
6 changes: 3 additions & 3 deletions EcoSonar-API/dataBase/bestPracticesRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const bestpractices = require('./models/bestpractices')
const SystemError = require('../utils/SystemError')
import bestpractices from './models/bestpractices.js'
import SystemError from '../utils/SystemError.js'

const BestPracticesRepository = function () {
/**
Expand Down Expand Up @@ -151,4 +151,4 @@ function replaceDotWithUnderscoreInKeys (obj) {
}

const bestPracticesRepository = new BestPracticesRepository()
module.exports = bestPracticesRepository
export default bestPracticesRepository
8 changes: 4 additions & 4 deletions EcoSonar-API/dataBase/greenItRepository.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const greenits = require('./models/greenits')
const urlsprojects = require('./models/urlsprojects')
const SystemError = require('../utils/SystemError')
import greenits from './models/greenits.js'
import urlsprojects from './models/urlsprojects.js'
import SystemError from '../utils/SystemError.js'

const GreenItRepository = function () {
/**
Expand Down Expand Up @@ -162,4 +162,4 @@ async function checkValues (arrayToInsert) {
}

const greenItRepository = new GreenItRepository()
module.exports = greenItRepository
export default greenItRepository
6 changes: 3 additions & 3 deletions EcoSonar-API/dataBase/lighthouseRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const lighthouses = require('./models/lighthouses')
const SystemError = require('../utils/SystemError')
import lighthouses from './models/lighthouses.js'
import SystemError from '../utils/SystemError.js'

const LighthouseRepository = function () {
/**
Expand Down Expand Up @@ -176,4 +176,4 @@ const LighthouseRepository = function () {
}

const lighthouseRepository = new LighthouseRepository()
module.exports = lighthouseRepository
export default lighthouseRepository
10 changes: 2 additions & 8 deletions EcoSonar-API/dataBase/models/bestpractices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const bestPracticesSchema = new Schema({
Expand Down Expand Up @@ -226,12 +226,6 @@ const bestPracticesSchema = new Schema({
description: { type: Array },
auditedMetric: { type: Number }
},
preloadLcpImage: {
score: { type: Number },
scoreDisplayMode: { type: String },
description: { type: Array },
auditedMetric: { type: Number }
},
domSize: {
score: { type: Number },
scoreDisplayMode: { type: String },
Expand Down Expand Up @@ -627,4 +621,4 @@ const bestPracticesSchema = new Schema({
})

const bestPractices = mongoose.model('bestpractices', bestPracticesSchema)
module.exports = bestPractices
export default bestPractices
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/greenits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const greenItSchema = new Schema({
Expand Down Expand Up @@ -42,4 +42,4 @@ const greenItSchema = new Schema({
})

const greenIt = mongoose.model('greenits', greenItSchema)
module.exports = greenIt
export default greenIt
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/lighthouses.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const lighthouseSchema = new Schema({
Expand Down Expand Up @@ -122,4 +122,4 @@ const lighthouseSchema = new Schema({
})

const lighthouse = mongoose.model('lighthouses', lighthouseSchema)
module.exports = lighthouse
export default lighthouse
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const projectsSchema = new Schema({
Expand All @@ -24,4 +24,4 @@ const projectsSchema = new Schema({
})

const project = mongoose.model('projects', projectsSchema)
module.exports = project
export default project
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/tempurlsproject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const tempUrlsProjectSchema = new Schema({
Expand All @@ -16,4 +16,4 @@ const tempUrlsProjectSchema = new Schema({
})

const tempurlsProject = mongoose.model('tempurlsprojects', tempUrlsProjectSchema)
module.exports = tempurlsProject
export default tempurlsProject
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/urlsprojects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const urlsProjectSchema = new Schema({
Expand All @@ -22,4 +22,4 @@ const urlsProjectSchema = new Schema({
})

const urlsProject = mongoose.model('urlsprojects', urlsProjectSchema)
module.exports = urlsProject
export default urlsProject
4 changes: 2 additions & 2 deletions EcoSonar-API/dataBase/models/w3cs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
import mongoose from 'mongoose'
const Schema = mongoose.Schema

const w3cSchema = new Schema({
Expand All @@ -14,4 +14,4 @@ const w3cSchema = new Schema({
})

const w3cs = mongoose.model('w3cs', w3cSchema)
module.exports = w3cs
export default w3cs
30 changes: 15 additions & 15 deletions EcoSonar-API/dataBase/projectsRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const projects = require('./models/projects')
const SystemError = require('../utils/SystemError')
import projects from './models/projects.js'
import SystemError from '../utils/SystemError.js'

const ProjectsRepository = function () {
/**
Expand All @@ -9,7 +9,7 @@ const ProjectsRepository = function () {
*/
this.createProcedure = function (projectName, procedure) {
return new Promise((resolve, reject) => {
projects.create({ projectName, procedure })
projects.create({ projectName: { $eq: projectName }, procedure })
.then(() => { resolve() })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -28,7 +28,7 @@ const ProjectsRepository = function () {
*/
this.updateProjectProcedure = async function (projectName, selectedProcedure) {
return new Promise((resolve, reject) => {
projects.updateOne({ projectName }, { procedure: selectedProcedure })
projects.updateOne({ projectName: { $eq: projectName } }, selectedProcedure)
.then(() => {
resolve()
})
Expand All @@ -50,7 +50,7 @@ const ProjectsRepository = function () {
this.createLoginConfiguration = async function (projectName, loginCredentials) {
const loginMap = (loginCredentials !== undefined && loginCredentials !== null) ? new Map(Object.entries(loginCredentials)) : {}
return new Promise((resolve, reject) => {
projects.create({ projectName, login: loginMap })
projects.create({ projectName: { $eq: projectName }, login: loginMap })
.then(() => { resolve() })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -66,7 +66,7 @@ const ProjectsRepository = function () {
*/
this.createProxyConfiguration = async function (projectName, proxy) {
return new Promise((resolve, reject) => {
projects.create({ projectName, proxy })
projects.create({ projectName: { $eq: projectName }, proxy })
.then(() => { resolve() })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -83,7 +83,7 @@ const ProjectsRepository = function () {
this.updateLoginConfiguration = async function (projectName, loginCredentials) {
const loginMap = new Map(Object.entries(loginCredentials))
return new Promise((resolve, reject) => {
projects.updateOne({ projectName }, { login: loginMap })
projects.updateOne({ projectName: { $eq: projectName } }, { login: loginMap })
.then(() => { resolve() })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -99,7 +99,7 @@ const ProjectsRepository = function () {
*/
this.updateProxyConfiguration = async function (projectName, proxy) {
return new Promise((resolve, reject) => {
projects.updateOne({ projectName }, { proxy })
projects.updateOne({ projectName: { $eq: projectName } }, { proxy })
.then(() => { resolve() })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -115,7 +115,7 @@ const ProjectsRepository = function () {
*/
this.getProjectSettings = async function (projectName) {
return new Promise((resolve, reject) => {
projects.findOne({ projectName }, { login: 1, procedure: 1, proxy: 1 })
projects.findOne({ projectName: { $eq: projectName } }, { login: 1, procedure: 1, proxy: 1 })

This comment has been minimized.

Copy link
@GloupGloup

GloupGloup Jun 3, 2024

This update causes issue with docker mongo:7.0.11 when using the API POST "/api/login/insert?projectName=ecosonar" :
ecosonar_api | ValidationError: projectName: Cast to string failed for value "{ '$eq': 'ecosonar' }" (type Object) at path "projectName"

.then((result) => {
resolve(result)
})
Expand All @@ -136,9 +136,9 @@ const ProjectsRepository = function () {
let systemError = false
try {
if (procedureRegistered !== undefined || proxyRegistered.ipAddress !== undefined || proxyRegistered.port !== undefined) {
await projects.updateOne({ projectName: projectNameReq }, { $unset: { login: '' } })
await projects.updateOne({ projectName: { $eq: projectNameReq } }, { $unset: { login: '' } })
} else {
await projects.deleteOne({ projectName: projectNameReq })
await projects.deleteOne({ projectName: { $eq: projectNameReq } })
}
} catch (error) {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -163,9 +163,9 @@ const ProjectsRepository = function () {
let systemError = false
try {
if (procedureRegistered !== undefined || loginRegistered !== undefined) {
await projects.updateOne({ projectName: projectNameReq }, { $unset: { proxy: '', ipAddress: '', port: '' } })
await projects.updateOne({ projectName: { $eq: projectNameReq } }, { $unset: { proxy: '', ipAddress: '', port: '' } })
} else {
await projects.deleteOne({ projectName: projectNameReq })
await projects.deleteOne({ projectName: { $eq: projectNameReq } })
}
} catch (error) {
console.error('\x1b[31m%s\x1b[0m', error)
Expand All @@ -186,7 +186,7 @@ const ProjectsRepository = function () {
*/
this.deleteProjectPerProjectName = async function (projectNameReq) {
return new Promise((resolve, reject) => {
projects.deleteOne({ projectName: projectNameReq })
projects.deleteOne({ projectName: { $eq: projectNameReq } })
.then(() => {
console.log(`DELETE URLS PROJECT - project ${projectNameReq} deleted`)
resolve()
Expand All @@ -199,4 +199,4 @@ const ProjectsRepository = function () {
}

const projectsRepository = new ProjectsRepository()
module.exports = projectsRepository
export default projectsRepository
Loading

1 comment on commit 2ed174c

@sboudaya
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you for your contribution. We have released a version (3.6) which fixed all the issues concerning the Cast to string exception.

Please sign in to comment.