From 84163517c600ff64e0d6ece4ecba40a8aeb52d73 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 14 Jan 2019 15:24:00 +0100 Subject: Add additional check to make sure user was added to our DockerHub org --- packages/monorepo-scripts/src/utils/configs.ts | 1 + .../monorepo-scripts/src/utils/docker_hub_utils.ts | 65 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 packages/monorepo-scripts/src/utils/docker_hub_utils.ts (limited to 'packages/monorepo-scripts/src/utils') diff --git a/packages/monorepo-scripts/src/utils/configs.ts b/packages/monorepo-scripts/src/utils/configs.ts index e579bdb7c..b6b6e2c5e 100644 --- a/packages/monorepo-scripts/src/utils/configs.ts +++ b/packages/monorepo-scripts/src/utils/configs.ts @@ -5,4 +5,5 @@ const REMOTE_NPM_REGISTRY_URL = 'https://registry.npmjs.org'; export const configs = { IS_LOCAL_PUBLISH, NPM_REGISTRY_URL: IS_LOCAL_PUBLISH ? LOCAL_NPM_REGISTRY_URL : REMOTE_NPM_REGISTRY_URL, + DOCKER_HUB_ORG: '0xorg', }; 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 { + 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 { + 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 { + 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 + }`, + ); + } + }, +}; -- cgit v1.2.3 From c09825660c04f6a3b46dcb5139caa856859a5f7a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 17 Jan 2019 16:14:19 +0100 Subject: Increase the Buffer size when fetching tags --- packages/monorepo-scripts/src/utils/utils.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/monorepo-scripts/src/utils') diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 95b187cc2..28c5658f3 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -106,8 +106,10 @@ export const utils = { return nextVersionIfValid; }, async getRemoteGitTagsAsync(): Promise { + const TEN_MEGA_BYTES = 1024 * 1024 * 10; // tslint:disable-line custom-no-magic-numbers const result = await execAsync(`git ls-remote --tags`, { cwd: constants.monorepoRootPath, + maxBuffer: TEN_MEGA_BYTES, }); const tagsString = result.stdout; const tagOutputs: string[] = tagsString.split('\n'); -- cgit v1.2.3