Skip to content

Commit

Permalink
Move CI autodetection to cdk.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jogold committed Feb 20, 2019
1 parent 67947f6 commit f85c776
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }))
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface DeployStackOptions {
roleArn?: string;
deployName?: string;
quiet?: boolean;
ci?: boolean;
ci: boolean;
}

const LARGE_TEMPLATE_SIZE_KB = 50;
Expand All @@ -40,7 +40,7 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt
throw new Error(`The stack ${options.stack.name} does not have an environment`);
}

const params = await prepareAssets(options.stack, options.toolkitInfo, options.ci);
const params = await prepareAssets(options.stack, options.ci, options.toolkitInfo);

const deployName = options.deployName || options.stack.name;

Expand Down
8 changes: 4 additions & 4 deletions packages/aws-cdk/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { zipDirectory } from './archive';
import { prepareContainerAsset } from './docker';
import { debug, success } from './logging';

export async function prepareAssets(stack: SynthesizedStack, toolkitInfo?: ToolkitInfo, ci?: boolean): Promise<CloudFormation.Parameter[]> {
export async function prepareAssets(stack: SynthesizedStack, ci: boolean, toolkitInfo?: ToolkitInfo): Promise<CloudFormation.Parameter[]> {
const assets = findAssets(stack.metadata);
if (assets.length === 0) {
return [];
Expand All @@ -26,21 +26,21 @@ 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<CloudFormation.Parameter[]> {
async function prepareAsset(asset: AssetMetadataEntry, ci: boolean, toolkitInfo: ToolkitInfo): Promise<CloudFormation.Parameter[]> {
debug('Preparing asset', JSON.stringify(asset));
switch (asset.packaging) {
case 'zip':
return await prepareZipAsset(asset, 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.`);
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-cdk/lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloudFormation.Parameter[]> {
ci: boolean,
toolkitInfo: ToolkitInfo): Promise<CloudFormation.Parameter[]> {
debug(' 👑 Preparing Docker image asset:', asset.path);

const buildHold = new PleaseHold(` ⌛ Building Docker image for ${asset.path}; this may take a while.`);
Expand All @@ -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;

Expand All @@ -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();
Expand Down

0 comments on commit f85c776

Please sign in to comment.