Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hyperchain_wizard): run server in docker container #138

Closed
wants to merge 1 commit into from
Closed
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
81 changes: 79 additions & 2 deletions infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,79 @@ async function startServer() {
await server.server(false, false, components.join(','));
}

export async function startZksyncServerDocker() {

// Set home variable to be used in Docker image.
wrapEnvModify('ZKSYNC_HOME', '/');

// Ask user for the URLs of the GETH and POSTGRES servers.
const l1gethQuestion = [
{
message: 'Please provide URL of the L1 GETH node.',
name: 'GETH_URL',
type: 'input'
}
];

const l1gethResults: any = await enquirer.prompt(l1gethQuestion);

wrapEnvModify('ETH_CLIENT_WEB3_URL', l1gethResults.GETH_URL);

const l2postgresQuestion = [
{
message: 'Please provide URL of the L2 Postgres DB.',
name: 'DB_URL',
type: 'input'
}
];

const l2postgresResults: any = await enquirer.prompt(l2postgresQuestion);

wrapEnvModify('DATABASE_URL', l2postgresResults.DB_URL);

// Ask user for potential custom components to launch with server.

const DEFAULT = 'Default components';
const CUSTOM = 'Custom components';

const questions: BasePromptOptions[] = [
{
message: 'Do you want to use default or custom components with the dockerized Hyperchain server?',
name: 'start',
type: 'select',
choices: [DEFAULT, CUSTOM]
}
];

const results: any = await enquirer.prompt(questions);

let components: string[] = [];
const defaultChoices = ['http_api', 'eth', 'data_fetcher', 'state_keeper', 'housekeeper', 'tree_lightweight'];

if (results.start === CUSTOM) {
const componentQuestions: BasePromptOptions[] = [
{
message: 'Please select the desired components',
name: 'components',
type: 'multiselect',
choices: ['api', 'ws_api', ...defaultChoices, 'tree'].sort()
}
];

components = ((await enquirer.prompt(componentQuestions)) as any).components;
} else {
components = defaultChoices;
}

await utils.spawn('cp etc/tokens/{test,localhost}.json');

await utils.spawn('CARGO_HOME=./cargo cargo fetch');

await utils.spawn('docker build -t zksync_server -f ./docker/server-v2/Dockerfile . ');

await utils.spawn(`docker run --env-file ${process.env.ENV_FILE} zksync_server --network zksync-2-dev_default $${components.join(' $')}`);
}

// The current env.modify requires to write down the variable name twice. This wraps it so the caller only writes the name and the value
function wrapEnvModify(variable: string, assignedVariable: string) {
env.modify(variable, `${variable}=${assignedVariable}`);
Expand Down Expand Up @@ -495,8 +568,7 @@ async function checkBalance(wallet: ethers.Wallet, expectedBalance: BigNumber):
const balance = await wallet.getBalance();
if (balance.lt(expectedBalance)) {
console.log(
`Wallet ${
wallet.address
`Wallet ${wallet.address
} has insufficient funds. Expected ${expectedBalance.toString()}, got ${balance.toString()}`
);
return false;
Expand Down Expand Up @@ -563,3 +635,8 @@ export function getTokens(network: string): L1Token[] {
export const initHyperchainCommand = new Command('init-hyperchain')
.description('Initializes a new hyperchain network')
.action(initHyperchain);


export const startDockerHyperchainCommand = new Command('docker-hyperchain')
.description('Start a new dockerized hyperchain network')
.action(initHyperchain);
3 changes: 2 additions & 1 deletion infrastructure/zk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { command as up } from './up';
import { command as down } from './down';
import { command as contract } from './contract';
import { initCommand as init, reinitCommand as reinit, lightweightInitCommand as lightweightInit } from './init';
import { initHyperchainCommand as initHyperchain } from './hyperchain_wizard';
import { initHyperchainCommand as initHyperchain, startDockerHyperchainCommand as startDockerHyperchain } from './hyperchain_wizard';
import { command as run } from './run/run';
import { command as test } from './test/test';
import { command as docker } from './docker';
Expand All @@ -34,6 +34,7 @@ const COMMANDS = [
reinit,
lightweightInit,
initHyperchain,
startDockerHyperchain,
run,
test,
fmt,
Expand Down
Loading