mumoshu / kodedeploy

CodeDeploy for EKS. Parallel and Continuous (re)delivery to multiple EKS clusters. Blue-green deployment "of" EKS clusters.
29 stars 5 forks source link

feat: appspec.yml-free, deployment-tool-agnostic deployment trigger #1

Open mumoshu opened 5 years ago

mumoshu commented 5 years ago

As a lazy developer who wants to automate continuous deployment of myapp to Kubernetes clusters, while not wanting to spend much time on learning yet another deployment tool(s), I want an easy way to turn any deployment command to CodeDeploy-ready.

How it should work

You just prefix your deployment command with kodedeploy FLAGS -- and CodeDeploy persists and (re)plays your command whenever necessary.

More concretely, once you run kodedeploy -- CMD, it creates:

Each revision is stored inside a S3 bucket, containing following files:

appspec.yml:

version: 0.0
os: linux
files:
  - source: deploy
    destination: /deploy
hooks:
  BeforeInstall:
  - location: codedeploy/before-install.sh
    timeout: 180
  AfterInstall:
  - location: codedeploy/after-install.sh
    timeout: 180

before-install.sh:

#!/usr/bin/env bash

rm -rf /deploy

after-install.sh:

#!/usr/bin/env bash

set -vx

wd="/opt/codedeploy-agent/deployment-root/${DEPLOYMENT_GROUP_ID}/${DEPLOYMENT_ID}/deployment-archive"
image="quay.io/roboll/helmfile:v0.40.1"

# To use kodedeploy pod's serviceaccount to access Kubernetes API
sd="/var/run/secrets/kubernetes.io/serviceaccount/"

cmd="<CMD>"

docker run -v "${wd}:${wd}" -v "${sd}:${sd}" --rm "${image}" -w "${wd}" bash -c "${cmd}"

Usage examples

With kubectl

$ kodedeploy apply --namespace myapp --environment preview -- kubectl apply -n myapp -f deploy/kubernetes

With helm

$ kodedeploy apply --namespace myapp --environment preview -- helm upgrade charts/myapp --name myapp --tiller-namespace myapp --namespace myapp

With helm-tiller

$ kodedeploy apply --namespace myapp --environment preview -- helm tiller run myapp -- upgrade charts/myapp --name myapp --namespace myapp