Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
Last active March 11, 2016 20:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erez-rabih/2a76270b95fb8b8022a7 to your computer and use it in GitHub Desktop.
Save erez-rabih/2a76270b95fb8b8022a7 to your computer and use it in GitHub Desktop.
Kubernetes deployment makefile
APP_IMAGE_TAG=$(shell git log -n 1 --pretty=format:%h server)
NGINX_IMAGE_TAG=$(shell git log -n 1 --pretty=format:%h nginx)
KUBE_TAG=$(shell git log -n 1 --pretty=format:%h kube)
RC_TAG=$(APP_IMAGE_TAG)$(NGINX_IMAGE_TAG)$(KUBE_TAG)
APP_IMAGE=my-repo/api-app:$(APP_IMAGE_TAG)
NGINX_IMAGE=my-repo/api-nginx:$(NGINX_IMAGE_TAG)
OLD_RC=$(shell kubectl get rc -l app=api -o template '--template={{(index .items 0).metadata.name}}')
define generate-rc
sed -e 's/{{RC_TAG}}/$(RC_TAG)/g;s/{{APP_IMAGE}}/$(APP_IMAGE)/g;s/{{NGINX_IMAGE}}/$(NGINX_IMAGE)/g' kube/rc.yml
endef
define get-current-rc
kubectl get rc api-$(RC_TAG)
endef
deploy: docker
$(call get-current-rc) || $(call generate-rc) | kubectl rolling-update $(OLD_RC) --update-period="5s" -f -
docker: docker-api docker-nginx
docker-nginx:
docker pull $(NGINX_IMAGE) || (docker build -t $(NGINX_IMAGE) nginx && docker push $(NGINX_IMAGE))
docker-api:
docker pull $(APP_IMAGE) || (docker build -t $(APP_IMAGE) server && docker push $(APP_IMAGE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment