Convert LavaMoat policy generation script to Yargs application (#15626)
This PR converts `generate-lavamoat-policies.sh` to `.js` using Yargs. This makes it easier to only generate policy files for a specific build type (using the `-t` flag), which is often useful during Flask development. In addition, the `lavamoat:background:auto` scripts are renamed, and the main readme is updated with some useful tips. Note that `lavamoat:background:auto:dev` is removed and `lavamoat:background:auto` should be used during local development.feature/default_network_editable
parent
ba376c07c1
commit
8210e3a812
@ -0,0 +1,53 @@ |
|||||||
|
const concurrently = require('concurrently'); |
||||||
|
const yargs = require('yargs/yargs'); |
||||||
|
const { hideBin } = require('yargs/helpers'); |
||||||
|
const { BuildType } = require('./lib/build-type'); |
||||||
|
|
||||||
|
start().catch((error) => { |
||||||
|
console.error('Policy generation failed.', error); |
||||||
|
process.exitCode = 1; |
||||||
|
}); |
||||||
|
|
||||||
|
async function start() { |
||||||
|
const { |
||||||
|
argv: { buildTypes, parallel }, |
||||||
|
} = yargs(hideBin(process.argv)).usage( |
||||||
|
'$0 [options]', |
||||||
|
'Generate the LavaMoat policy file for one more more build types.', |
||||||
|
(yargsInstance) => |
||||||
|
yargsInstance |
||||||
|
.option('build-types', { |
||||||
|
alias: ['t'], |
||||||
|
choices: Object.values(BuildType), |
||||||
|
default: Object.values(BuildType), |
||||||
|
demandOption: true, |
||||||
|
description: 'The build type(s) to generate policy files for.', |
||||||
|
}) |
||||||
|
.option('parallel', { |
||||||
|
alias: ['p'], |
||||||
|
default: true, |
||||||
|
demandOption: true, |
||||||
|
description: 'Whether to generate policies in parallel.', |
||||||
|
type: 'boolean', |
||||||
|
}) |
||||||
|
.strict(), |
||||||
|
); |
||||||
|
|
||||||
|
await concurrently( |
||||||
|
(Array.isArray(buildTypes) ? buildTypes : [buildTypes]).map( |
||||||
|
(buildType) => ({ |
||||||
|
command: `yarn build scripts:prod --policy-only --build-type=${buildType}`, |
||||||
|
env: { |
||||||
|
WRITE_AUTO_POLICY: 1, |
||||||
|
}, |
||||||
|
name: buildType, |
||||||
|
}), |
||||||
|
), |
||||||
|
{ |
||||||
|
killOthers: true, |
||||||
|
maxProcesses: parallel ? buildTypes.length : 1, |
||||||
|
}, |
||||||
|
); |
||||||
|
|
||||||
|
console.log('Policy file(s) successfully generated!'); |
||||||
|
} |
@ -1,19 +0,0 @@ |
|||||||
#!/usr/bin/env bash |
|
||||||
|
|
||||||
set -e |
|
||||||
set -u |
|
||||||
set -o pipefail |
|
||||||
|
|
||||||
extraArgs=() |
|
||||||
if [[ $# -lt 1 ]]; then |
|
||||||
extraArgs+=(-m 1) |
|
||||||
fi |
|
||||||
|
|
||||||
# Generate LavaMoat policies for the extension background script for each build |
|
||||||
# type. |
|
||||||
# ATTN: This may tax your device when running it locally. |
|
||||||
concurrently --kill-others-on-fail -n main,beta,flask \ |
|
||||||
"${extraArgs[@]}" \ |
|
||||||
"WRITE_AUTO_POLICY=1 yarn build scripts:prod --policy-only" \ |
|
||||||
"WRITE_AUTO_POLICY=1 yarn build scripts:prod --policy-only --build-type beta" \ |
|
||||||
"WRITE_AUTO_POLICY=1 yarn build scripts:prod --policy-only --build-type flask" |
|
Loading…
Reference in new issue