diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-11 23:52:15 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-11 23:52:15 +0800 |
commit | 6dcf40f57057c72d1b93f61cea6fba8c8a771da4 (patch) | |
tree | 9717b9a1559244af9114b906e6a217548be93838 /packages/monorepo-scripts/src | |
parent | 43b04228040539e59611e482138f22e516cde7a2 (diff) | |
download | dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar.gz dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar.bz2 dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar.lz dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar.xz dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.tar.zst dexon-sol-tools-6dcf40f57057c72d1b93f61cea6fba8c8a771da4.zip |
Add publish to DockerHub step to publish flow
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index e39b70d9d..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'); @@ -101,6 +107,39 @@ async function confirmAsync(message: string): Promise<void> { 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()); |