Skip to content

Commit 5167ef0

Browse files
authored
Add pipelines for unlimited staging (#3)
* Add pipelines for unlimited staging
1 parent 1000755 commit 5167ef0

File tree

9 files changed

+200
-46
lines changed

9 files changed

+200
-46
lines changed

codefresh/deploy.yaml

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,7 @@ steps:
1313
- cf_export NAMESPACE=${{STAGE}}
1414
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
1515
- cf_export IMAGE_TAG=${{CF_RELEASE_TAG}}
16-
17-
set_github_deployment_status_to_pending:
18-
title: Set GitHub deployment status to "pending"
19-
stage: Deploy
20-
image: cloudposse/github-status-updater
21-
environment:
22-
- GITHUB_ACTION=update_state
23-
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
24-
- GITHUB_OWNER=${{CF_REPO_OWNER}}
25-
- GITHUB_REPO=${{CF_REPO_NAME}}
26-
- GITHUB_REF=${{CF_REVISION}}
27-
- GITHUB_CONTEXT=${{STAGE}}-environment
28-
- GITHUB_STATE=pending
29-
- GITHUB_DESCRIPTION=Deploying changes to ${{NAMESPACE}} namespace
30-
- GITHUB_TARGET_URL=${{ATLANTIS_ATLANTIS_URL}}
31-
when:
32-
condition:
33-
all:
34-
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
16+
- cf_export GATEWAY_HOST=example.${{BASE_HOST}}
3517

3618
deploy_helmfile:
3719
title: "Deploy with helmfile"
@@ -41,25 +23,6 @@ steps:
4123
commands:
4224
# Announce the release version
4325
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
44-
- echo dev > .ctlenv
4526
# Deploy chart to cluster
4627
- "/deploy/ctl --namespace=${{NAMESPACE}} blue-green"
4728

48-
set_github_deployment_status_to_success:
49-
title: Set GitHub deployment status to "success"
50-
stage: "Deploy"
51-
image: cloudposse/github-status-updater
52-
environment:
53-
- GITHUB_ACTION=update_state
54-
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
55-
- GITHUB_OWNER=${{CF_REPO_OWNER}}
56-
- GITHUB_REPO=${{CF_REPO_NAME}}
57-
- GITHUB_REF=${{CF_REVISION}}
58-
- GITHUB_CONTEXT=${{STAGE}}-environment
59-
- GITHUB_STATE=success
60-
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} namespace
61-
- GITHUB_TARGET_URL=${{ATLANTIS_ATLANTIS_URL}}
62-
when:
63-
condition:
64-
all:
65-
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"

codefresh/destroy.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Destroy
5+
6+
steps:
7+
main_clone:
8+
title: Destroy namespace
9+
stage: Destroy
10+
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
11+
working_directory: /build-harness/
12+
environment:
13+
- NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
14+
commands:
15+
- "kubectl config use-context ${{KUBE_CONTEXT}}"
16+
- "make helm/delete/namespace"
17+
- "make helm/delete/namespace/empty"

