Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipelines): CodeBuild images have (too) old Node version #9446

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ yarn-error.log
# Parcel default cache directory
.parcel-cache

# Cloud9
.c9
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as path from 'path';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a part of using --fix to clean up linting issues. It seems it had a bad import order throwing a warning beforehand anyway.

import * as cfn from '@aws-cdk/aws-cloudformation';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as cpactions from '@aws-cdk/aws-codepipeline-actions';
import * as events from '@aws-cdk/aws-events';
import * as iam from '@aws-cdk/aws-iam';
import { Arn, Construct, Fn, Stack } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import * as path from 'path';
import { appOf, assemblyBuilderOf } from '../private/construct-internals';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class PublishAssetsAction extends Construct implements codepipeline.IActi

const project = new codebuild.PipelineProject(this, 'Default', {
projectName: this.props.projectName,
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_4_0,
privileged: (props.assetType === AssetType.DOCKER_IMAGE) ? true : undefined,
},
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
Expand All @@ -92,8 +96,6 @@ export class PublishAssetsAction extends Construct implements codepipeline.IActi
},
},
}),
// Needed to perform Docker builds
environment: props.assetType === AssetType.DOCKER_IMAGE ? { privileged: true } : undefined,
role: props.role,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class UpdatePipelineAction extends Construct implements codepipeline.IAct

const selfMutationProject = new codebuild.PipelineProject(this, 'SelfMutation', {
projectName: props.projectName,
environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0 },
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/pipelines/lib/private/asset-manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// FIXME: copied from `ckd-assets`, because this tool needs to read the asset manifest aswell.
import { AssetManifest, DockerImageDestination, DockerImageSource, FileDestination, FileSource, Manifest } from '@aws-cdk/cloud-assembly-schema';
import * as fs from 'fs';
import * as path from 'path';
import { AssetManifest, DockerImageDestination, DockerImageSource, FileDestination, FileSource, Manifest } from '@aws-cdk/cloud-assembly-schema';

/**
* A manifest of assets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Get access to construct internals that we need but got removed from the Stages PR.
*/
import * as path from 'path';
import { App, IConstruct, Stage } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import * as path from 'path';

export function appOf(construct: IConstruct): App {
const root = construct.node.root;
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/pipelines/lib/synths/simple-synth-action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import * as events from '@aws-cdk/aws-events';
import { Construct } from '@aws-cdk/core';
import * as path from 'path';
import { cloudAssemblyBuildSpecDir } from '../private/construct-internals';
import { copyEnvironmentVariables, filterEmpty } from './_util';

Expand Down Expand Up @@ -54,7 +54,7 @@ export interface SimpleSynthOptions {
/**
* Build environment to use for CodeBuild job
*
* @default BuildEnvironment.LinuxBuildImage.STANDARD_1_0
* @default BuildEnvironment.LinuxBuildImage.STANDARD_4_0
*/
readonly environment?: codebuild.BuildEnvironment;

Expand Down Expand Up @@ -210,7 +210,7 @@ export class SimpleSynthAction implements codepipeline.IAction {

const project = new codebuild.PipelineProject(scope, 'CdkBuildProject', {
projectName: this.props.projectName ?? this.props.projectName,
environment: this.props.environment,
environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0, ...this.props.environment },
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class ShellScriptAction implements codepipeline.IAction {
}

this._project = new codebuild.PipelineProject(scope, 'Project', {
environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0 },
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/pipelines/test/builds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ test.each([['npm'], ['yarn']])('%s build automatically determines artifact base-

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
artifacts: {
Expand All @@ -55,6 +58,9 @@ test.each([['npm'], ['yarn']])('%s build respects subdirectory', (npmYarn) => {

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand All @@ -80,6 +86,9 @@ test.each([['npm'], ['yarn']])('%s assumes no build step by default', (npmYarn)

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand All @@ -106,6 +115,9 @@ test.each([['npm'], ['yarn']])('%s can have its install command overridden', (np

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down Expand Up @@ -141,6 +153,9 @@ test('Standard (NPM) synth can output additional artifacts', () => {

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
artifacts: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -1087,7 +1087,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -1391,7 +1391,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -1564,7 +1564,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -1594,7 +1594,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/pipelines/test/integ.pipeline.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -986,7 +986,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down Expand Up @@ -1290,7 +1290,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"Image": "aws/codebuild/standard:1.0",
"Image": "aws/codebuild/standard:4.0",
"PrivilegedMode": false,
"Type": "LINUX_CONTAINER"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/pipelines/test/pipeline-assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ test('command line properly locates assets in subassembly', () => {

// THEN
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down Expand Up @@ -107,6 +110,7 @@ test('file image asset publishers do not use privilegedmode, have right AssumeRo
},
Environment: objectLike({
PrivilegedMode: false,
Image: 'aws/codebuild/standard:4.0',
}),
});

Expand Down Expand Up @@ -137,6 +141,7 @@ test('docker image asset publishers use privilegedmode, have right AssumeRole',
})),
},
Environment: objectLike({
Image: 'aws/codebuild/standard:4.0',
PrivilegedMode: true,
}),
});
Expand All @@ -161,6 +166,9 @@ test('can control fix/CLI version used in pipeline selfupdate', () => {

// THEN
expect(stack2).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/pipelines/test/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ test('pipeline has self-mutation stage', () => {
});

expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand All @@ -200,6 +203,9 @@ test('selfmutation stage correctly identifies nested assembly of pipeline stack'

// THEN
expect(stackTemplate(nestedPipelineStack)).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/pipelines/test/testutil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as fs from 'fs';
import * as path from 'path';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import * as s3 from '@aws-cdk/aws-s3';
import { App, AppProps, Construct, Environment, SecretValue, Stack, StackProps, Stage } from '@aws-cdk/core';
import * as fs from 'fs';
import * as path from 'path';
import * as cdkp from '../lib';
import { assemblyBuilderOf } from '../lib/private/construct-internals';

Expand Down
9 changes: 9 additions & 0 deletions packages/@aws-cdk/pipelines/test/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ test('can use stack outputs as validation inputs', () => {
});

expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down Expand Up @@ -113,6 +116,9 @@ test('can use additional files from source', () => {
}),
});
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down Expand Up @@ -149,6 +155,9 @@ test('can use additional files from build', () => {
}),
});
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
Environment: {
Image: 'aws/codebuild/standard:4.0',
},
Source: {
BuildSpec: encodedJson(deepObjectLike({
phases: {
Expand Down