Skip to content

Commit

Permalink
Convert mungegithub to use deployments instead of RCs
Browse files Browse the repository at this point in the history
Simplifies makefile mess
  • Loading branch information
eparis committed Apr 23, 2016
1 parent 651e9e3 commit 42b8c8a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 66 deletions.
46 changes: 17 additions & 29 deletions mungegithub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,35 @@ endif
# Launch the container on a cluster (with --dry-run).
# The cluster will likely need a service to get access to the web interface (see service.yaml)
# The cluster will need a github oauth token (the secret target makes that easy to create)
deploy: push rc
# Get existing RCs
$(eval rcs := $(shell kubectl --kubeconfig=$(KUBECONFIG) get rc --selector='app=$(APP),readonly=$(READONLY)' --output=template --template='{{range .items}}{{.metadata.name}} {{end}}'))
# Deploy the new RC
kubectl --kubeconfig=$(KUBECONFIG) create -f $(APP)/local.rc.yaml
# Scale the old RCs to 0
$(foreach rc,$(rcs),kubectl --kubeconfig=$(KUBECONFIG) scale --replicas=0 rc $(rc);)
# Current RCs, you might want to clean some up!
kubectl --kubeconfig=$(KUBECONFIG) get rc

# Removes all mungegithub RCs
cleanrcs:
$(eval rcs := $(shell kubectl --kubeconfig=$(KUBECONFIG) get rc --selector='app=$(APP),readonly=$(READONLY)' --output=template --template='{{range .items}}{{.metadata.name}} {{end}}'))
$(foreach rc,$(rcs),kubectl --kubeconfig=$(KUBECONFIG) delete rc $(rc);)
deploy: push deployment
# Deploy the new deployment
kubectl --kubeconfig=$(KUBECONFIG) apply -f $(APP)/local.deployment.yaml --record

# Try to run the binary locally using docker, doesn't need to push or have a running kube cluster.
# Binary is exposed on port 8080
local_dryrun: container
docker run --rm -v $(TOKEN):/token -p 8080:8080 $(CONTAINER)

# updates the rc.yaml with current build information and sets it to --dry-run
rc:
# update the rc.yaml with the current date and git hash
sed -e 's|[[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}-[[:xdigit:]]\+|$(TAG)|g' $(APP)/rc.yaml > $(APP)/local.rc.yaml
# update the rc.yaml with the current repo (if not gcr.io
sed -i -e 's|gcr.io/google_containers|$(REPO)|g' $(APP)/local.rc.yaml
# updates the deployment.yaml with current build information and sets it to --dry-run
deployment:
# update the deployment.yaml with the current date and git hash
sed -e 's|[[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}-[[:xdigit:]]\+|$(TAG)|g' $(APP)/deployment.yaml > $(APP)/local.deployment.yaml
# update the deployment.yaml with the current repo (if not gcr.io
sed -i -e 's|gcr.io/google_containers|$(REPO)|g' $(APP)/local.deployment.yaml
ifeq ($(READONLY),false)
# update the rc.yaml with --dry-run=false
sed -i -e 's!^\([[:space:]]\+\)- --dry-run=true!\1- --dry-run=false!g' $(APP)/local.rc.yaml
# update the deployment.yaml with --dry-run=false
sed -i -e 's!^\([[:space:]]\+\)- --dry-run=true!\1- --dry-run=false!g' $(APP)/local.deployment.yaml
endif
# update the rc.yaml with label "readonly: true"
sed -i -e 's!^\([[:space:]]\+\)app: $(APP)!\1app: $(APP)\n\1readonly: "$(READONLY)"!g' $(APP)/local.rc.yaml
# update the deployment.yaml with label "readonly: true"
sed -i -e 's!^\([[:space:]]\+\)app: $(APP)!\1app: $(APP)\n\1readonly: "$(READONLY)"!g' $(APP)/local.deployment.yaml

# simple transformation of a github oauth secret file to a kubernetes secret
secret:
@echo $(token)
sed -e 's|1234567890123456789012345678901234567890123456789012345=|$(token)|' $(APP)/secret.yaml > $(APP)/local.secret.yaml

clean:
rm -f mungegithub $(APP)/local.rc.yaml $(APP)/local.secret.yaml
rm -f mungegithub $(APP)/local.deployment.yaml $(APP)/local.secret.yaml

