-
Notifications
You must be signed in to change notification settings - Fork 428
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
feat(manifest): support codebuild environment image config #2125
Changes from 4 commits
19c5478
bacf01d
d85e76d
a5455b9
c1f20e1
2dd9f4c
443c8c8
ac47e63
54624ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import ( | |
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const defaultImage = "aws/codebuild/amazonlinux2-x86_64-standard:3.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I want to clarify. Do you mean rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I see sorry that's my bad! you can ignore the comment then, I thought they were in the same pkg :) |
||
|
||
func TestCloudFormation_PipelineExists(t *testing.T) { | ||
in := &deploy.CreatePipelineInput{ | ||
AppName: "kudos", | ||
|
@@ -79,6 +81,9 @@ func TestCloudFormation_CreatePipeline(t *testing.T) { | |
ProviderName: "Bitbucket", | ||
Branch: "main", | ||
}, | ||
Build: &deploy.Build{ | ||
Image: defaultImage, | ||
}, | ||
Stages: nil, | ||
ArtifactBuckets: nil, | ||
} | ||
|
@@ -239,6 +244,9 @@ func TestCloudFormation_UpdatePipeline(t *testing.T) { | |
RepositoryURL: "aws/somethingCool", | ||
Branch: "main", | ||
}, | ||
Build: &deploy.Build{ | ||
Image: defaultImage, | ||
}, | ||
Stages: nil, | ||
ArtifactBuckets: nil, | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,9 @@ type CreatePipelineInput struct { | |||||||||||||||||||||||||||||||||
// The source code provider for this pipeline | ||||||||||||||||||||||||||||||||||
Source interface{} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// The build project settings for this pipeline | ||||||||||||||||||||||||||||||||||
Build *Build | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// The stages of the pipeline. The order of stages in this list | ||||||||||||||||||||||||||||||||||
// will be the order we deploy to. | ||||||||||||||||||||||||||||||||||
Stages []PipelineStage | ||||||||||||||||||||||||||||||||||
|
@@ -52,6 +55,13 @@ type CreatePipelineInput struct { | |||||||||||||||||||||||||||||||||
AdditionalTags map[string]string | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Build represents CodeBuild project used in the CodePipeline | ||||||||||||||||||||||||||||||||||
// to build and test Docker image. | ||||||||||||||||||||||||||||||||||
type Build struct { | ||||||||||||||||||||||||||||||||||
// The URI that identifies the Docker image to use for this build project. | ||||||||||||||||||||||||||||||||||
Image string | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// ArtifactBucket represents an S3 bucket used by the CodePipeline to store | ||||||||||||||||||||||||||||||||||
// intermediate artifacts produced by the pipeline. | ||||||||||||||||||||||||||||||||||
type ArtifactBucket struct { | ||||||||||||||||||||||||||||||||||
|
@@ -171,6 +181,19 @@ func PipelineSourceFromManifest(mfSource *manifest.Source) (source interface{}, | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// PipelineBuildFromManifest processes manifest info about the build project settings. | ||||||||||||||||||||||||||||||||||
func PipelineBuildFromManifest(mfBuild *manifest.Build) (build *Build) { | ||||||||||||||||||||||||||||||||||
var imageURI string | ||||||||||||||||||||||||||||||||||
if (mfBuild == nil || mfBuild.Image == "") { | ||||||||||||||||||||||||||||||||||
imageURI = manifest.DefaultImage | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
imageURI = mfBuild.Image | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return &Build{ | ||||||||||||||||||||||||||||||||||
Image: imageURI, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// GitHubPersonalAccessTokenSecretID returns the ID of the secret in the | ||||||||||||||||||||||||||||||||||
// Secrets manager, which stores the GitHub Personal Access token if the | ||||||||||||||||||||||||||||||||||
// provider is "GitHubV1". | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ const ( | |
GithubV1ProviderName = "GitHubV1" | ||
CodeCommitProviderName = "CodeCommit" | ||
BitbucketProviderName = "Bitbucket" | ||
DefaultImage = "aws/codebuild/amazonlinux2-x86_64-standard:3.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we define this constant in the |
||
|
||
pipelineManifestPath = "cicd/pipeline.yml" | ||
) | ||
|
@@ -157,6 +158,7 @@ type PipelineManifest struct { | |
Name string `yaml:"name"` | ||
Version PipelineSchemaMajorVersion `yaml:"version"` | ||
Source *Source `yaml:"source"` | ||
Build *Build `yaml:"build"` | ||
Stages []PipelineStage `yaml:"stages"` | ||
|
||
parser template.Parser | ||
|
@@ -168,6 +170,11 @@ type Source struct { | |
Properties map[string]interface{} `yaml:"properties"` | ||
} | ||
|
||
// Build defines the build project to build and test image. | ||
type Build struct { | ||
Image string `yaml:"image"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is this formatted correctly with |
||
} | ||
|
||
// PipelineStage represents a stage in the pipeline manifest | ||
type PipelineStage struct { | ||
Name string `yaml:"name"` | ||
|
@@ -190,6 +197,9 @@ func NewPipelineManifest(pipelineName string, provider Provider, stages []Pipeli | |
ProviderName: provider.Name(), | ||
Properties: provider.Properties(), | ||
}, | ||
Build: &Build{ | ||
Image: DefaultImage, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If leave the default to be |
||
Stages: stages, | ||
|
||
parser: template.New(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
const ( | ||
defaultGHBranch = "main" | ||
defaultCCBranch = "master" | ||
defaultImage = "aws/codebuild/amazonlinux2-x86_64-standard:3.0" | ||
) | ||
|
||
func TestNewProvider(t *testing.T) { | ||
|
@@ -106,6 +107,9 @@ func TestNewPipelineManifest(t *testing.T) { | |
Branch: defaultGHBranch, | ||
}), | ||
}, | ||
Build: &Build{ | ||
Image: defaultImage, | ||
}, | ||
Stages: []PipelineStage{ | ||
{ | ||
Name: "chicken", | ||
|
@@ -218,7 +222,7 @@ stages: | |
inContent: `corrupted yaml`, | ||
expectedErr: errors.New("yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `corrupt...` into manifest.PipelineManifest"), | ||
}, | ||
"valid pipeline.yml": { | ||
"valid pipeline.yml without build": { | ||
inContent: ` | ||
name: pipepiper | ||
version: 1 | ||
|
@@ -261,6 +265,48 @@ stages: | |
}, | ||
}, | ||
}, | ||
"valid pipeline.yml with build": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for writing all these tests! They are really helpful and comprehensive. |
||
inContent: ` | ||
name: pipepiper | ||
version: 1 | ||
|
||
source: | ||
provider: GitHub | ||
properties: | ||
repository: aws/somethingCool | ||
access_token_secret: "github-token-badgoose-backend" | ||
branch: main | ||
|
||
build: | ||
image: aws/codebuild/standard:3.0 | ||
|
||
stages: | ||
- | ||
name: chicken | ||
test_commands: [] | ||
`, | ||
expectedManifest: &PipelineManifest{ | ||
Name: "pipepiper", | ||
Version: Ver1, | ||
Source: &Source{ | ||
ProviderName: "GitHub", | ||
Properties: map[string]interface{}{ | ||
"access_token_secret": "github-token-badgoose-backend", | ||
"repository": "aws/somethingCool", | ||
"branch": defaultGHBranch, | ||
}, | ||
}, | ||
Build: &Build{ | ||
Image: "aws/codebuild/standard:3.0", | ||
}, | ||
Stages: []PipelineStage{ | ||
{ | ||
Name: "chicken", | ||
TestCommands: []string{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ source: | |
# Optional: specify the name of an existing CodeStar Connections connection. | ||
# connection_name: a-connection | ||
{{- end}} | ||
|
||
# This section defines the build project. | ||
build: | ||
# The URI that identifies the Docker image to use for this build project. | ||
image: {{.Build.Image}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not show this setting by default as it is mostly for advanced users. I expect most folks are satisfied with the default image that we provide. Can we instead add it as a field in our documentation here? https://github.com/aws/copilot-cli/blob/mainline/site/content/docs/manifest/pipeline.md 🙏 |
||
|
||
{{$length := len .Stages}}{{if gt $length 0}} | ||
# The deployment section defines the order the pipeline will deploy | ||
# to your environments. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to remove the extra variable