Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
786e6d7
comment out unused features
osterman Jun 15, 2020
84aa9b3
push to dockerhub
osterman Jun 16, 2020
5cd64f0
use helm2
osterman Jun 16, 2020
deccf81
use helm3
osterman Jun 16, 2020
82c47ed
push to dockerhub
osterman Jun 16, 2020
317b07c
use dockerhub
osterman Jun 16, 2020
cf42520
fix typo
osterman Jun 16, 2020
b84e25d
deprecate deploy ctl
osterman Jun 16, 2020
b1a21a5
deprecate deploy ctl
osterman Jun 16, 2020
265b19f
fix yaml
osterman Jun 16, 2020
9ad4d18
add missing quote
osterman Jun 16, 2020
0086a92
set default color
osterman Jun 16, 2020
02e1607
fix annotation
osterman Jun 16, 2020
277b288
upgrade monochart
osterman Jun 16, 2020
c08e76b
set to real color
osterman Jun 16, 2020
c8cfac5
Deploy t staging sequentially
osterman Jun 16, 2020
c552957
rename pull-request to preview
osterman Jun 16, 2020
17e3d72
rename pull-request to preview
osterman Jun 16, 2020
76b8ace
downgrade helm
osterman Jun 16, 2020
bc50e0d
downgrade helm
osterman Jun 16, 2020
4a8f5c3
fix command
osterman Jun 16, 2020
290fbbb
change format
osterman Jun 16, 2020
6850186
comment like crazy
osterman Jun 16, 2020
82088de
update context
osterman Jun 16, 2020
828e081
update descriptions
osterman Jun 16, 2020
64422db
wording
osterman Jun 16, 2020
ee6eba8
fix timestamp
osterman Jun 16, 2020
32139cd
fix date time
osterman Jun 16, 2020
eab09ae
clean up format
osterman Jun 16, 2020
82e1a62
wording
osterman Jun 16, 2020
0bf3ad0
remove $
osterman Jun 16, 2020
00eac51
remove quotes
osterman Jun 16, 2020
2f9d772
add destroy action
osterman Jun 16, 2020
ca9bc96
remove quotes
osterman Jun 16, 2020
fb39778
format time
osterman Jun 16, 2020
6a49265
restore +
osterman Jun 16, 2020
b5b8a5e
fix timestamp
osterman Jun 16, 2020
4f89fee
positive reward
osterman Jun 16, 2020
5599983
repo pinning
osterman Jun 16, 2020
a101afb
use helmfile to destroy
osterman Jun 16, 2020
7415a90
Release pipeline
osterman Jun 16, 2020
b82db8b
Add deployment pipelines
osterman Jun 16, 2020
fc5cc33
fix yaml
osterman Jun 16, 2020
fb0520e
fix env
osterman Jun 16, 2020
e1c53f7
fix push
osterman Jun 16, 2020
3948b07
braces
osterman Jun 16, 2020
2974862
do not detach
osterman Jun 16, 2020
0716fc5
fix pipeline
osterman Jun 16, 2020
ec3aa86
add chart name
osterman Jun 16, 2020
6a91cc3
fix pipeline
osterman Jun 16, 2020
a1ff944
deploy pipeline fixes
osterman Jun 16, 2020
74d447f
Set release name
osterman Jun 16, 2020
d78d2ef
fix working directory
osterman Jun 16, 2020
d247c5e
create namespace and use iamge for destroy
osterman Jun 16, 2020
b23ae48
cannot create namespace with helm 3.1.3
osterman Jun 16, 2020
de23569
destroy tweaks
osterman Jun 16, 2020
52d02a4
pass more args
osterman Jun 16, 2020
41756a6
set color for destroy
osterman Jun 16, 2020
8a88bec
fix deployment notificaiton
osterman Jun 16, 2020
1b877c3
git commit message
osterman Jun 16, 2020
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
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine3.8 AS builder
FROM golang:alpine3.11 AS builder

# Copy source into builder
ADD . /src
Expand All @@ -8,12 +8,11 @@ RUN cd /src && \
go build -o example-app

