Add Docker image and Snapshot commands

This commit is contained in:
Jacob Evans 2018-12-17 12:42:27 +11:00
parent 737d1dc54d
commit 2a577e0475
No known key found for this signature in database
GPG Key ID: 2036DA2ADDFB0842
5 changed files with 55 additions and 2 deletions

View File

@ -17,6 +17,7 @@ export interface Web3Config {
shouldThrowErrorsOnGanacheRPCResponse?: boolean; // default: true
rpcUrl?: string; // default: localhost:8545
shouldUseFakeGasEstimate?: boolean; // default: true
ganacheDatabasePath?: string; // default: undefined, creates a tmp dir
}
export const web3Factory = {
@ -45,9 +46,14 @@ export const web3Factory = {
const shouldThrowErrorsOnGanacheRPCResponse =
_.isUndefined(config.shouldThrowErrorsOnGanacheRPCResponse) ||
config.shouldThrowErrorsOnGanacheRPCResponse;
if (!_.isUndefined(config.ganacheDatabasePath)) {
// Saving the snapshot to a local db. Ganache requires this directory to exist
fs.mkdirSync(config.ganacheDatabasePath);
}
provider.addProvider(
new GanacheSubprovider({
vmErrorsOnRPCResponse: shouldThrowErrorsOnGanacheRPCResponse,
db_path: config.ganacheDatabasePath,
gasLimit: constants.GAS_LIMIT,
logger,
verbose: env.parseBoolean(EnvVars.VerboseGanache),

2
packages/migrations/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.zip
0x_ganache_snapshot

View File

@ -0,0 +1,13 @@
FROM mhart/alpine-node:10
WORKDIR /usr/src/app
RUN npm install -g ganache-cli@6.1.6
COPY 0x_ganache_snapshot ./0x_ganache_snapshot
ENV MNEMONIC "concert load couple harbor equip island argue ramp clarify fence smart topic"
ENV NETWORK_ID 50
EXPOSE 8545
CMD [ "sh", "-c", "ganache-cli --gasLimit 10000000 --db 0x_ganache_snapshot --noVMErrorsOnRPCResponse -p 8545 --networkId \"$NETWORK_ID\" -m \"$MNEMONIC\""]

View File

@ -10,13 +10,22 @@
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"clean": "shx rm -rf lib",
"clean": "shx rm -rf lib ${npm_package_config_snapshot_name} *.zip",
"lint": "tslint --format stylish --project .",
"migrate:v2": "run-s build script:migrate:v2",
"migrate:v2:snapshot": "run-s build script:migrate:v2:snapshot",
"script:migrate:v2": "node ./lib/migrate.js",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
"script:migrate:v2:snapshot": "node ./lib/migrate_snapshot.js",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES",
"build:snapshot": "rm -rf ${npm_package_config_snapshot_name} && yarn migrate:v2:snapshot && zip -r \"$(git rev-parse HEAD).zip\" ${npm_package_config_snapshot_name}",
"build:snapshot:docker": "docker build --tag ${npm_package_config_docker_snapshot_name}:${npm_package_version} --tag ${npm_package_config_docker_snapshot_name}:latest .",
"publish:snapshot": "aws s3 cp $(git rev-parse HEAD).zip ${npm_package_config_s3_snapshot_bucket}",
"publish:snapshot:docker": "docker push ${npm_package_config_docker_snapshot_name}:latest"
},
"config": {
"s3_snapshot_bucket": "s3://testrpc-snapshots",
"docker_snapshot_name": "0xorg/ganache-cli",
"snapshot_name": "0x_ganache_snapshot",
"postpublish": {
"assets": []
}

View File

@ -0,0 +1,23 @@
#!/usr/bin/env node
import { devConstants, web3Factory } from '@0x/dev-utils';
import { logUtils } from '@0x/utils';
import { Provider } from 'ethereum-types';
import { runMigrationsAsync } from './migration';
(async () => {
let providerConfigs;
let provider: Provider;
let txDefaults;
providerConfigs = { shouldUseInProcessGanache: true, ganacheDatabasePath: '0x_ganache_snapshot' };
provider = web3Factory.getRpcProvider(providerConfigs);
txDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,
};
await runMigrationsAsync(provider, txDefaults);
process.exit(0);
})().catch(err => {
logUtils.log(err);
process.exit(1);
});