Skip to content

Commit

Permalink
add IaaS parameter to self-update pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Simmons <colin.simmons@engineerbetter.com>
  • Loading branch information
crsimmons committed Apr 15, 2019
1 parent 7ef8de1 commit 68d1d53
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
30 changes: 17 additions & 13 deletions fly/aws_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ type AWSPipeline struct {
PipelineTemplateParams
AWSAccessKeyID string
AWSSecretAccessKey string
credsGetter AWSCredsGetter
credsGetter AWSCredsGetter
}

// NewAWSPipeline return AWSPipeline
func NewAWSPipeline(getter AWSCredsGetter) Pipeline {
return AWSPipeline{credsGetter: getter}
}

type AWSCredsGetter = func()(string, string, error)
type AWSCredsGetter = func() (string, string, error)

var getCredsFromSession = func() (string, string, error) {
sess, err := session.NewSession()
if err != nil {
Expand All @@ -35,7 +36,7 @@ var getCredsFromSession = func() (string, string, error) {
}

//BuildPipelineParams builds params for AWS control-tower self update pipeline
func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain string) (Pipeline, error) {
func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error) {
accessKeyID, secretAccessKey, err := a.credsGetter()
if err != nil {
return nil, err
Expand All @@ -44,10 +45,11 @@ func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain s
return AWSPipeline{
PipelineTemplateParams: PipelineTemplateParams{
ControlTowerVersion: ControlTowerVersion,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
Domain: domain,
Namespace: namespace,
Region: region,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
Domain: domain,
Namespace: namespace,
Region: region,
IaaS: iaas,
},
AWSAccessKeyID: accessKeyID,
AWSSecretAccessKey: secretAccessKey,
Expand All @@ -71,12 +73,13 @@ jobs:
trigger: true
- task: update
params:
AWS_REGION: "{{ .Region }}"
DEPLOYMENT: "{{ .Deployment }}"
AWS_ACCESS_KEY_ID: "{{ .AWSAccessKeyID }}"
AWS_REGION: "{{ .Region }}"
AWS_SECRET_ACCESS_KEY: "{{ .AWSSecretAccessKey }}"
DEPLOYMENT: "{{ .Deployment }}"
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
SELF_UPDATE: true
NAMESPACE: {{ .Namespace }}
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -105,12 +108,13 @@ jobs:
trigger: true
- task: update
params:
AWS_REGION: "{{ .Region }}"
DEPLOYMENT: "{{ .Deployment }}"
AWS_ACCESS_KEY_ID: "{{ .AWSAccessKeyID }}"
AWS_REGION: "{{ .Region }}"
AWS_SECRET_ACCESS_KEY: "{{ .AWSSecretAccessKey }}"
DEPLOYMENT: "{{ .Deployment }}"
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
SELF_UPDATE: true
NAMESPACE: {{ .Namespace }}
config:
platform: linux
image_resource:
Expand Down
16 changes: 9 additions & 7 deletions fly/aws_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ jobs:
trigger: true
- task: update
params:
AWS_REGION: "eu-west-1"
DEPLOYMENT: "my-deployment"
AWS_ACCESS_KEY_ID: "access-key"
AWS_REGION: "eu-west-1"
AWS_SECRET_ACCESS_KEY: "secret-key"
DEPLOYMENT: "my-deployment"
IAAS: "AWS"
NAMESPACE: "prod"
SELF_UPDATE: true
NAMESPACE: prod
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -65,12 +66,13 @@ jobs:
trigger: true
- task: update
params:
AWS_REGION: "eu-west-1"
DEPLOYMENT: "my-deployment"
AWS_ACCESS_KEY_ID: "access-key"
AWS_REGION: "eu-west-1"
AWS_SECRET_ACCESS_KEY: "secret-key"
DEPLOYMENT: "my-deployment"
IAAS: "AWS"
NAMESPACE: "prod"
SELF_UPDATE: true
NAMESPACE: prod
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -110,7 +112,7 @@ jobs:

pipeline := NewAWSPipeline(fakeCredsGetter)

params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "eu-west-1", "ci.engineerbetter.com")
params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "eu-west-1", "ci.engineerbetter.com", "AWS")
Expect(err).ToNot(HaveOccurred())

yamlBytes, err := util.RenderTemplate("self-update pipeline", pipeline.GetConfigTemplate(), params)
Expand Down
2 changes: 1 addition & 1 deletion fly/fly.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (client *Client) writePipelineConfig(pipelinePath string, config config.Con
}
defer fileHandler.Close()

params, err := client.pipeline.BuildPipelineParams(config.GetDeployment(), config.GetNamespace(), config.GetRegion(), config.GetDomain())
params, err := client.pipeline.BuildPipelineParams(config.GetDeployment(), config.GetNamespace(), config.GetRegion(), config.GetDomain(), config.GetIAAS())
if err != nil {
return err
}
Expand Down
23 changes: 12 additions & 11 deletions fly/gcp_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ func NewGCPPipeline(credsPath string) (Pipeline, error) {
}

//BuildPipelineParams builds params for AWS control-tower self update pipeline
func (a GCPPipeline) BuildPipelineParams(deployment, namespace, region, domain string) (Pipeline, error) {
func (a GCPPipeline) BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error) {
return GCPPipeline{
PipelineTemplateParams: PipelineTemplateParams{
ControlTowerVersion: ControlTowerVersion,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
Domain: domain,
Namespace: namespace,
Region: region,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
Domain: domain,
Namespace: namespace,
Region: region,
IaaS: iaas,
},
GCPCreds: a.GCPCreds,
}, nil
Expand Down Expand Up @@ -63,10 +64,10 @@ jobs:
params:
AWS_REGION: "{{ .Region }}"
DEPLOYMENT: "{{ .Deployment }}"
IAAS: GCP
SELF_UPDATE: true
NAMESPACE: {{ .Namespace }}
GCPCreds: '{{ .GCPCreds }}'
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
SELF_UPDATE: true
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -98,10 +99,10 @@ jobs:
params:
AWS_REGION: "{{ .Region }}"
DEPLOYMENT: "{{ .Deployment }}"
IAAS: GCP
SELF_UPDATE: true
NAMESPACE: "{{ .Namespace }}"
GCPCreds: '{{ .GCPCreds }}'
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
SELF_UPDATE: true
config:
platform: linux
image_resource:
Expand Down
14 changes: 7 additions & 7 deletions fly/gcp_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
params:
AWS_REGION: "europe-west1"
DEPLOYMENT: "my-deployment"
IAAS: GCP
SELF_UPDATE: true
NAMESPACE: prod
GCPCreds: 'creds-content'
IAAS: "GCP"
NAMESPACE: "prod"
SELF_UPDATE: true
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -71,10 +71,10 @@ jobs:
params:
AWS_REGION: "europe-west1"
DEPLOYMENT: "my-deployment"
IAAS: GCP
SELF_UPDATE: true
NAMESPACE: "prod"
GCPCreds: 'creds-content'
IAAS: "GCP"
NAMESPACE: "prod"
SELF_UPDATE: true
config:
platform: linux
image_resource:
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
pipeline, err := NewGCPPipeline(tempFile.Name())
Expect(err).ToNot(HaveOccurred())

params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "europe-west1", "ci.engineerbetter.com")
params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "europe-west1", "ci.engineerbetter.com", "GCP")
Expect(err).ToNot(HaveOccurred())

yamlBytes, err := util.RenderTemplate("self-update pipeline", pipeline.GetConfigTemplate(), params)
Expand Down
11 changes: 6 additions & 5 deletions fly/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package fly

// Pipeline is interface for self update pipeline
type Pipeline interface {
BuildPipelineParams(deployment, namespace, region, domain string) (Pipeline, error)
BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error)
GetConfigTemplate() string
}

type PipelineTemplateParams struct {
ControlTowerVersion string
Deployment string
Domain string
Namespace string
Region string
Deployment string
Domain string
Namespace string
Region string
IaaS string
}

const selfUpdateResources = `
Expand Down

0 comments on commit 68d1d53

Please sign in to comment.