Skip to content

Commit

Permalink
fix: removing docker-run.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Jul 26, 2022
1 parent 1cbedc5 commit d8078d3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
4 changes: 2 additions & 2 deletions tests/bin/agent/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { runDescribeIfPlatforms, runTestIfPlatforms } from '../../utils';
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';

describe('start', () => {
const logger = new Logger('start test', LogLevel.INFO, [new StreamHandler()]);
const logger = new Logger('start test', LogLevel.WARN, [new StreamHandler()]);
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
Expand All @@ -30,7 +30,7 @@ describe('start', () => {
recursive: true,
});
});
runTestIfPlatforms('linux', 'docker').only(
runTestIfPlatforms('linux', 'docker')(
'start in foreground',
async () => {
const password = 'abc123';
Expand Down
92 changes: 50 additions & 42 deletions tests/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,35 @@ const generateDockerArgs = (mountPath: string) => [
'run',
'--interactive',
'--rm',
'--network', 'host',
'--pid', 'host',
'--userns', 'host',
`--user`, `${process.getuid()}`,
'--mount', `type=bind,src=${mountPath},dst=${mountPath}`,
'--env', 'PK_PASSWORD',
'--env', 'PK_NODE_PATH',
'--env', 'PK_RECOVERY_CODE',
'--env', 'PK_TOKEN',
'--env', 'PK_ROOT_KEY',
'--env', 'PK_NODE_ID',
'--env', 'PK_CLIENT_HOST',
'--env', 'PK_CLIENT_PORT',
'--network',
'host',
'--pid',
'host',
'--userns',
'host',
`--user`,
`${process.getuid()}`,
'--mount',
`type=bind,src=${mountPath},dst=${mountPath}`,
'--env',
'PK_PASSWORD',
'--env',
'PK_NODE_PATH',
'--env',
'PK_RECOVERY_CODE',
'--env',
'PK_TOKEN',
'--env',
'PK_ROOT_KEY',
'--env',
'PK_NODE_ID',
'--env',
'PK_CLIENT_HOST',
'--env',
'PK_CLIENT_PORT',
`${process.env.PK_TEST_DOCKER_IMAGE}`,
'polykey'
]
'polykey',
];

/**
* Wrapper for execFile to make it asynchronous and non-blocking
Expand Down Expand Up @@ -283,7 +296,6 @@ async function pkSpawn(
/**
* Mimics the behaviour of `pkStdio` while running the command as a separate process.
* Note that this is incompatible with jest mocking.
* @param cmd - path to the target command relative to the project directory.
* @param args - args to be passed to the command.
* @param env - environment variables to be passed to the command.
* @param cwd - the working directory the command will be executed in.
Expand Down Expand Up @@ -312,18 +324,16 @@ async function pkStdioTarget(
...process.env,
...env,
};
const command = global.testCmd === 'docker' ?
'docker' :
path.resolve(path.join(global.projectDir, global.testCmd!));
const command =
global.testCmd === 'docker'
? 'docker'
: path.resolve(path.join(global.projectDir, global.testCmd!));
const dockerArgs = global.testCmd === 'docker' ? generateDockerArgs(cwd) : [];
const subprocess = child_process.spawn(
command,
[...dockerArgs, ...args],
{
env,
cwd,
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true,
const subprocess = child_process.spawn(command, [...dockerArgs, ...args], {
env,
cwd,
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true,
});
const exitCodeProm = promise<number | null>();
subprocess.on('exit', (code) => {
Expand All @@ -345,7 +355,6 @@ async function pkStdioTarget(

/**
* Execs the target command spawning it as a seperate process
* @param cmd - path to the target command relative to the project directory.
* @param args - args to be passed to the command.
* @param env Augments env for command execution
* @param cwd Defaults to temporary directory
Expand All @@ -372,9 +381,10 @@ async function pkExecTarget(
// (if not defined in the env) to ensure no attempted connections. A regular
// PolykeyAgent is expected to initially connect to the mainnet seed nodes
env['PK_SEED_NODES'] = env['PK_SEED_NODES'] ?? '';
const command = global.testCmd === 'docker' ?
'docker' :
path.resolve(path.join(global.projectDir, global.testCmd!));
const command =
global.testCmd === 'docker'
? 'docker'
: path.resolve(path.join(global.projectDir, global.testCmd!));
const dockerArgs = global.testCmd === 'docker' ? generateDockerArgs(cwd) : [];
return new Promise((resolve, reject) => {
child_process.execFile(
Expand Down Expand Up @@ -428,18 +438,16 @@ async function pkSpawnTarget(
// (if not defined in the env) to ensure no attempted connections. A regular
// PolykeyAgent is expected to initially connect to the mainnet seed nodes
env['PK_SEED_NODES'] = env['PK_SEED_NODES'] ?? '';
const command = global.testCmd === 'docker' ?
'docker' :
path.resolve(path.join(global.projectDir, global.testCmd!));
const command =
global.testCmd === 'docker'
? 'docker'
: path.resolve(path.join(global.projectDir, global.testCmd!));
const dockerArgs = global.testCmd === 'docker' ? generateDockerArgs(cwd) : [];
const subprocess = child_process.spawn(
command,
[...dockerArgs, ...args],
{
env,
cwd,
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true,
const subprocess = child_process.spawn(command, [...dockerArgs, ...args], {
env,
cwd,
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true,
});
// The readline library will trim newlines
const rlOut = readline.createInterface(subprocess.stdout!);
Expand Down

0 comments on commit d8078d3

Please sign in to comment.