help:
@echo "ENVIRONMENT VARS:"
Expand All @@ -93,12 +82,11 @@ help:
@echo " mungegithub: builds the binary"
@echo " container: builds the binary and creates a container with the binary"
@echo " push: pushes the container to the registry"
@echo " deploy: launches the container on a kubernetes cluster, it will scale all other RCs to 0, but not delete them"
@echo " cleanrcs: removes all RCs deployed READONLY=$(READONLY)"
@echo " deploy: launches/updates the app on a kubernetes cluster"
@echo " local_dryrun: tries to launch the container locally with docker"
@echo " rc: updates $(APP)/rc.yaml and places results in $(APP)/local.rc.yaml"
@echo " deployment: updates $(APP)/deployment.yaml and places results in $(APP)/local.deployment.yaml"
@echo " secret: updates $(APP)/secret.yaml with TOKEN an creates $(APP)/local.secret.yaml"
@echo " clean: deletes the binary and local files (does not delete old containers)"


.PHONY: all mungegithub test container push dryrun cleandryrun local_dryrun rc secret clean help
.PHONY: all mungegithub test container push dryrun cleandryrun local_dryrun deployment secret clean help
2 changes: 1 addition & 1 deletion mungegithub/cherrypick/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
local.rc.yaml
local.deployment.yaml
local.secret.yaml
local.service.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
apiVersion: v1
kind: ReplicationController
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: cherrypick
version: "2015-10-26-2a7f8fd"
name: cherrypick-2015-10-26-2a7f8fd
namespace: default
name: cherrypick
spec:
replicas: 1
selector:
app: cherrypick
version: "2015-10-26-2a7f8fd"
template:
metadata:
name: cherrypick
namespace: default
labels:
app: cherrypick
version: "2015-10-26-2a7f8fd"
spec:
containers:
- command:
- name: cherrypick
command:
- /mungegithub
- --token-file=/etc/secret-volume/token
- --pr-mungers=cherrypick-must-have-milestone,cherrypick-clear-after-merge,cherrypick-queue
Expand All @@ -29,9 +20,7 @@ spec:
- --dry-run=true
- --kubernetes-dir=/gitrepo/kubernetes
- --period=3m
image: gcr.io/google_containers/cherrypick:2015-10-26-2a7f8fd
imagePullPolicy: IfNotPresent
name: cherrypick
image: docker.io/eparis/cherrypick:2016-03-14-7fb1dae
ports:
- name: status
containerPort: 8080
Expand All @@ -45,7 +34,6 @@ spec:
name: cherrypick-secret-volume
- mountPath: /gitrepo
name: kubernetes-repo
dnsPolicy: ClusterFirst
volumes:
- name: cherrypick-secret-volume
secret:
Expand Down
2 changes: 1 addition & 1 deletion mungegithub/submit-queue/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
local.rc.yaml
local.deployment.yaml
local.secret.yaml
local.service.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
apiVersion: v1
kind: ReplicationController
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: submit-queue
version: "2015-10-26-2a7f8fd"
name: submit-queue-2015-10-26-2a7f8fd
namespace: default
name: submit-queue
spec:
replicas: 1
selector:
app: submit-queue
version: "2015-10-26-2a7f8fd"
template:
metadata:
name: submit-queue
namespace: default
labels:
app: submit-queue
version: "2015-10-26-2a7f8fd"
spec:
containers:
- command:
- name: submit-queue
command:
- /mungegithub
- --token-file=/etc/secret-volume/token
- --pr-mungers=blunderbuss,lgtm-after-commit,cherrypick-auto-approve,label-unapproved-picks,needs-rebase,ok-to-test,rebuild-request,path-label,size,stale-pending-ci,stale-green-ci,block-path,release-note-label,comment-deleter,submit-queue
- --dry-run=true
image: gcr.io/google_containers/submit-queue:2015-10-26-2a7f8fd
imagePullPolicy: IfNotPresent
name: submit-queue
ports:
- name: status
containerPort: 8080
resources:
requests:
cpu: 100m
limits:
cpu: 100m
volumeMounts:
- mountPath: /etc/secret-volume
name: secret-volume
- mountPath: /gitrepos
name: kubernetes-repo
dnsPolicy: ClusterFirst
volumes:
- name: secret-volume
secret:
Expand Down

0 comments on commit 42b8c8a

Please sign in to comment.