Add a Makefile to run Docker & Kubernetes related commands
authorNsukami Patrick <ndkpatt at gmail dot com>
Thu, 16 May 2019 07:34:37 +0000
changeset 94 16f45bd19cf0
parent 93 e49209d5bc8e
child 95 f92ba8352ee4
Add a Makefile to run Docker & Kubernetes related commands
Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Thu May 16 07:34:37 2019 +0000
@@ -0,0 +1,29 @@
+REGISTRY?=hub.extranet.logilab.fr/logilab/fresh
+VERSION?=$(shell hg log -r . -T "{sub(':.*', '', '{latesttag}')}{sub('^-0-.*', '', '-{latesttagdistance}-hg{shortest(node, 7)}')}\n")
+IMAGE?=$(REGISTRY):$(VERSION)
+PORT?=8080
+DOCKER_ARGS?=$(shell test -e .env && echo --env-file .env) -p $(PORT):8080 -v /var/run/postgresql:/var/run/postgresql -e CW_DB_USER=$(shell id -nu)
+NAMESPACE=intranet
+
+all: build
+
+build:
+	docker build -t $(IMAGE) .
+
+push: build
+	docker push $(IMAGE)
+	docker tag $(IMAGE) $(REGISTRY):latest
+	docker push $(REGISTRY):latest
+
+run: build
+	docker run $(DOCKER_ARGS) --rm -it $(IMAGE)
+
+dev: build
+	docker run --rm -it $(DOCKER_ARGS) -v `pwd`:/src $(IMAGE) bash
+
+deploy: push
+	sed "s@hub.extranet.logilab.fr/logilab/fresh@$(IMAGE)@" deploy/deployment.yaml | kubectl -n $(NAMESPACE) apply -f -
+	@echo "wait at max 3 minutes for deployment to be UP"
+	kubectl -n $(NAMESPACE) wait --for=condition=available --timeout=180s deployment/fresh deployment/$(NAMESPACE)-scheduler
+
+.PHONY: all build push run dev deploy