Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

ci: install xvfb on the machine and start it with pm2 #605

Draft
wants to merge 22 commits into
base: daily
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b3b4dd8
chore(guardoni): define docker image (#550)
chobeat Jul 6, 2022
6ef5b16
fix(tktrex): use new logo in extension popup (#584)
ascariandrea Jul 6, 2022
e084754
fix(guardoni): add standard chrome path for macOS (#585)
ascariandrea Jul 6, 2022
54aaed0
chore: upgrade eslint deps
ascariandrea Jul 6, 2022
b787730
chore: upgrade webpack-dev-server, ts-loader and filemanager-webpack-…
ascariandrea Jul 6, 2022
2286731
chore: upgrade supertest and removed jest-dev-server
ascariandrea Jul 6, 2022
897767c
chore: upgrade react-refresh-typescript and react-i18next
ascariandrea Jul 6, 2022
949b8dc
chore: upgrade [email protected] and [email protected]
ascariandrea Jul 6, 2022
9921b09
chore: upgrade [email protected] and [email protected]
ascariandrea Jul 6, 2022
9c28bfc
chore(yttrex): load keys from .env.development for testing
ascariandrea Jul 7, 2022
4c22f11
chore: upgrade prettier@^2.7.1
ascariandrea Jul 7, 2022
16a7290
chore: upgrade bs58@^4.0.1
ascariandrea Jul 11, 2022
ccddc47
fix(guardoni): configure experiment for extensions
ascariandrea Jul 6, 2022
2629b41
fix: removed API to conclude experiment
ascariandrea Jul 12, 2022
2d99058
fix: renamed 'evidencetag' to 'researchTag'
ascariandrea Jul 12, 2022
3707003
fix(yttrex): defined API to retrieve metadata by researchTag/experime…
ascariandrea Jul 15, 2022
b4c2f6a
docs(guardoni): typo and open-doc-api models (#598)
ascariandrea Jul 15, 2022
e081a6a
fix: mongo collection renaming in yttrex and tktrex (#591, #596)
ascariandrea Jul 15, 2022
7e44c4c
chore: removed makhno files #602 (#603)
vecna Jul 15, 2022
23d6fac
chore: removed makhno workspace from yarn.lock
ascariandrea Jul 18, 2022
f63d072
fix(guardoni): fetch metadata after experiment in cli tests (#552)
ascariandrea Jul 18, 2022
d03ed6d
ci: use 'xvfb' node module in cli-yt-home
ascariandrea Jul 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__mocks__
.husky
**/build
**/docker
**/docker/electron-builder
**/coverage
**/node_modules
docker
!docker/guardoni/guardoni.config.json
26 changes: 15 additions & 11 deletions .github/workflows/guardoni_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
- fix/**
- refactor/**
paths:
- "packages/shared/**"
- "platforms/**"
- 'packages/shared/**'
- 'platforms/**'

jobs:
pull_request:
Expand All @@ -34,7 +34,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
cache: 'yarn'
cache-dependency-path: yarn.lock

- name: Install modules
Expand Down Expand Up @@ -69,9 +69,6 @@ jobs:
guardoni_build:
name: Guardoni build
runs-on: ${{ matrix.config.os }}
# defaults:
# run:
# shell: bash --noprofile --norc -exo pipefail {0}
strategy:
max-parallel: 1
matrix:
Expand Down Expand Up @@ -126,21 +123,28 @@ jobs:
platforms/guardoni/dist
platforms/ycai/studio/build

- name: Install Xvfb
run: |
sudo apt install -y xvfb x11-utils libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 xdotool

- name: Install dependencies
run: yarn

- name: Start PM2
run: |
yarn pm2 start --env test ./platforms/ecosystem.config.js
sleep 5
run: yarn pm2 start --env test ./platforms/ecosystem.config.js

- name: Build Guardoni for ${{ matrix.config.os }}
working-directory: ./platforms/guardoni
run: ./scripts/cli-build.mjs

- name: Test YT cli
- name: Test CLI - YT Home
working-directory: ./platforms/guardoni
run: ./scripts/cli-yt-test.mjs
env:
DISPLAY: ':99.0'
run: xvfb-run --auto-servernum ./scripts/cli-yt-test-home.mjs

- name: Test CLI - YT Videos
run: yarn guardoni cli-yt-test-videos

- name: Stop PM2
run: yarn pm2 stop all
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/bs58-npm-3.1.0-c7b525bd2a-6d757a4995.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/cpy-npm-8.1.2-1dc1b9bc19-e121f13f2b.zip
Binary file not shown.
Binary file removed .yarn/cache/cwd-npm-0.10.0-ccb304998d-55ab180af8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/junk-npm-3.1.0-aa1fa701c6-6c4d68e8f8.zip
Binary file not shown.
Binary file removed .yarn/cache/lcid-npm-1.0.0-02d845072b-e8c7a4db07.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/y18n-npm-3.2.2-f9b6b42101-6154fd7544.zip
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions docker/guardoni/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:16-slim

RUN mkdir /guardoni
WORKDIR /guardoni
RUN apt-get update
RUN apt-get install -y python3 build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

ADD ./ ./

RUN yarn install
RUN yarn tk:ext build
RUN yarn yt:ext build
RUN yarn guardoni build:cli
RUN yarn guardoni pkg
WORKDIR /guardoni/platforms/guardoni/dist/
RUN mv $(ls -1 guardoni-cli*-linux) guardoni-cli

FROM selenium/standalone-chrome:102.0
WORKDIR /guardoni

COPY --from=0 /guardoni/platforms/guardoni/dist/guardoni-cli guardoni-cli
COPY --from=0 "/guardoni/node_modules/@tktrex/extension/build" tktrex
COPY --from=0 "/guardoni/node_modules/@yttrex/extension/build" yttrex
COPY --from=0 /guardoni/docker/guardoni/guardoni.config.json .

USER root
RUN chmod -R 777 /guardoni/yttrex
RUN chmod -R 777 /guardoni/tktrex
USER seluser

ENTRYPOINT [ "/guardoni/guardoni-cli" ]
6 changes: 6 additions & 0 deletions docker/guardoni/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"
cd "$SCRIPT_DIR/../../"
docker build -f "docker/guardoni/Dockerfile" -t guardoni .
17 changes: 17 additions & 0 deletions docker/guardoni/guardoni.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"profileName": "dockerized-guardoni",
"headless": true,
"verbose": false,
"loadFor": 3000,
"yt": {
"name": "youtube",
"backend": "https://youtube.tracking.exposed/api",
"extensionDir": "/guardoni/yttrex"
},
"tk": {
"name": "tiktok",
"backend": "https://tiktok.tracking.exposed/api",
"extensionDir": "/guardoni/tktrex"
},
"chromePath": "/usr/bin/google-chrome"
}
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@tsconfig/docusaurus": "^1.0.4",
"docusaurus-plugin-openapi": "^0.5.0",
"docusaurus-preset-openapi": "^0.5.0",
"typescript": "^4.7.2"
"typescript": "^4.7.4"
},
"browserslist": {
"production": [
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"packages/*",
"platforms/guardoni",
"platforms/ycai/studio",
"platforms/makhno/*",
"platforms/yttrex/*",
"platforms/tktrex/docs",
"platforms/tktrex/extension",
Expand All @@ -26,7 +25,7 @@
"clean": "yarn workspaces foreach -v run clean",
"lint": "yarn workspaces foreach -v run lint",
"type-check": "yarn workspaces foreach run tsc --noEmit",
"build": "yarn workspaces foreach run build",
"build": "scripts/build.sh",
"test": "jest",
"docs": "yarn workspace @trex/docs",
"taboule": "yarn workspace @trex/taboule",
Expand All @@ -40,7 +39,6 @@
"yt:shared": "yarn workspace @yttrex/shared",
"yt:backend": "yarn workspace @yttrex/backend",
"yt:ext": "yarn workspace @yttrex/extension",
"makhno": "yarn workspace @makhno/backend",
"ycai": "yarn workspace @trex/ycai",
"lint-staged": "lint-staged",
"postinstall": "husky install",
Expand All @@ -57,16 +55,16 @@
"@release-it/conventional-changelog": "^4.3.0",
"@types/node": "^16.11.36",
"@types/prettier": "^2.6.3",
"eslint": "^8.16.0",
"eslint": "^8.19.0",
"eslint-plugin-n": "^15.2.4",
"husky": "^7.0.4",
"jest": "^27.5.1",
"jest-dev-server": "^6.0.3",
"lint-staged": "^12.3.3",
"prettier": "^2.6.2",
"prettier": "^2.7.1",
"release-it": "^14.14.3",
"release-it-yarn-workspaces": "^2.0.1",
"ts-jest": "^27.1.5",
"typescript": "^4.7.2",
"typescript": "^4.7.4",
"webpack": "^5.73.0",
"zx": "^6.2.5"
},
Expand Down
24 changes: 12 additions & 12 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,44 @@
"io-ts-types": "^0.5.16",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.3",
"react-i18next": "^11.18.0",
"ts-endpoint": "^2.0.0",
"ts-endpoint-express": "^2.0.0",
"ts-io-error": "^2.0.0",
"typelevel-ts": "^0.4.0",
"typescript": "^4.7.2"
"typescript": "^4.7.4"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@types/chrome": "^0.0.188",
"@types/debug": "^4.1.7",
"@types/dotenv-webpack": "^7.0.3",
"@types/node": "^16.11.36",
"@types/react": "^17.0.45",
"@types/react": "^17.0.47",
"@types/react-dom": "^17.0.17",
"@types/webpack-bundle-analyzer": "^4.4.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"copy-webpack-plugin": "^11.0.0",
"dotenv-webpack": "^7.1.0",
"eslint": "^8.16.0",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.30.1",
"fast-check": "^2.25.0",
"fast-check-io-ts": "^0.5.0",
"filemanager-webpack-plugin": "^6.1.7",
"filemanager-webpack-plugin": "^7.0.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^27.5.1",
"mini-css-extract-plugin": "^2.6.1",
"node-loader": "^2.0.0",
"node-sass": "^7.0.1",
"prettier": "^2.6.2",
"prettier": "^2.7.1",
"react-refresh": "^0.12.0",
"react-refresh-typescript": "^2.0.5",
"react-refresh-typescript": "^2.0.7",
"sass-loader": "^12.6.0",
"style-loader": "^3.3.1",
"tsconfig-paths-webpack-plugin": "^3.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/backend/utils/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const toError = (e: unknown): IOError => {
};
};

declare type UndefinedOrRuntime<N> = N extends RecordCodec<any, any>
export declare type UndefinedOrRuntime<N> = N extends RecordCodec<any, any>
? {
[k in keyof N['props']]: runtimeType<N['props'][k]>;
}
Expand Down
131 changes: 131 additions & 0 deletions packages/shared/src/backend/utils/routeHandlerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import express from 'express';
import _ from 'lodash';
import { APIError } from '../../errors/APIError';
import { GetLogger } from '../../logger';

const logger = GetLogger('route-handler');

const logAPICount = { requests: {}, responses: {}, errors: {} };

function loginc(kind: string, fname: string): void {
(logAPICount as any)[kind][fname] = (logAPICount as any)[kind][fname]
? (logAPICount as any)[kind][fname]++
: 1;
}

type RouteHandlerMiddleware<R extends Record<string, express.RequestHandler>> =
(
fname: keyof R
) => (req: express.Request, res: express.Response) => Promise<void>;

export const routeHandleMiddleware = <
R extends Record<string, express.RequestHandler>
>(
apiList: R
): RouteHandlerMiddleware<R> => {
setInterval(() => {
let print = false;
_.each(_.keys(logAPICount), function (k) {
if (!_.keys((logAPICount as any)[k]).length)
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete (logAPICount as any)[k];
else print = true;
});
if (print) logger.debug('%j', logAPICount);
logAPICount.responses = {};
logAPICount.errors = {};
logAPICount.requests = {};
}, 60 * 1000);

return (fn) => async (req, res) => {
const fname = fn as any;
try {
loginc('requests', fname);
const funct = apiList[fname];
const httpresult = await (funct as any)(req, res);

if (!httpresult) {
logger.debug("API (%s) didn't return anything!?", fname);
loginc('errors', fname);
res.send('Fatal error: Invalid output');
res.status(501);
return;
}

if (httpresult.json?.error) {
const statusCode = httpresult.json.status ?? 500;
logger.debug('API (%s) failure, returning %d', fname, statusCode);
loginc('errors', fname);
res.status(statusCode);
res.json(httpresult.json);
return;
}

if (httpresult.headers)
_.each(httpresult.headers, function (value, key) {
logger.debug('Setting header %s: %s', key, value);
res.setHeader(key, value);
});

if (httpresult.json) {
// logger("API (%s) success, returning %d bytes JSON", fname, _.size(JSON.stringify(httpresult.json)));
loginc('responses', fname);
res.setHeader('Access-Control-Allow-Origin', '*');
res.json(httpresult.json);
} else if (httpresult.text) {
// logger("API (%s) success, returning text (size %d)", fname, _.size(httpresult.text));
loginc('responses', fname);
res.send(httpresult.text);
} else if (httpresult.status) {
// logger("Returning empty status %d from API (%s)", httpresult.status, fname);
loginc('responses', fname);
res.status(httpresult.status);
} else {
logger.debug(
'Undetermined failure in API (%s) → %j',
fname,
httpresult
);
loginc('errors', fname);
res.status(502);
res.send('Error?');
}
} catch (error) {
logger.error('Route handler (%s) error: %O', fname, error);

// todo: this should be 500
res.status(502);

if (error instanceof APIError) {
logger.error(
'APIError - %s: (%s) %s %s',
error.name,
error.message,
error.stack
);
res.status(error.status);
res.send({
name: error.type,
message: error.message,
details: error.details,
});
} else if (error instanceof Error) {
logger.error('Error - %s: %s', error.name, error.message);

res.send('Software error: ' + error.message);
logger.error(
'Error in HTTP handler API(%s): %s %s',
fname,
error.message,
error.stack
);
} else {
res.status(502);
res.send('Software error: ' + (error as any).message);
loginc('errors', fname);
logger.debug('Error in HTTP handler API(%s): %o', fname, error);
}
}
res.end();
};
};
Loading