codefresh/pull-request.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Build
6+
- Push
7+
- Deploy
8+
9+
steps:
10+
main_clone:
11+
title: "Clone repository"
12+
type: git-clone
13+
stage: Prepare
14+
description: "Initialize"
15+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
16+
git: CF-default
17+
revision: ${{CF_REVISION}}
18+
19+
export:
20+
title: Export Environment
21+
stage: Prepare
22+
image: alpine
23+
commands:
24+
- cf_export GIT_BRANCH=${{CF_BRANCH}}
25+
- cf_export PROJECT=${{CF_REPO_NAME}}
26+
- cf_export APP_NAME=${{CF_REPO_NAME}}
27+
- cf_export CHART_NAME=monochart
28+
- cf_export PIPELINE_ENV=integration
29+
- cf_export NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
30+
- cf_export RELEASE_NAME=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
31+
- cf_export APP_HOST=pr-${{CF_PULL_REQUEST_NUMBER}}.${{CF_REPO_NAME}}.${{BASE_HOST}}
32+
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
33+
- cf_export IMAGE_TAG=${{CF_REVISION}}
34+
35+
build_image:
36+
title: Build image
37+
stage: Build
38+
type: build
39+
description: Build app
40+
image_name: ${{CF_REPO_NAME}}
41+
dockerfile: Dockerfile
42+
no_cache: false
43+
no_cf_cache: false
44+
45+
push_image_commit:
46+
title: Push image with commit tag
47+
stage: Push
48+
type: push
49+
candidate: ${{build_image}}
50+
tags:
51+
- "${{CF_REVISION}}"
52+
53+
set_github_deployment_status_to_pending:
54+
title: Set GitHub deployment status to "pending"
55+
stage: Deploy
56+
image: cloudposse/github-status-updater
57+
environment:
58+
- GITHUB_ACTION=update_state
59+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
60+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
61+
- GITHUB_REPO=${{CF_REPO_NAME}}
62+
- GITHUB_REF=${{CF_REVISION}}
63+
- GITHUB_CONTEXT=Staging Environment
64+
- GITHUB_STATE=pending
65+
- GITHUB_DESCRIPTION=Deploying changes to ${{NAMESPACE}} namespace
66+
- GITHUB_TARGET_URL=http://${{APP_HOST}}
67+
when:
68+
condition:
69+
all:
70+
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
71+
72+
deploy_helmfile:
73+
title: Deploy with helmfile
74+
stage: Deploy
75+
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
76+
working_directory: /deploy/
77+
commands:
78+
# Announce the release version
79+
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
80+
# Deploy chart to cluster in a dedicated namespace
81+
- "/deploy/ctl --namespace=${{NAMESPACE}} rolling"
82+
83+
set_github_deployment_status_to_success:
84+
title: Set GitHub deployment status to "success"
85+
stage: Deploy
86+
image: cloudposse/github-status-updater
87+
environment:
88+
- GITHUB_ACTION=update_state
89+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
90+
- GITHUB_OWNER=${{CF_REPO_OWNER}}
91+
- GITHUB_REPO=${{CF_REPO_NAME}}
92+
- GITHUB_REF=${{CF_REVISION}}
93+
- GITHUB_CONTEXT=Staging Environment
94+
- GITHUB_STATE=success
95+
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} namespace
96+
- GITHUB_TARGET_URL=http://${{APP_HOST}}
97+
when:
98+
condition:
99+
all:
100+
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
101+
102+
send_slack_notification:
103+
title: Send notification to Slack channel
104+
stage: Deploy
105+
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
106+
commands:
107+
- make codefresh/notify/slack/deploy/webapp

deploy/.ctlenv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dev

deploy/ctl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,28 @@ tasks:
4242
if [ -f ${config} ]; then
4343
cat ${config}
4444
else
45+
echo "Initializing as blue" >&2
4546
echo "blue" | tee ${config}
4647
fi
4748

49+
rolling:
50+
description: "Trigger a standard rolling deployment without istio"
51+
52+
parameters:
53+
- name: color
54+
type: string
55+
default: "black"
56+
description: "Selected color to deploy"
57+
58+
steps:
59+
- task: deps
60+
- task: use-context
61+
- script: |
62+
export COLOR={{ get "color" }}
63+
echo "Updating [${KUBE_CONTEXT}] context {{ get "namespace" }} namespace with color=${COLOR}"
64+
# Deploy the app and update istio virtual service
65+
helmfile --namespace {{ get "namespace" }} --selector pull-request=true sync
66+
4867
blue-green:
4968
description: "Trigger a blue-green deployment"
5069
parameters:
@@ -73,6 +92,8 @@ tasks:
7392
echo "Config file is ${config}"
7493
echo "Updating [${KUBE_CONTEXT}] context {{ get "namespace" }} namespace: $cur_color => $new_color"
7594
export COLOR=$new_color
95+
export APP_HOST=${COLOR}.example.${BASE_HOST}
96+
export RELEASE_NAME=example-${COLOR}
7697
# Deploy the app and update istio virtual service
7798
helmfile --namespace {{ get "namespace" }} sync
7899
echo "$new_color" > ${config}

deploy/helmfile.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Ordered list of releases.
22
helmfiles:
3+
- "releases/pull-secret.yaml"
34
- "releases/app.yaml"
45
- "releases/istio.yaml"

