Skip to content

Commit

Permalink
Move deployment configuration templates to be in files (#709)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:

Fixes #

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

/cc @nakabonne 
This PR was merged by Kapetanios.
  • Loading branch information
nghialv committed Aug 27, 2020
1 parent 66794b1 commit b2ede6a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 61 deletions.
3 changes: 2 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ buildifier(

genrule(
name = "copy_piped",
srcs = ["//cmd/piped"],
srcs = ["//cmd/piped:piped"],
outs = ["piped"],
cmd = "cp $< $@",
)
Expand All @@ -56,3 +56,4 @@ genrule(
# gazelle:exclude pkg/model/project.pb.validate.go
# gazelle:exclude pkg/model/role.pb.validate.go
# gazelle:exclude pkg/model/user.pb.validate.go
# gazelle:exclude pkg/app/api/api/deployment_config_templates.embed.go
13 changes: 13 additions & 0 deletions pkg/app/api/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
"fake_web_api.go",
"piped_api.go",
"web_api.go",
":deployment_config_templates.embed", #keep
],
importpath = "github.com/pipe-cd/pipe/pkg/app/api/api",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -35,3 +36,15 @@ go_test(
embed = [":go_default_library"],
deps = ["//pkg/app/api/service/webservice:go_default_library"],
)

load("@io_bazel_rules_go//go:def.bzl", "go_embed_data")

go_embed_data(
name = "deployment_config_templates.embed",
srcs = glob(["deploymentconfigtemplates/*"]),
flatten = True,
package = "api",
string = True,
var = "DeploymentConfigTemplates",
visibility = ["//visibility:public"],
)
71 changes: 11 additions & 60 deletions pkg/app/api/api/deployment_config_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,26 @@ var (
k8sDeploymentConfigTemplates = []*webservice.DeploymentConfigTemplate{
{
ApplicationKind: model.ApplicationKind_KUBERNETES,
Name: "Canary Deployment",
Name: "Simple",
Labels: []webservice.DeploymentConfigTemplateLabel{},
Content: DeploymentConfigTemplates["KubernetesSimple"],
},
{
ApplicationKind: model.ApplicationKind_KUBERNETES,
Name: "Canary",
Labels: []webservice.DeploymentConfigTemplateLabel{webservice.DeploymentConfigTemplateLabel_CANARY},
Content: k8sCanaryDeploymentConfigTemplate,
Content: DeploymentConfigTemplates["KubernetesCanary"],
},
{
ApplicationKind: model.ApplicationKind_KUBERNETES,
Name: "Blue/Green Deployment",
Name: "Blue/Green",
Labels: []webservice.DeploymentConfigTemplateLabel{webservice.DeploymentConfigTemplateLabel_BLUE_GREEN},
Content: k8sBluegreenDeploymentConfigTemplate,
Content: DeploymentConfigTemplates["KubernetesBlueGreen"],
},
}

terraformDeploymentConfigTemplates = []*webservice.DeploymentConfigTemplate{}
crossplaneDeploymentConfigTemplates = []*webservice.DeploymentConfigTemplate{}
lambdaDeploymentConfigTemplates = []*webservice.DeploymentConfigTemplate{}
cloudrunDeploymentConfigTemplates = []*webservice.DeploymentConfigTemplate{}
)

const (
k8sCanaryDeploymentConfigTemplate = `
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
commitMatcher:
sync: "^Revert"
pipeline:
stages:
# Deploy the workloads of CANARY variant. In this case, the number of
# workload replicas of CANARY variant is 10% of the replicas number of PRIMARY variant.
- name: K8S_CANARY_ROLLOUT
with:
replicas: 10%
# Wait 10 seconds before going to the next stage.
- name: WAIT
with:
duration: 10s
# Update the workload of PRIMARY variant to the new version.
- name: K8S_PRIMARY_ROLLOUT
# Destroy all workloads of CANARY variant.
- name: K8S_CANARY_CLEAN
`

k8sBluegreenDeploymentConfigTemplate = `
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
pipeline:
stages:
# Deploy the workloads of CANARY variant. In this case, the number of
# workload replicas of CANARY variant is the same with PRIMARY variant.
- name: K8S_CANARY_ROLLOUT
with:
replicas: 100%
# The percentage of traffic each variant should receive.
# In this case, CANARY variant will receive all of the traffic.
- name: K8S_TRAFFIC_ROUTING
with:
all: canary
- name: WAIT_APPROVAL
# Update the workload of PRIMARY variant to the new version.
- name: K8S_PRIMARY_ROLLOUT
# The percentage of traffic each variant should receive.
# In this case, PRIMARY variant will receive all of the traffic.
- name: K8S_TRAFFIC_ROUTING
with:
primary: 100
# Destroy all workloads of CANARY variant.
- name: K8S_CANARY_CLEAN
# This example is not using service mesh.
trafficSplit:
method: pod
`
)
32 changes: 32 additions & 0 deletions pkg/app/api/api/deploymentconfigtemplates/KubernetesBlueGreen
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Deploy progressively with bluegreen stragegy.
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
pipeline:
stages:
# Deploy the workloads of CANARY variant. In this case, the number of
# workload replicas of CANARY variant is the same with PRIMARY variant.
- name: K8S_CANARY_ROLLOUT
with:
replicas: 100%

# The percentage of traffic each variant should receive.
# In this case, CANARY variant will receive all of the traffic.
- name: K8S_TRAFFIC_ROUTING
with:
all: canary

# Wait a manual approval from a developer on web.
- name: WAIT_APPROVAL

# Update the workload of PRIMARY variant to the new version.
- name: K8S_PRIMARY_ROLLOUT

# The percentage of traffic each variant should receive.
# In this case, PRIMARY variant will receive all of the traffic.
- name: K8S_TRAFFIC_ROUTING
with:
primary: 100

# Destroy all workloads of CANARY variant.
- name: K8S_CANARY_CLEAN
20 changes: 20 additions & 0 deletions pkg/app/api/api/deploymentconfigtemplates/KubernetesCanary
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Deploy progressively with canary stragegy.
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
pipeline:
stages:
# Deploy the workloads of CANARY variant. In this case, the number of
# workload replicas of CANARY variant is 10% of the replicas number of PRIMARY variant.
- name: K8S_CANARY_ROLLOUT
with:
replicas: 10%

# Wait a manual approval from a developer on web.
- name: WAIT_APPROVAL

# Update the workload of PRIMARY variant to the new version.
- name: K8S_PRIMARY_ROLLOUT

# Destroy all workloads of CANARY variant.
- name: K8S_CANARY_CLEAN
4 changes: 4 additions & 0 deletions pkg/app/api/api/deploymentconfigtemplates/KubernetesSimple
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Deploy plain-yaml manifests placing in the application configuration directory without specifying pipeline.
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:

0 comments on commit b2ede6a

Please sign in to comment.