# Build the final image
FROM alpine:3.8 as final
FROM alpine:3.11 as final

# Install the cloudposse alpine repository
ADD https://apk.cloudposse.com/ops@cloudposse.com.rsa.pub /etc/apk/keys/
RUN echo "@cloudposse https://apk.cloudposse.com/3.8/vendor" >> /etc/apk/repositories
RUN apk add --update bash variant@cloudposse
RUN echo "@cloudposse https://apk.cloudposse.com/3.11/vendor" >> /etc/apk/repositories

# Expose port of the app
EXPOSE 8080
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Example application for Codefresh CI/CD demonstrations.

### Codefresh Pipelines

1. Unlimited Staging Pipelines (pull-request, destroy)
1. Unlimited Staging Pipelines (preview, destroy)
2. Release Pipeline
3. Deploy Pipeline

Expand Down
19 changes: 17 additions & 2 deletions codefresh/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ stages:
- Prepare
- Build
- Push
- Deploy

steps:
main_clone:
Expand All @@ -20,13 +21,27 @@ steps:
stage: Build
type: build
description: Build image
image_name: ${{CF_REPO_NAME}}
image_name: ${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
dockerfile: Dockerfile

push_image_commit:
title: Push image with commit tag
stage: Push
type: push
candidate: ${{build_image}}
registry: dockerhub
tags:
- "${{CF_REVISION}}"
- "${{CF_REVISION}}"

deploy_master:
title: Deploying to Master
stage: "Deploy"
image: 'codefresh/cli:latest'
environment:
STAGE: master
commands:
- codefresh run ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/deploy-${{STAGE}} -d -b=${{CF_BRANCH}} -v CF_RELEASE_TAG=${{CF_REVISION}} -v CF_PRERELEASE_FLAG=${{CF_PRERELEASE_FLAG}} -v STAGE=${{STAGE}}
when:
branch:
only:
- master
61 changes: 45 additions & 16 deletions codefresh/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ steps:
- cf_export NAMESPACE=${{STAGE}}
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
- cf_export IMAGE_TAG=${{CF_RELEASE_TAG}}
- cf_export GATEWAY_HOST=example.${{BASE_HOST}}

ask_for_permission:
type: pending-approval
title: Deploy release?
stage: Prepare
- cf_export APP_SCHEME=http
- cf_export APP_HOST=${{STAGE}}.${{CF_REPO_NAME}}.${{BASE_HOST}}
- cf_export COLOR=blue
- cf_export CF_BUILD_DATE_TIME=$(date +"%Y-%m-%d/%H:%M:%S" -d @$((${{CF_BUILD_TIMESTAMP}}/1000)))

wait:
title: Wait
Expand All @@ -34,18 +32,17 @@ steps:
deploy_helmfile:
title: "Deploy with helmfile"
stage: "Deploy"
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
image: "${{IMAGE_NAME}}:${{IMAGE_TAG}}"
working_directory: /deploy/
environment:
- RELEASE_NAME=${{CF_REPO_NAME}}
commands:
# Announce the release version
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
# Deploy chart to cluster
- "/deploy/ctl --namespace=${{NAMESPACE}} blue-green"
when:
steps:
- name: ask_for_permission
on:
- approved
- "echo 'Preparing to deploy ${{IMAGE_NAME}}:${{IMAGE_TAG}}'"
- "apk add --update curl make bash git kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
- "kubectl config use-context ${{KUBE_CONTEXT}}"
# Deploy chart to cluster in a dedicated namespace
- "helmfile --namespace ${{NAMESPACE}} --selector preview=true sync"

send_slack_notification:
title: Send notification to Slack channel
Expand All @@ -54,6 +51,38 @@ steps:
working_directory: /build-harness
environment:
- PIPELINE_ENV=${{STAGE}}
- CHART_NAME=monochart
- GIT_COMMIT_SHORT=${{CF_SHORT_REVISION}}
- GIT_COMMIT_URL=${{CF_COMMIT_URL}}
- GIT_COMMIT_MESSAGE=${{CF_COMMIT_MESSAGE}}
- GIT_COMMIT_AUTHOR=${{CF_COMMIT_AUTHOR}}
- GIT_BRANCH_TAG=${{CF_BRANCH_TAG_NORMALIZED}}
commands:
- make codefresh/notify/slack/deploy/webapp
- make codefresh/notify/slack/deploy/webapp GIT_COMMIT_TIMESTAMP=$((${{CF_BUILD_TIMESTAMP}}/1000))

set_github_deployment_status_to_success:
title: Set GitHub deployment status to "success"
stage: Deploy
image: cloudposse/github-status-updater
environment:
- GITHUB_ACTION=update_state
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_REF=${{CF_REVISION}}
- GITHUB_CONTEXT=${{STAGE}}/env
- GITHUB_STATE=success
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} by @${{CF_BUILD_INITIATOR}}
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}/dashboard

