Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
701b2af
Initial implementation
osterman Jan 22, 2019
7f09af9
Update pipelines
osterman Jan 22, 2019
dc17039
Fix deps
osterman Jan 22, 2019
89f5f32
add bash dep
osterman Jan 22, 2019
8cd0373
remove deps
osterman Jan 22, 2019
85c11ee
click to crash
osterman Jan 23, 2019
46bfca7
copy public/
osterman Jan 23, 2019
35f2828
rebrand to example
osterman Jan 23, 2019
c1737cc
enable deployment
osterman Jan 23, 2019
c49221c
Enable boom
osterman Jan 23, 2019
c944557
prefix color
osterman Jan 23, 2019
6699492
Generalize
osterman Jan 23, 2019
56c67fe
fix syntax
osterman Jan 23, 2019
41e444f
Add ctl tool
osterman Jan 23, 2019
c557486
Update deployment script
osterman Jan 23, 2019
e8d4e07
Remove debug mode
osterman Jan 23, 2019
e90d29d
Update readme
osterman Jan 23, 2019
95e94fa
add bash
osterman Jan 23, 2019
57fc839
Add istio
osterman Jan 23, 2019
84587d7
helm init
osterman Jan 23, 2019
05fcd84
triage
osterman Jan 23, 2019
b4fc9b3
add details
osterman Jan 23, 2019
e600444
define context
osterman Jan 23, 2019
a9c45ad
overwrite label
osterman Jan 23, 2019
f20203d
fix istio name
osterman Jan 23, 2019
5314019
fix yaml
osterman Jan 23, 2019
864e8f5
tune settings
osterman Jan 23, 2019
579bc9c
save state after successful deploy
osterman Jan 23, 2019
4eced17
silence logs
osterman Jan 23, 2019
d3f5af8
Disable death
osterman Jan 23, 2019
0765d5b
Update public/boom.html
aknysh Jan 23, 2019
3d66d7e
Update public/index.html
aknysh Jan 23, 2019
10e7324
Update deploy/releases/istio.yaml
aknysh Jan 23, 2019
8fa849d
Update public/index.html
aknysh Jan 23, 2019
eea4d17
Update deploy/ctl
aknysh Jan 23, 2019
05be497
tune settings
osterman Jan 23, 2019
dde515a
Merge branch 'init' of github.com:cloudposse/example-app into init
osterman Jan 23, 2019
5ce2c57
Works
osterman Jan 23, 2019
d8ec981
disable exit
osterman Jan 23, 2019
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.idea
*.iml
.editorconfig
build-harness
.build-harness
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Override for Makefile
[{Makefile, makefile, GNUmakefile}]
indent_style = tab
indent_size = 4

[Makefile.*]
indent_style = tab
indent_size = 4

