From 2a577e04750f9f90f72f763b45232dd9b5a35d93 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Mon, 17 Dec 2018 12:42:27 +1100 Subject: Add Docker image and Snapshot commands --- packages/migrations/.gitignore | 2 ++ packages/migrations/Dockerfile | 13 +++++++++++++ packages/migrations/package.json | 13 +++++++++++-- packages/migrations/src/migrate_snapshot.ts | 23 +++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 packages/migrations/.gitignore create mode 100644 packages/migrations/Dockerfile create mode 100644 packages/migrations/src/migrate_snapshot.ts (limited to 'packages/migrations') diff --git a/packages/migrations/.gitignore b/packages/migrations/.gitignore new file mode 100644 index 000000000..4de81c5a8 --- /dev/null +++ b/packages/migrations/.gitignore @@ -0,0 +1,2 @@ +*.zip +0x_ganache_snapshot diff --git a/packages/migrations/Dockerfile b/packages/migrations/Dockerfile new file mode 100644 index 000000000..ce4d6e867 --- /dev/null +++ b/packages/migrations/Dockerfile @@ -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\""] + diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 72ffe67b2..32d61a857 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -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": [] } diff --git a/packages/migrations/src/migrate_snapshot.ts b/packages/migrations/src/migrate_snapshot.ts new file mode 100644 index 000000000..f9b7751a5 --- /dev/null +++ b/packages/migrations/src/migrate_snapshot.ts @@ -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); +}); -- cgit v1.2.3 From bcd20081d39b2d00150fc6d67e2c481b23d03b48 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Mon, 24 Dec 2018 13:14:16 +1100 Subject: Use new bucket, bind on 0.0.0.0 --- packages/migrations/Dockerfile | 8 +++++--- packages/migrations/package.json | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'packages/migrations') diff --git a/packages/migrations/Dockerfile b/packages/migrations/Dockerfile index ce4d6e867..12f2eaa0c 100644 --- a/packages/migrations/Dockerfile +++ b/packages/migrations/Dockerfile @@ -3,11 +3,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 - +ENV VERSION "2.2.2" +ENV SNAPSHOT_HOST "http://ganache-snapshots.0x.org.s3-website.us-east-2.amazonaws.com" +ENV SNAPSHOT_NAME "0x_ganache_snapshot" EXPOSE 8545 -CMD [ "sh", "-c", "ganache-cli --gasLimit 10000000 --db 0x_ganache_snapshot --noVMErrorsOnRPCResponse -p 8545 --networkId \"$NETWORK_ID\" -m \"$MNEMONIC\""] + +CMD [ "sh", "-c", "wget $SNAPSHOT_HOST/$SNAPSHOT_NAME-$VERSION.zip -O snapshot.zip && unzip snapshot.zip && ganache-cli --gasLimit 10000000 --db $SNAPSHOT_NAME --noVMErrorsOnRPCResponse -p 8545 --networkId \"$NETWORK_ID\" -m \"$MNEMONIC\" -h 0.0.0.0"] diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 32d61a857..0f91c2972 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -17,13 +17,13 @@ "script:migrate:v2": "node ./lib/migrate.js", "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": "rm -rf ${npm_package_config_snapshot_name} && yarn migrate:v2:snapshot && zip -r \"${npm_package_config_snapshot_name}-${npm_package_version}.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": "aws s3 cp ${npm_package_config_snapshot_name}-${npm_package_version}.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", + "s3_snapshot_bucket": "s3://ganache-snapshots.0x.org", "docker_snapshot_name": "0xorg/ganache-cli", "snapshot_name": "0x_ganache_snapshot", "postpublish": { -- cgit v1.2.3 From 0a1701eac99a35dee4e39505fd9f54df6a5bc4ac Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Mon, 24 Dec 2018 13:20:50 +1100 Subject: Copy latest published version to 0x_ganache_snapshot-latest.zip --- packages/migrations/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/migrations') diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 0f91c2972..59bf30629 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -19,7 +19,7 @@ "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 \"${npm_package_config_snapshot_name}-${npm_package_version}.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 ${npm_package_config_snapshot_name}-${npm_package_version}.zip ${npm_package_config_s3_snapshot_bucket}", + "publish:snapshot": "aws s3 cp ${npm_package_config_snapshot_name}-${npm_package_version}.zip ${npm_package_config_s3_snapshot_bucket} && aws s3 cp ${npm_package_config_s3_snapshot_bucket}/${npm_package_config_snapshot_name}-${npm_package_version}.zip ${npm_package_config_s3_snapshot_bucket}/${npm_package_config_snapshot_name}-latest.zip", "publish:snapshot:docker": "docker push ${npm_package_config_docker_snapshot_name}:latest" }, "config": { -- cgit v1.2.3 From 2b7875571d8a7a980eab82633b80750458b9e80b Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Mon, 24 Dec 2018 13:22:39 +1100 Subject: Dockerfile defaults to latest --- packages/migrations/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/migrations') diff --git a/packages/migrations/Dockerfile b/packages/migrations/Dockerfile index 12f2eaa0c..c4d6128c2 100644 --- a/packages/migrations/Dockerfile +++ b/packages/migrations/Dockerfile @@ -6,7 +6,7 @@ RUN npm install -g ganache-cli@6.1.6 ENV MNEMONIC "concert load couple harbor equip island argue ramp clarify fence smart topic" ENV NETWORK_ID 50 -ENV VERSION "2.2.2" +ENV VERSION "latest" ENV SNAPSHOT_HOST "http://ganache-snapshots.0x.org.s3-website.us-east-2.amazonaws.com" ENV SNAPSHOT_NAME "0x_ganache_snapshot" EXPOSE 8545 -- cgit v1.2.3 From 9d5d0dbe144fe63469d2830c6da95940c7a78206 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 27 Dec 2018 12:45:29 +1100 Subject: Readme, read snapshot name from package.json --- packages/migrations/README.md | 41 +++++++++++++++++++++++++++++ packages/migrations/package.json | 2 +- packages/migrations/src/migrate_snapshot.ts | 11 +++++++- 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'packages/migrations') diff --git a/packages/migrations/README.md b/packages/migrations/README.md index b90d730eb..1e8b92bf8 100644 --- a/packages/migrations/README.md +++ b/packages/migrations/README.md @@ -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 +``` diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 59bf30629..0d6ad037c 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -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", diff --git a/packages/migrations/src/migrate_snapshot.ts b/packages/migrations/src/migrate_snapshot.ts index f9b7751a5..13fb063da 100644 --- a/packages/migrations/src/migrate_snapshot.ts +++ b/packages/migrations/src/migrate_snapshot.ts @@ -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, -- cgit v1.2.3