Skip to content

Commit

Permalink
Fix key dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniallugo committed Jan 14, 2021
1 parent b87b4cc commit 4202c60
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
7 changes: 5 additions & 2 deletions core/lib/config/src/configs/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ pub struct DBConfig {
impl DBConfig {
pub fn from_env() -> Self {
Self {
pool_size: env!("DB_POOL_SIZE").parse().unwrap(),
url: env!("DATABASE_URL").to_string(),
pool_size: std::env::var("DB_POOL_SIZE")
.expect("DB_POOL_SIZE is set")
.parse()
.unwrap(),
url: std::env::var("DATABASE_URL").expect("DATABASE_URL is set"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/zk/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Command} from 'commander';
import { Command } from 'commander';
import * as toml from '@iarna/toml';
import * as fs from 'fs';
import * as path from 'path';
import deepExtend from 'deep-extend';
import {env} from 'process';
import { env } from 'process';

const CONFIG_FILES = [
'api.toml',
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function deploy() {
const matches = deployLog.match(pattern);
if (matches !== null) {
env.modify(envVar, matches[0]);
env.modify_contracts_toml( envVar, matches[0]);
env.modify_contracts_toml(envVar, matches[0]);
}
}
}
Expand Down
35 changes: 17 additions & 18 deletions infrastructure/zk/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import fs from 'fs';
import dotenv from 'dotenv';
import * as utils from './utils';
import * as config from './config';
import * as toml from "@iarna/toml";
import * as toml from '@iarna/toml';

export function get() {
fs.readdirSync('etc/env').forEach((file) => {
if (!file.endsWith(".env")){
if (!file.endsWith('.env')) {
return;
}

Expand Down Expand Up @@ -39,10 +39,9 @@ export function set(env: string) {
throw new Error(envFile + ' not found');
}


fs.writeFileSync('etc/env/current', env);
process.env.ENV_FILE = envFile;
process.env.ENV_DIR = envDir
process.env.ENV_DIR = envDir;
process.env.ZKSYNC_ENV = env;
get();
}
Expand All @@ -64,22 +63,22 @@ export async function load() {
process.env.ZKSYNC_ENV || (fs.existsSync(current) ? fs.readFileSync(current).toString().trim() : 'dev');
const envFile = `etc/env/${zksyncEnv}.env`;
const envDir = `etc/env/${zksyncEnv}`;
if (zksyncEnv == 'dev') {
/// If there no folder with toml files we should delete the old dev.env and regenerate toml files and
if (!fs.existsSync('etc/env/dev')) {
fs.rmSync('etc/env/dev.env')
}
if (zksyncEnv == 'dev') {
/// If there no folder with toml files we should delete the old dev.env and regenerate toml files and
if (!fs.existsSync('etc/env/dev')) {
fs.rmSync('etc/env/dev.env');
}

if (!fs.existsSync('etc/env/dev.env')) {
await config.compileConfig();
}
if (!fs.existsSync('etc/env/dev.env')) {
await config.compileConfig();
}
}
if (!fs.existsSync(envFile)) {
throw new Error('ZkSync config file not found: ' + envFile);
}
process.env.ZKSYNC_ENV = zksyncEnv;
process.env.ENV_FILE = envFile;
process.env.ENV_DIR = envDir
process.env.ENV_DIR = envDir;
dotenv.config({ path: envFile });
}

Expand All @@ -92,14 +91,14 @@ export function modify(variable: string, assignedVariable: string) {
reload();
}

export function modify_contracts_toml(variable: string, assignedVariable: string){
const toml_file =`${process.env.ENV_DIR}/contracts.toml`;
export function modify_contracts_toml(variable: string, assignedVariable: string) {
const toml_file = `${process.env.ENV_DIR}/contracts.toml`;
const source = fs.readFileSync(toml_file).toString();
const toml_res = toml.parse(source);
const trimmed_variable = variable.replace("CONTRACTS_", "");
const trimmed_value = assignedVariable.split("=");
const trimmed_variable = variable.replace('CONTRACTS_', '');
const trimmed_value = assignedVariable.split('=');
// @ts-ignore
toml_res["contracts"][trimmed_variable] = trimmed_value[1];
toml_res['contracts'][trimmed_variable] = trimmed_value[1];
fs.writeFileSync(toml_file, toml.stringify(toml_res));
}

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function genesis() {
fs.mkdirSync(`logs/${label}`, { recursive: true });
fs.copyFileSync('genesis.log', `logs/${label}/genesis.log`);
env.modify('CONTRACTS_GENESIS_ROOT', genesisRoot);
env.modify_contracts_toml("CONTRACTS_GENESIS_ROOT", genesisRoot);
env.modify_contracts_toml('CONTRACTS_GENESIS_ROOT', genesisRoot);
}

export const command = new Command('server')
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,11 @@
dependencies:
"@hapi/hoek" "^8.3.0"

"@iarna/toml@^2.2.5":
version "2.2.5"
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
integrity sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==

"@intervolga/optimize-cssnano-plugin@^1.0.5":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@intervolga/optimize-cssnano-plugin/-/optimize-cssnano-plugin-1.0.6.tgz#be7c7846128b88f6a9b1d1261a0ad06eb5c0fdf8"
Expand Down Expand Up @@ -12612,11 +12617,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==

toml@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==

toposort@^1.0.0:
version "1.0.7"
resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029"
Expand Down

0 comments on commit 4202c60

Please sign in to comment.