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

fix: guardoni cli and electron build #371

Merged
merged 10 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion YCAI/src/providers/dataDonation.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as TE from 'fp-ts/lib/TaskEither';
import _ from 'lodash';
import { config } from '../config';
import { Keypair, Settings } from '../models/Settings';
import { getTimeISO8601 } from '../utils/date.utils';
import { getTimeISO8601 } from '@shared/utils/date.utils';
import { logger } from '../utils/logger.utils';
import { sendAPIMessage } from './browser.provider';
import security from './bs58.provider';
Expand Down
2 changes: 1 addition & 1 deletion backend/bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ export const makeApp = async (
'/v2/guardoni/list/:directiveType/:key?',
iowrapper('getAllExperiments')
);
apiRouter.get('/v3/directives/public', iowrapper('getPublicDirectives'));
apiRouter.post('/v3/directives/:directiveType', iowrapper('postDirective'));
apiRouter.get('/api/v3/directives/public', iowrapper('getPublicDirectives'));
apiRouter.get('/v3/directives/:experimentId', iowrapper('fetchDirective'));
apiRouter.post('/v2/handshake', iowrapper('experimentChannel3'));
apiRouter.delete(
Expand Down
8 changes: 1 addition & 7 deletions extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ const PRODUCTION = NODE_ENV === 'production';
const DEVELOPMENT = NODE_ENV === 'development';
const BUILDISODATE = new Date().toISOString();
const GUARDONI_TARGET = process.env?.BUILD_TARGET === 'guardoni';
const APP_VERSION = GUARDONI_TARGET
? packageJSON.version
.split('.')
.filter((v, i) => i !== 2)
.concat('99')
.join('.')
: packageJSON.version;
const APP_VERSION = packageJSON.version;

console.log(
'NODE_ENV [' + process.env.NODE_ENV + '] Prod:',
Expand Down
1 change: 0 additions & 1 deletion guardoni/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NODE_ENV=production
VERSION=1.9.0
BACKEND=https://youtube.tracking.exposed/api
DEBUG="guardoni:*"
3 changes: 1 addition & 2 deletions guardoni/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NODE_ENV=development
VERSION=1.9.0.99
BACKEND=http://localhost:9000/api
DEBUG=guardoni:*
DEBUG=@trex:*,guardoni:*
1 change: 1 addition & 0 deletions guardoni/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
11 changes: 10 additions & 1 deletion guardoni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [CLI commands](#cli-commands)
- [Register CSV](#register-csv)
- [Running an experiment by id](#running-an-experiment-by-id)
- [List public directives](#list-public-directives)
- [Running a default experiment](#running-a-default-experiment)
- [Build](#build)
- [Package](#package)
Expand Down Expand Up @@ -80,7 +81,7 @@ Examples:

### CLI commands

Three fundamental commands exist: `register`, `experiment` and "auto mode".
Three fundamental commands exist: `register`, `experiment`, `list` and "auto mode".

How do they works?

Expand Down Expand Up @@ -121,6 +122,14 @@ With an experiment id you can run guardoni quite easily:
guardoni-cli experiment 123456
```

#### List public directives

With this command you can list the public directives available to run.

```bash
guardoni-cli list
```

#### Running a default experiment

Guardoni provides also an `auto` method to run pre-configured experiment. At the moment there are only 2 experiments available that can be run:
Expand Down
85 changes: 48 additions & 37 deletions guardoni/bin/guardoni-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,66 @@

const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const { GetGuardoniCLI } = require('../build/guardoni/cli.js');
const { GetGuardoniCLI, cliLogger } = require('../build/guardoni/cli.js');
const puppeteer = require('puppeteer');
const D = require('debug');

const runGuardoni = ({
_,
$0,
v,
headless,
verbose,
backend,
basePath,
profile,
evidenceTag,
proxy,
...command
c,
config,
command,
...guardoniConf
}) => {
return GetGuardoniCLI({
headless,
basePath,
profile,
verbose,
evidenceTag,
proxy,
backend,
})
if (verbose) {
if (config) {
console.log(`Configuration loaded from ${config}`, guardoniConf);
}
}

return GetGuardoniCLI({ ...guardoniConf, verbose }, puppeteer)
.runOrThrow(command)
.then(() => process.exit(0));
};

yargs(hideBin(process.argv))
.scriptName('guardoni-cli')
.example('$0 --type comparison')
.command(
'experiment <experiment>',
'Run guardoni from a given experiment',
(yargs) =>
yargs
.positional('experiment', {
desc: 'Experiment id',
demandOption: 'Provide the experiment id',
type: 'string',
})
.example('$0 experiment 1234'),
(argv) => runGuardoni({ ...argv, run: 'experiment' })
yargs.positional('experiment', {
desc: 'Experiment id',
demandOption: 'Provide the experiment id',
type: 'string',
}),
({ experiment, ...argv }) =>
runGuardoni({ ...argv, command: { run: 'experiment', experiment } })
)
.command(
'register <file>',
'Register an experiment from a CSV',
(yargs) => {
return yargs
.positional('file', {
desc: 'CSV file to register an experiment',
type: 'string',
demandOption: 'Provide a valid path to a csv file',
})
.example('$0 csv ./path/to/file.csv');
return yargs.positional('file', {
desc: 'CSV file to register an experiment',
type: 'string',
demandOption: 'Provide a valid path to a csv file',
});
},
(argv) => runGuardoni({ ...argv, run: 'register-csv' })
({ file, ...argv }) =>
runGuardoni({ ...argv, command: { run: 'register-csv', file } })
)
.command(
'list',
'List available experiments',
(yargs) => {
return yargs.example('$0 list');
},
(argv) => runGuardoni({ ...argv, command: { run: 'list' } })
)
.usage(
'$0 [index]',
Expand All @@ -71,9 +75,17 @@ yargs(hideBin(process.argv))
demandOption: 'Run comparison or shadow ban experiment run',
});
},
(args) => runGuardoni({ ...args, run: 'auto' })
({ index, ...args }) =>
runGuardoni({ ...args, command: { run: 'auto', index: index } })
)
.example('$0 --type comparison')
.option('c', {
type: 'string',
alias: 'config',
desc: 'Guardoni configuration',
default: 'guardoni.config.json',
config: true,
})
.config()
.option('headless', {
type: 'boolean',
desc: 'Run guardoni in headless mode.',
Expand Down Expand Up @@ -105,5 +117,4 @@ yargs(hideBin(process.argv))
desc: 'Produce tons of logs',
default: false,
})
.strictCommands()
.parse();
.strictCommands().argv;
30 changes: 16 additions & 14 deletions guardoni/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ appId: guardoni.tracking.exposed

productName: Guardoni

asar: false
asar: true
asarUnpack: ['node_modules']

extends: null

extraMetadata:
main: "build/electron/main.js"

files: [
"build/**",
"!profiles/**",
"!src/**",
"!screenshots/**",
"!static/**"
]

icon: ./static/yttrex-128.png
main: 'build/electron/main.js'

files:
[
'build/**',
'!node_modules/**',
'!src/**',
'!profiles/**',
'!screenshots/**',
'!static/**',
]

linux:
target: ["deb"]
icon: ./static/linux/icons
target: ['deb']
category: Network

win:
target: ["portable"]
target: ['portable']
3 changes: 3 additions & 0 deletions guardoni/guardoni.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"backend": "http://localhost:9000/api"
}
8 changes: 5 additions & 3 deletions guardoni/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start": "electron .",
"pack": "electron-builder build --dir",
"dist:linux": "electron-builder build -l",
"dist:mac": "electron-builder build -m",
"dist:windows": "electron-builder build -w",
"dist:all": "scripts/dist-all.sh",
"postinstall": "electron-builder install-app-deps",
Expand Down Expand Up @@ -45,7 +46,7 @@
"csv-stringify": "^6.0.5",
"debug": "^4.3.3",
"electron-debug": "^3.2.0",
"electron-log": "^4.4.5",
"electron-log": "^4.4.6",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.0.1",
"fp-ts": "^2.11.8",
Expand Down Expand Up @@ -77,7 +78,7 @@
"chalk": "^5.0.0",
"electron": "16.0.8",
"electron-builder": "^22.14.13",
"electron-reloader": "^1.2.1",
"electron-reloader": "^1.2.2",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard-with-typescript": "^21.0.1",
Expand Down Expand Up @@ -110,7 +111,8 @@
"experiments/.keep",
"static/index.html",
"config/default.json",
"profiles/.keep"
"profiles/.keep",
"package.json"
],
"targets": [
"node16-linux-x64",
Expand Down
14 changes: 4 additions & 10 deletions guardoni/scripts/dist-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

set -e -x

yarn dist:linux
# CONTAINER_NAME=electron-builder-node-16

# docker exec --privileged $CONTAINER_NAME bash -c "yarn"
# docker exec --privileged $CONTAINER_NAME bash -c "chown -R ${USER}:${GROUP} /project"
# docker exec --privileged $CONTAINER_NAME bash -c "chown -R ${USER}:${GROUP} /root/.cache/"
# docker exec $CONTAINER_NAME bash -c "yarn guardoni dist:linux"
# docker exec $CONTAINER_NAME bash -c "yarn guardoni dist:windows"
export NODE_ENV='production'

# docker stop $CONTAINER_NAME
# docker rm $CONTAINER_NAME
yarn dist:linux
# yarn dist:windows
# yarn dist:mac
5 changes: 2 additions & 3 deletions guardoni/scripts/pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ set -ex

pkg ./package.json

version=`grep version package.json | cut -b 15- | sed -es/\".*//`
# 1.8.2
version=$(grep version package.json | cut -b 15- | sed -es/\".*//)

cd dist
mv guardoni-win.exe guardoni-cli-$version.exe
mv guardoni-macos guardoni-cli-$version-macos
mv guardoni-linux guardoni-cli-$version-linux
chmod +x *
chmod +x *-cli-*
ls -l
cd ..
10 changes: 7 additions & 3 deletions guardoni/src/electron/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ export const App: React.FC = () => {
setConfig(config);
});

// request guardoni config
ipcRenderer.send(GET_GUARDONI_CONFIG_EVENT.value);
if (config === undefined) {
setTimeout(() => {
// request guardoni config
ipcRenderer.send(GET_GUARDONI_CONFIG_EVENT.value);
}, 200);
}

return () => {
ipcRenderer.removeAllListeners(GET_GUARDONI_CONFIG_EVENT.value);
};
}, []);
}, [config]);

if (!config) {
return <LinearProgress />;
Expand Down
Loading