aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/monorepo-scripts/src/prepublish_checks.ts14
-rw-r--r--packages/monorepo-scripts/src/publish.ts46
-rw-r--r--packages/monorepo-scripts/src/types.ts6
-rw-r--r--packages/order-watcher/package.json5
4 files changed, 67 insertions, 4 deletions
diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts
index 82eaf5cf9..75a8935c8 100644
--- a/packages/monorepo-scripts/src/prepublish_checks.ts
+++ b/packages/monorepo-scripts/src/prepublish_checks.ts
@@ -17,6 +17,20 @@ async function prepublishChecksAsync(): Promise<void> {
await checkChangelogFormatAsync(updatedPublicPackages);
await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages);
await checkPublishRequiredSetupAsync();
+ await checkDockerHubSetupAsync();
+}
+
+async function checkDockerHubSetupAsync(): Promise<void> {
+ try {
+ utils.log('Checking that the user is logged in to docker command...');
+ await execAsync(`echo "$DOCKER_PASS" | docker login -u $DOCKER_USERNAME --password-stdin`);
+ } catch (err) {
+ throw new Error(
+ `Failed to log you into the 'docker' commandline tool. Make sure you have environment variables 'DOCKER_USERNAME; and 'DOCKER_PASS' set. Full error: ${
+ err.message
+ }`,
+ );
+ }
}
async function checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages: Package[]): Promise<void> {
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts
index e0602a74f..4a22df544 100644
--- a/packages/monorepo-scripts/src/publish.ts
+++ b/packages/monorepo-scripts/src/publish.ts
@@ -1,11 +1,12 @@
#!/usr/bin/env node
+import { logUtils } from '@0x/utils';
import * as promisify from 'es6-promisify';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as moment from 'moment';
import opn = require('opn');
-import { exec as execAsync } from 'promisify-child-process';
+import { exec as execAsync, spawn as spawnAsync } from 'promisify-child-process';
import * as prompt from 'prompt';
import semver = require('semver');
import semverSort = require('semver-sort');
@@ -21,6 +22,7 @@ import { utils } from './utils/utils';
const NPM_NAMESPACE = '@0x/';
const TODAYS_TIMESTAMP = moment().unix();
+const DOCKER_ORG = '0xorg';
async function confirmAsync(message: string): Promise<void> {
prompt.start();
@@ -79,12 +81,16 @@ async function confirmAsync(message: string): Promise<void> {
});
utils.log(`Calling 'lerna publish'...`);
await lernaPublishAsync(packageToNextVersion);
- if (!configs.IS_LOCAL_PUBLISH) {
+
+ const isDryRun = configs.IS_LOCAL_PUBLISH;
+ if (!isDryRun) {
+ // Publish docker images to DockerHub
+ await publishImagesToDockerHubAsync(allPackagesToPublish);
+
const isStaging = false;
const shouldUploadDocs = true;
await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging, shouldUploadDocs);
}
- const isDryRun = configs.IS_LOCAL_PUBLISH;
const releaseNotes = await publishReleaseNotesAsync(updatedPublicPackages, isDryRun);
utils.log('Published release notes');
@@ -95,11 +101,45 @@ async function confirmAsync(message: string): Promise<void> {
utils.log("Publish successful, but couldn't auto-alert discord (", e.message, '), Please alert manually.');
}
}
+ process.exit(0);
})().catch(err => {
utils.log(err);
process.exit(1);
});
+async function publishImagesToDockerHubAsync(allUpdatedPackages: Package[]): Promise<void> {
+ for (const pkg of allUpdatedPackages) {
+ const packageJSON = pkg.packageJson;
+ const shouldPublishDockerImage =
+ !_.isUndefined(packageJSON.config) &&
+ !_.isUndefined(packageJSON.config.postpublish) &&
+ !_.isUndefined(packageJSON.config.postpublish.dockerHubRepo);
+ if (!shouldPublishDockerImage) {
+ continue;
+ }
+ const dockerHubRepo = _.get(packageJSON, 'config.postpublish.dockerHubRepo');
+ const pkgName = pkg.packageJson.name;
+ const packageDirName = _.startsWith(pkgName, '@0x/') ? pkgName.split('/')[1] : pkgName;
+
+ // Build the Docker image
+ logUtils.log(`Building '${dockerHubRepo}' docker image...`);
+ await spawnAsync('docker', ['build', '-t', dockerHubRepo, '.'], {
+ cwd: `${constants.monorepoRootPath}/packages/${packageDirName}`,
+ });
+
+ // Tag the docker image with the latest version
+ const version = pkg.packageJson.version;
+ logUtils.log(`Tagging '${dockerHubRepo}' docker image with version ${version}...`);
+ await execAsync(`docker tag ${dockerHubRepo} ${DOCKER_ORG}/${dockerHubRepo}:${version}`);
+ await execAsync(`docker tag ${dockerHubRepo} ${DOCKER_ORG}/${dockerHubRepo}:latest`);
+
+ // Publish to DockerHub
+ logUtils.log(`Pushing '${dockerHubRepo}' docker image to DockerHub...`);
+ await execAsync(`docker push ${DOCKER_ORG}/${dockerHubRepo}:${version}`);
+ await execAsync(`docker push ${DOCKER_ORG}/${dockerHubRepo}:latest`);
+ }
+}
+
function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] {
const rootPackageJsonPath = `${constants.monorepoRootPath}/package.json`;
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath).toString());
diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts
index 3c2ec5069..4af4fd257 100644
--- a/packages/monorepo-scripts/src/types.ts
+++ b/packages/monorepo-scripts/src/types.ts
@@ -41,7 +41,11 @@ export interface PackageJSON {
main?: string;
scripts?: { [command: string]: string };
config?: {
- additionalTsTypings?: string[];
+ postpublish?: {
+ assets?: string[];
+ docOmitExports?: string[];
+ dockerHubRepo?: string;
+ };
};
}
diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json
index 5919759dd..5ca2ba1ac 100644
--- a/packages/order-watcher/package.json
+++ b/packages/order-watcher/package.json
@@ -24,6 +24,11 @@
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
+ "config": {
+ "postpublish": {
+ "dockerHubRepo": "order-watcher"
+ }
+ },
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x-monorepo"