deploy/releases/app.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ releases:
88
# References:
99
# - https://github.com/cloudposse/charts/blob/master/incubator/monochart
1010
#
11-
- name: 'example-{{ requiredEnv "COLOR" }}'
11+
- name: '{{ requiredEnv "RELEASE_NAME" }}'
1212
labels:
1313
color: "{{ requiredEnv "COLOR" }}"
14+
pull-request: "true"
1415
chart: "cloudposse-incubator/monochart"
1516
version: "0.7.0"
1617
wait: true
@@ -23,7 +24,7 @@ releases:
2324
tag: '{{ env "IMAGE_TAG" | default "0.1.0" }}'
2425
pullPolicy: Always
2526
pullSecrets:
26-
- "pull-secret"
27+
- "{{ requiredEnv "RELEASE_NAME" }}-pull-secret-dockercfg "
2728
replicaCount: 5
2829
# Deployment configuration
2930
deployment:
@@ -64,14 +65,14 @@ releases:
6465
external-dns.alpha.kubernetes.io/target: '{{ requiredEnv "NGINX_INGRESS_HOSTNAME" }}'
6566
external-dns.alpha.kubernetes.io/ttl: "60"
6667
hosts:
67-
### Required: APP_HOSTNAME;
68-
'{{ requiredEnv "COLOR" }}.{{ env "APP_HOSTNAME" }}': /
68+
### Required: APP_HOST;
69+
'{{ env "APP_HOST" }}': /
6970
tls:
7071
### Optional: ATLANTIS_TLS_SECRET_NAME;
7172
- secretName: '{{ env "APP_TLS_SECRET_NAME" | default (requiredEnv "COLOR" | printf "example-%s-server-tls") }}'
7273
hosts:
73-
### Required: APP_HOSTNAME;
74-
- '{{ requiredEnv "COLOR" }}.{{ env "APP_HOSTNAME" }}'
74+
### Required: APP_HOST;
75+
- '{{ env "APP_HOST" }}'
7576

7677
probes:
7778
# Probe that ensures service is healthy

deploy/releases/istio.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ releases:
3232
name: http
3333
protocol: HTTP
3434
hosts:
35-
- "{{ env "APP_HOSTNAME" }}"
35+
- "{{ env "GATEWAY_HOST" }}"
3636

3737
# Istio Virtual Service
3838
- apiVersion: networking.istio.io/v1alpha3
@@ -41,7 +41,7 @@ releases:
4141
name: example-app
4242
spec:
4343
hosts:
44-
- "{{ env "APP_HOSTNAME" }}"
44+
- "{{ env "GATEWAY_HOST" }}"
4545
gateways:
4646
- example-app
4747
http:

deploy/releases/pull-secret.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Deploy Docker Repository Pull Secrets
3+
#
4+
5+
#
6+
# Helm Defaults
7+
#
8+
helmDefaults:
9+
wait: true
10+
verify: false
11+
timeout: 600
12+
recreatePods: false
13+
force: true
14+
15+
repositories:
16+
# Cloud Posse incubator repo of helm charts
17+
- name: "cloudposse-incubator"
18+
url: "https://charts.cloudposse.com/incubator/"
19+
#
20+
# Kubernetes cluster
21+
#
22+
context: '{{ requiredEnv "KUBE_CONTEXT" }}'
23+
24+
#
25+
# Helm Releases
26+
#
27+
releases:
28+
# Pull Secret (.dockercfg)
29+
- name: '{{ requiredEnv "RELEASE_NAME" }}-pull-secret'
30+
chart: "cloudposse-incubator/dockercfg"
31+
version: "0.1.0"
32+
namespace: '{{ requiredEnv "NAMESPACE" }}'
33+
labels:
34+
chart: "dockercfg"
35+
component: "secrets"
36+
pull-request: "true"
37+
38+
values:
39+
- image:
40+
pullSecret:
41+
registry: '{{ requiredEnv "IMAGE_PULL_SECRET_REGISTRY" }}'
42+
username: '{{ requiredEnv "IMAGE_PULL_SECRET_USERNAME" }}'
43+
password: '{{ requiredEnv "IMAGE_PULL_SECRET_PASSWORD" }}'

0 commit comments

Comments
 (0)