Readme, read snapshot name from package.json

This commit is contained in:
Jacob Evans 2018-12-27 12:45:29 +11:00
parent 2b7875571d
commit 9d5d0dbe14
No known key found for this signature in database
GPG Key ID: 2036DA2ADDFB0842
3 changed files with 52 additions and 2 deletions

View File

@ -57,3 +57,44 @@ In order to migrate the V2 0x smart contracts to TestRPC/Ganache running at `htt
```bash
yarn migrate:v2
```
### Publish
#### 0x Ganache Snapshot
The 0x Ganache snapshot can be generated and published in this package. In order to build the snapshot for this version of migrations run:
```bash
yarn build:snapshot
```
This will run the migrations in Ganache and output a zip file to be uploaded to the s3 bucket. For example, after running this command you will have created `0x_ganache_snapshot-2.2.2.zip`. To publish the zip file to the s3 bucket run:
```bash
yarn publish:snapshot
```
This snapshot will now be publicly available at http://ganache-snapshots.0x.org.s3.amazonaws.com/0x_ganache_snapshot-latest.zip and also versioned with the package.json version.
#### 0x Ganache Docker Image
We also publish a simple docker image which downloads the latest snapshot, extracts and runs Ganache. This is not required to be built when migrations change as it always downloads and runs the latest zip file. If you have made changes to the Dockerfile then a publish of the image is required. To do this run:
```bash
yarn build:snapshot:docker
yarn publish:snapshot:docker
```
The result is a published docker image to the 0xorg docker registry. To start the docker image run:
```bash
docker run -p 8545:8545 -ti 0xorg/ganache-cli:latest
```
This will pull the latest zip in the s3 bucket, extract and start Ganache with the snapshot.
In the event you need a specific version of the published Ganache snapshot run the following specifying the VERSION environment variable:
```bash
docker run -e VERSION=2.2.2 -p 8545:8545 -ti 0xorg/ganache-cli:latest
```

View File

@ -10,7 +10,7 @@
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"clean": "shx rm -rf lib ${npm_package_config_snapshot_name} *.zip",
"clean": "shx rm -rf lib ${npm_package_config_snapshot_name} ${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",

View File

@ -2,6 +2,9 @@
import { devConstants, web3Factory } from '@0x/dev-utils';
import { logUtils } from '@0x/utils';
import { Provider } from 'ethereum-types';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import { runMigrationsAsync } from './migration';
@ -9,8 +12,14 @@ import { runMigrationsAsync } from './migration';
let providerConfigs;
let provider: Provider;
let txDefaults;
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJsonString = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonString);
if (_.isUndefined(packageJson.config) || _.isUndefined(packageJson.config.snapshot_name)) {
throw new Error(`Did not find 'snapshot_name' key in package.json config`);
}
providerConfigs = { shouldUseInProcessGanache: true, ganacheDatabasePath: '0x_ganache_snapshot' };
providerConfigs = { shouldUseInProcessGanache: true, ganacheDatabasePath: packageJson.config.snapshot_name };
provider = web3Factory.getRpcProvider(providerConfigs);
txDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,