diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-17 22:59:00 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-17 22:59:00 +0800 |
commit | 293e93729176b06f7e3cf78c798f48ddf360e311 (patch) | |
tree | e47909d281ae7da6b7c9e6af76757373ad485705 /packages/monorepo-scripts/src/utils/docker_hub_utils.ts | |
parent | fe2f97dabd1511918051161c882c57bcc1d41ac2 (diff) | |
parent | 0b23aaca2619b888dd4e15774d5c543f79f4588d (diff) | |
download | dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar.gz dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar.bz2 dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar.lz dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar.xz dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.tar.zst dexon-sol-tools-293e93729176b06f7e3cf78c798f48ddf360e311.zip |
Merge branch 'development' into fix/dev-tools-pages/finalTouches
* development: (22 commits)
Fix linter
Update packages/sol-tracing-utils/src/trace_collection_subprovider.ts
Update packages/sol-tracing-utils/CHANGELOG.json
Update packages/sol-tracing-utils/CHANGELOG.json
Add PR numbers
Fix/simplify handling of revert trace snippets
Fix a bug when TraceCollectionSubprovider was hanging on the fake Geth snapshot transaction
Fix a bug when a custom Geth tracer didn't return stack entries for DELEGATECALL
Revert devnet mining period from 1 to 0
update team info, add brent
Publish
Updated CHANGELOGS
Add commented-out pre-publish checks
Add additional check to make sure user was added to our DockerHub org
Update test for required amountAvailableToFill
Add actual error message thrown
Flag order-watcher as having a Docker image to publish
Add publish to DockerHub step to publish flow
Flesh out postpublish configs in packageJSON type
Add pre-publish check to ensure publisher is logged in to docker cmdline
...
Diffstat (limited to 'packages/monorepo-scripts/src/utils/docker_hub_utils.ts')
-rw-r--r-- | packages/monorepo-scripts/src/utils/docker_hub_utils.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils/docker_hub_utils.ts b/packages/monorepo-scripts/src/utils/docker_hub_utils.ts new file mode 100644 index 000000000..62215a579 --- /dev/null +++ b/packages/monorepo-scripts/src/utils/docker_hub_utils.ts @@ -0,0 +1,65 @@ +import { fetchAsync } from '@0x/utils'; +import { exec as execAsync } from 'promisify-child-process'; + +import { utils } from './utils'; + +const API_ENDPOINT = 'https://hub.docker.com/v2'; +const HTTP_OK_STATUS = 200; + +export const dockerHubUtils = { + async getTokenAsync(): Promise<string> { + const payload = { + username: process.env.DOCKER_USERNAME, + password: process.env.DOCKER_PASS, + }; + const response = await fetchAsync(`${API_ENDPOINT}/users/login`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }); + if (response.status !== HTTP_OK_STATUS) { + throw new Error( + `DockerHub user login failed (status code: ${ + response.status + }). Make sure you have environment variables 'DOCKER_USERNAME; and 'DOCKER_PASS' set`, + ); + } + const respPayload = await response.json(); + const token = respPayload.token; + return token; + }, + async checkUserAddedToOrganizationOrThrowAsync(organization: string): Promise<void> { + utils.log('Checking that the user was added to the 0xorg DockerHub organization...'); + const token = await dockerHubUtils.getTokenAsync(); + const response = await fetchAsync(`${API_ENDPOINT}/repositories/${organization}/?page_size=10`, { + method: 'GET', + headers: { + Accept: 'application/json', + Authorization: `JWT ${token}`, + }, + }); + const respPayload = await response.json(); + if (response.status !== HTTP_OK_STATUS || respPayload.count === 0) { + throw new Error( + `Failed to fetch org: ${organization}'s list of repos (status code: ${ + response.status + }). Make sure your account has been added to the '${organization}' org on DockerHub`, + ); + } + }, + async loginUserToDockerCommandlineOrThrowAsync(): 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 the 'docker' commandline tool installed. Full error: ${ + err.message + }`, + ); + } + }, +}; |