add_url_to_comment_on_commit:
title: Comment on commit with the deployed URL
stage: Deploy
image: cloudposse/github-commenter
environment:
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_COMMENT_TYPE=commit
- GITHUB_COMMIT_SHA=${{CF_SHORT_REVISION}}
- 'GITHUB_COMMENT=Version ${{CF_SHORT_REVISION}} deployed by @${{CF_BUILD_INITIATOR}} to the [`${{NAMESPACE}}`](${{APP_SCHEME}}://${{APP_HOST}}/dashboard) namespace on `${{STAGE}}` at ${{CF_BUILD_DATE_TIME}}'
34 changes: 27 additions & 7 deletions codefresh/destroy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steps:
stage: Destroy
image: codefresh/cli:latest
commands:
- codefresh get builds --pipeline=destroy --pipeline=pull-request --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
- codefresh get builds --pipeline=destroy --pipeline=preview --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
retry:
maxAttempts: 10
delay: 20
Expand All @@ -21,20 +21,40 @@ steps:
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"

destroy:
title: Destroy namespace
title: Destroy Preview Environment
stage: Destroy
image: cloudposse/build-harness:${{BUILD_HARNESS_VERSION}}
working_directory: /build-harness/
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
working_directory: /deploy/
environment:
- NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
- RELEASE_NAME=${{CF_REPO_NAME}}
- COLOR=blue
commands:
- "apk add kubectl"
- "apk add kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
- "kubectl config use-context ${{KUBE_CONTEXT}}"
- "make helm/delete/namespace"
- "make helm/delete/namespace/empty"
- "helmfile --namespace ${NAMESPACE} --selector preview=true destroy"
when:
condition:
any:
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"

set_github_destroy_status_to_success:
title: Set GitHub destroy status to "success"
stage: Destroy
image: cloudposse/github-status-updater
environment:
- GITHUB_ACTION=update_state
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_REF=${{CF_REVISION}}
- GITHUB_CONTEXT=preview/env
- GITHUB_STATE=success
- GITHUB_DESCRIPTION=Destroyed by @${{CF_BUILD_INITIATOR}}
- GITHUB_TARGET_URL=${{CF_BUILD_URL}}
when:
condition:
any:
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == false"
validatePRAction: "'${{CF_PULL_REQUEST_ACTION}}' == 'closed'"
41 changes: 32 additions & 9 deletions codefresh/pull-request.yaml → codefresh/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ steps:
stage: Prepare
image: alpine
commands:
- cf_export COLOR=blue
- cf_export STAGE=preview
- cf_export GIT_BRANCH=${{CF_BRANCH}}
- cf_export PROJECT=${{CF_REPO_NAME}}
- cf_export APP_NAME=${{CF_REPO_NAME}}
- cf_export CHART_NAME=monochart
- cf_export PIPELINE_ENV=integration
- cf_export NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
- cf_export RELEASE_NAME=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
- cf_export RELEASE_NAME=${{CF_REPO_NAME}}
- cf_export APP_SCHEME=http
- cf_export APP_HOST=pr-${{CF_PULL_REQUEST_NUMBER}}.${{CF_REPO_NAME}}.${{BASE_HOST}}
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
- cf_export IMAGE_TAG=${{CF_REVISION}}
- cf_export CF_BUILD_DATE_TIME=$(date +"%Y-%m-%d/%H:%M:%S" -d @$((${{CF_BUILD_TIMESTAMP}}/1000)))

