From f85c77663170f73d05a06675fe8c70be58e146b8 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 20 Feb 2019 16:27:05 +0100 Subject: [PATCH] Move CI autodetection to cdk.ts --- packages/aws-cdk/bin/cdk.ts | 4 ++-- packages/aws-cdk/lib/api/deploy-stack.ts | 4 ++-- packages/aws-cdk/lib/assets.ts | 8 ++++---- packages/aws-cdk/lib/docker.ts | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 94eda56cf5ad1..ca4ff1c8b90e4 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -61,7 +61,7 @@ async function parseCommandLineArguments() { .command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' }) .option('require-approval', { type: 'string', choices: [RequireApproval.Never, RequireApproval.AnyChange, RequireApproval.Broadening], desc: 'what security-sensitive changes need manual approval' })) - .option('ci', { type: 'boolean', desc: 'Force CI detection. Use --no-ci to disable CI autodetection.', default: undefined }) + .option('ci', { type: 'boolean', desc: 'Force CI detection. Use --no-ci to disable CI autodetection.', default: process.env.CI !== undefined }) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'x', desc: 'only deploy requested stacks, don\'t include dependees' }) .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' })) @@ -326,7 +326,7 @@ async function initCommandLine() { toolkitStackName: string, roleArn: string | undefined, requireApproval: RequireApproval, - ci?: boolean) { + ci: boolean) { if (requireApproval === undefined) { requireApproval = RequireApproval.Broadening; } const stacks = await appStacks.selectStacks(stackNames, exclusively ? ExtendedStackSelection.None : ExtendedStackSelection.Upstream); diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 3ad0c95b8e0aa..0cf267256c854 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -30,7 +30,7 @@ export interface DeployStackOptions { roleArn?: string; deployName?: string; quiet?: boolean; - ci?: boolean; + ci: boolean; } const LARGE_TEMPLATE_SIZE_KB = 50; @@ -40,7 +40,7 @@ export async function deployStack(options: DeployStackOptions): Promise { +export async function prepareAssets(stack: SynthesizedStack, ci: boolean, toolkitInfo?: ToolkitInfo): Promise { const assets = findAssets(stack.metadata); if (assets.length === 0) { return []; @@ -26,13 +26,13 @@ export async function prepareAssets(stack: SynthesizedStack, toolkitInfo?: Toolk for (const asset of assets) { debug(` - ${asset.path} (${asset.packaging})`); - params = params.concat(await prepareAsset(asset, toolkitInfo, ci)); + params = params.concat(await prepareAsset(asset, ci, toolkitInfo)); } return params; } -async function prepareAsset(asset: AssetMetadataEntry, toolkitInfo: ToolkitInfo, ci?: boolean): Promise { +async function prepareAsset(asset: AssetMetadataEntry, ci: boolean, toolkitInfo: ToolkitInfo): Promise { debug('Preparing asset', JSON.stringify(asset)); switch (asset.packaging) { case 'zip': @@ -40,7 +40,7 @@ async function prepareAsset(asset: AssetMetadataEntry, toolkitInfo: ToolkitInfo, case 'file': return await prepareFileAsset(asset, toolkitInfo); case 'container-image': - return await prepareContainerAsset(asset, toolkitInfo, ci); + return await prepareContainerAsset(asset, ci, toolkitInfo); default: // tslint:disable-next-line:max-line-length throw new Error(`Unsupported packaging type: ${(asset as any).packaging}. You might need to upgrade your aws-cdk toolkit to support this asset type.`); diff --git a/packages/aws-cdk/lib/docker.ts b/packages/aws-cdk/lib/docker.ts index 8e6548e5304d5..2c2c65bb61245 100644 --- a/packages/aws-cdk/lib/docker.ts +++ b/packages/aws-cdk/lib/docker.ts @@ -29,8 +29,8 @@ import { PleaseHold } from './util/please-hold'; * the `--ci` command line option. */ export async function prepareContainerAsset(asset: ContainerImageAssetMetadataEntry, - toolkitInfo: ToolkitInfo, - ci?: boolean): Promise { + ci: boolean, + toolkitInfo: ToolkitInfo): Promise { debug(' 👑 Preparing Docker image asset:', asset.path); const buildHold = new PleaseHold(` ⌛ Building Docker image for ${asset.path}; this may take a while.`); @@ -41,7 +41,7 @@ export async function prepareContainerAsset(asset: ContainerImageAssetMetadataEn let loggedIn = false; // In CI we try to pull latest first - if (ci === true || (process.env.CI && ci !== false)) { + if (ci) { await dockerLogin(toolkitInfo); loggedIn = true; @@ -58,7 +58,7 @@ export async function prepareContainerAsset(asset: ContainerImageAssetMetadataEn 'build', '--quiet', asset.path]; - const command = process.env.CI + const command = ci ? [...baseCommand, '--cache-from', latest] // This does not fail if latest is not available : baseCommand; const imageId = (await shell(command, { quiet: true })).trim();