[*.yaml]
indent_style = spaces
indent_size = 2
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
release/*
.build-harness
build-harness/
.idea
*.iml
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:alpine3.8 AS builder

# Copy source into builder
ADD . /src

# Build the app
RUN cd /src && \
go build -o example-app

# Build the final image
FROM alpine:3.8 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

# Expose port of the app
EXPOSE 8080

# Set the runtime working directory
WORKDIR /app

# Copy the helmfile deployment configuration
COPY deploy/ /deploy/
COPY public/ /app/public/

# Install the app
COPY --from=builder /src/example-app /app/

# Define the entrypoint
ENTRYPOINT ["./example-app"]
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DOCKER_IMAGE_NAME ?= example-app
SHELL = /bin/bash

PATH:=$(PATH):$(GOPATH)/bin

-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)

build: go/build
@exit 0

run:
docker run -it -p 8080:8080 --rm $(DOCKER_IMAGE_NAME)
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# example-app
Example application for CI/CD demonstrations

Example application for Codefresh CI/CD demonstrations.

Contact <hello@cloudposse.com>
32 changes: 32 additions & 0 deletions codefresh/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '1.0'

stages:
- Prepare
- Build
- Push

steps:
main_clone:
title: "Clone repository"
type: git-clone
stage: Prepare
description: "Initialize"
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
git: CF-default
revision: ${{CF_REVISION}}

build_image:
title: Build image
stage: Build
type: build
description: Build image
image_name: ${{CF_REPO_NAME}}
dockerfile: Dockerfile

push_image_commit:
title: Push image with commit tag
stage: Push
type: push
candidate: ${{build_image}}
tags:
- "${{CF_REVISION}}"
70 changes: 70 additions & 0 deletions codefresh/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: '1.0'

stages:
- Prepare
- Deploy

steps:
main_clone:
title: "Create Context"
stage: Prepare
image: alpine
commands:
- cf_export NAMESPACE=${{STAGE}}
- cf_export IMAGE_NAME=${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}
- cf_export IMAGE_TAG=${{CF_RELEASE_TAG}}

set_github_deployment_status_to_pending:
title: Set GitHub deployment status to "pending"
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}}-environment
- GITHUB_STATE=pending
- GITHUB_DESCRIPTION=Deploying changes to ${{NAMESPACE}} namespace
- GITHUB_TARGET_URL=${{ATLANTIS_ATLANTIS_URL}}
when:
condition:
all:
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"

deploy_helmfile:
title: "Deploy with helmfile"
stage: "Deploy"
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
working_directory: /deploy/
commands:
# Announce the release version
- "echo 'Preparing to deploy version ${{CF_RELEASE_TAG}}'"
# Fetch the build-harness
- "curl -sSL -o Makefile https://git.io/build-harness"
# Initialize the build-harness
- "make init"
# Install or upgrade tiller
- "make helm/toolbox/upsert"
# Deploy chart to cluster using helmfile
- "helmfile --namespace ${{NAMESPACE}} --selector color=blue sync"

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}}-environment
- GITHUB_STATE=success
- GITHUB_DESCRIPTION=Deployed to ${{NAMESPACE}} namespace
- GITHUB_TARGET_URL=${{ATLANTIS_ATLANTIS_URL}}
when:
condition:
all:
githubNotificationsEnabled: "'${{GITHUB_NOTIFICATIONS_ENABLED}}' == 'true'"
42 changes: 42 additions & 0 deletions codefresh/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '1.0'

stages:
- Prepare
- Promote
- Deploy

steps:
main_clone:
title: "Create Context"
stage: "Prepare"
image: alpine
commands:
# Extract the postfix of a semver (e.g. 0.0.0-stage => stage)
- cf_export STAGE=$(echo ${{CF_RELEASE_TAG}} | sed -E 's/^[^-]+-?//')

pull_image_sha:
title: Pull image with commit sha
stage: "Promote"
image: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
commands:
- "true"

push_image_tag:
title: Push image with release tag
stage: "Promote"
type: push
image_name: ${{CF_REPO_NAME}}
candidate: "${{CF_DOCKER_REPO_URL}}/${{CF_REPO_NAME}}:${{CF_REVISION}}"
tags:
- "${{CF_RELEASE_TAG}}"

deploy:
title: Deploy Release
stage: "Deploy"
image: 'codefresh/cli:latest'
commands:
- codefresh run ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/deploy-${{STAGE}} -d -b=${{CF_BRANCH}} -v CF_RELEASE_TAG=${{CF_RELEASE_TAG}} -v CF_PRERELEASE_FLAG=${{CF_PRERELEASE_FLAG}} -v STAGE=${{STAGE}}
when:
condition:
all:
stageDefined: "'${{STAGE}}' != ''"
78 changes: 78 additions & 0 deletions deploy/ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env variant
# vim:set ft=yaml

parameters:
- name: config
default: .color
description: "Config file that keeps track of the current color"

- name: namespace
default: "default"
description: "Kubernetes namespace"

tasks:

# https://istio.io/docs/tasks/traffic-management/ingress/#determining-the-ingress-ip-and-ports-when-using-an-external-load-balancer
istio-ingress:
description: Output the FQHN of the Istio Ingress Gateway
script: |
kubectl --namespace istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'

# https://istio.io/docs/setup/kubernetes/quick-start/
istio-injection:
description: Enable Istio Sidecar Injection for a namespace
script: |
kubectl label namespace {{ get "namespace" }} istio-injection=enabled --overwrite=true

use-context:
description: "Configure kube-context"
script: |
kubectl config use-context ${KUBE_CONTEXT}

deps:
description: "Install alpine dependencies"
script: |
! which apk >/dev/null || apk add --update curl make bash git kubectl@cloudposse helm@cloudposse helmfile@cloudposse
helm init --client-only

color:
description: "Lookup the current color"
script: |
config=${CF_VOLUME_PATH:-.}/{{ get "config" }}
if [ -f ${config} ]; then
cat ${config}
else
echo "blue" | tee ${config}
fi

blue-green:
description: "Trigger a blue-green deployment"
parameters:
- name: color
type: string
description: "Selected color to deploy"

- name: blue
type: string
default: green
description: "Flip blue color to this color"

- name: green
type: string
default: blue
description: "Flip green color to this color"

steps:
- task: deps
- task: use-context
- task: istio-injection
- script: |
config=${CF_VOLUME_PATH:-.}/{{ get "config" }}
cur_color={{ get "color" }}
new_color={{ get "color" | get }}
echo "Config file is ${config}"
echo "Updating [${KUBE_CONTEXT}] context {{ get "namespace" }} namespace: $cur_color => $new_color"
export COLOR=$new_color
# Deploy the app and update istio virtual service
helmfile --namespace {{ get "namespace" }} sync
echo "$new_color" > ${config}
4 changes: 4 additions & 0 deletions deploy/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ordered list of releases.
helmfiles:
- "releases/app.yaml"
- "releases/istio.yaml"
Loading