build:
type: parallel
Expand All @@ -40,7 +44,7 @@ steps:
title: Build image
type: build
description: Build app
image_name: ${{CF_REPO_NAME}}
image_name: ${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
tag: ${{CF_SHORT_REVISION}}
dockerfile: Dockerfile
no_cache: false
Expand Down Expand Up @@ -91,10 +95,10 @@ steps:
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_REF=${{CF_REVISION}}
- GITHUB_CONTEXT=Staging Environment
- GITHUB_CONTEXT=${{STAGE}}/env
- GITHUB_STATE=pending
- GITHUB_DESCRIPTION=Deploying changes to ${{NAMESPACE}} namespace
- GITHUB_TARGET_URL=http://${{APP_HOST}}
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}
when:
condition:
all:
Expand All @@ -105,6 +109,7 @@ steps:
title: Push image with commit tag
stage: Deploy
type: push
registry: dockerhub
candidate: ${{build_image}}
tags:
- "${{CF_REVISION}}"
Expand All @@ -114,7 +119,7 @@ steps:
stage: Deploy
image: codefresh/cli:latest
commands:
- codefresh get builds --pipeline=destroy --pipeline=pull-request --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
- codefresh get builds --pipeline=destroy --pipeline=preview --branch=${{CF_BRANCH}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
retry:
maxAttempts: 10
delay: 20
Expand All @@ -132,8 +137,11 @@ steps:
commands:
# Announce the release version
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
# Downgrade to helm 3.1.3: https://github.com/helm/helm/issues/7956
- "apk add --update curl make bash git kubectl@cloudposse helm@cloudposse=3.1.3-r0 helmfile@cloudposse"
- "kubectl config use-context ${{KUBE_CONTEXT}}"
# Deploy chart to cluster in a dedicated namespace
- "/deploy/ctl --namespace=${{NAMESPACE}} rolling"
- "helmfile --namespace ${{NAMESPACE}} --selector preview=true sync"
when:
condition:
any:
Expand All @@ -149,10 +157,10 @@ steps:
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_REF=${{CF_REVISION}}
- GITHUB_CONTEXT=Staging Environment
- GITHUB_CONTEXT=${{STAGE}}/env
- GITHUB_STATE=success
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} namespace
- GITHUB_TARGET_URL=http://${{APP_HOST}}
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} by @${{CF_BUILD_INITIATOR}}
- GITHUB_TARGET_URL=${{APP_SCHEME}}://${{APP_HOST}}/dashboard
when:
condition:
all:
Expand All @@ -177,3 +185,18 @@ steps:
any:
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"

add_url_to_comment_on_commit:
title: Comment on commit with the deployed URL
stage: Deploy
image: cloudposse/github-commenter
environment:
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
- GITHUB_OWNER=${{CF_REPO_OWNER}}
- GITHUB_REPO=${{CF_REPO_NAME}}
- GITHUB_COMMENT_TYPE=commit
- GITHUB_COMMIT_SHA=${{CF_SHORT_REVISION}}
- 'GITHUB_COMMENT=Version ${{CF_SHORT_REVISION}} deployed by @${{CF_BUILD_INITIATOR}} to the [`${{NAMESPACE}}`](${{APP_SCHEME}}://${{APP_HOST}}/dashboard) namespace on `${{STAGE}}` at ${{CF_BUILD_DATE_TIME}}<details>![:thumbsup:](https://cloudposse.com/urand/familyguy.gif)</details>'
when:
condition:
all:
deployLabel: "match('${{CF_PULL_REQUEST_LABELS}}', 'deploy', false) == true"
Loading