Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mumoshu opened this issue Nov 13, 2018 · 0 comments
Open

Comments

@mumoshu
Copy link
Owner

mumoshu commented Nov 13, 2018

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:

  • A CodeDeploy application (if missing)
  • A CodeDeploy revision for the application
  • A CodeDeploy deployment group (if missing)
  • A CodeDeploy deployment in the group

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

  • An auto-generated appspec.yml, before-install.sh, and after-install.sh
  • Everything inside the current working directory, so that it can be used from within the CodeDeploy deployment script

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant