Created
August 22, 2016 16:23
-
-
Save include/e5fe019a5c0b680b13c899ef7820b91f to your computer and use it in GitHub Desktop.
Makefile-kubes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| api/ | |
| |__service1/ | |
| | |_ Dockerfile | |
| | |_ src/ | |
| |__service2/ | |
| | |_ Dockerfile | |
| | |_ my.cnf | |
| |__kube/ | |
| | |_rc.yml | |
| |__Makefile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| APP_IMAGE_TAG=$(shell git log -n 1 --pretty=format:%h service1) | |
| NGINX_IMAGE_TAG=$(shell git log -n 1 --pretty=format:%h service2) | |
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: v1 | |
| kind: ReplicationController | |
| metadata: | |
| name: api-{{RC_TAG}} | |
| labels: | |
| app: api | |
| tag: "{{RC_TAG}}" | |
| spec: | |
| replicas: 3 | |
| selector: | |
| app: api | |
| tag: "{{RC_TAG}}" | |
| template: | |
| metadata: | |
| labels: | |
| app: api | |
| tag: "{{RC_TAG}}" | |
| spec: | |
| containers: | |
| - name: api-service1 | |
| image: {{SERVICE1_IMAGE}} | |
| resources: | |
| requests: | |
| cpu: 500m | |
| ports: | |
| - name: application | |
| containerPort: 3000 | |
| - name: api-service2 | |
| image: {{SERVICE2_IMAGE}} | |
| resources: | |
| requests: | |
| cpu: 100m | |
| ports: | |
| - name: http | |
| containerPort: 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment