updated blocks

This commit is contained in:
Oly 2019-11-01 13:04:44 +00:00
parent 4cbf3d91f6
commit aa4c393659
2 changed files with 70 additions and 28 deletions

View File

@ -38,6 +38,22 @@
(lk/expose-cluster-ip :mosquitto-master (lk/expose-cluster-ip :mosquitto-master
(lk/port :mosquitto :mosquitto 1883 1883))))))) (lk/port :mosquitto :mosquitto 1883 1883)))))))
(defn test [kube-injector]
(-> kube-injector
(lk/rule :test-rule []
(fn []
(-> (lk/pod
:test-pod
{:app :test})
(lk/add-container :busybox "busybox"
(-> {}
(lkh/add-to-spec :resources resources-mini)
(lkh/add-to-spec :command ["sleep 3600"])
(lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}])))
(lk/deployment 1))))))
(defn postgres (defn postgres
([kube-injector] ([kube-injector]
(postgres kube-injector {})) (postgres kube-injector {}))
@ -84,7 +100,7 @@
app-nginx-container-name (keyword (str app-name "-nginx-container")) app-nginx-container-name (keyword (str app-name "-nginx-container"))
app-nginx-pod-name (str app-name "-pod") app-nginx-pod-name (str app-name "-pod")
app-annotations (get settings :annotations {}) app-annotations (get settings :annotations {})
app-dependencies (get settings :dependencies []) app-dependencies [] ;(get settings :dependencies [])
app-containers 1 app-containers 1
app-labels (get settings :labels {:app app-name}) app-labels (get settings :labels {:app app-name})
app-image (get settings :image "python:3") app-image (get settings :image "python:3")
@ -93,15 +109,20 @@
app-nginx-service-name "nginx-service" app-nginx-service-name "nginx-service"
app-serve-static (get settings :serve-static true)] app-serve-static (get settings :serve-static true)]
(-> kube-injector (-> kube-injector
(lk/rule (keyword (str app-name "-rule")) app-dependencies (lk/rule (keyword (str app-name "-rule")) app-dependencies
(fn [] (fn []
(as-> (lk/pod (println app-pod-name)
app-pod-name
app-labels (as->
{:imagePullSecrets [{:name "docker-registry"}]}) (lk/pod
pod app-pod-name
; Add containers to the pod, one for frontend assets and one for backend app-labels
{:imagePullSecrets [{:name "docker-registry"}]})
pod
; Add containers to the pod, one for frontend assets and one for backend
(lk/add-annotation pod :linkerd.io/inject "enabled") (lk/add-annotation pod :linkerd.io/inject "enabled")
(lk/add-container (lk/add-container
pod pod
@ -123,7 +144,7 @@
#_(lkh/add-readiness-probe-cmd ["wget" "127.0.0.1:5000"]) #_(lkh/add-readiness-probe-cmd ["wget" "127.0.0.1:5000"])
#_(lkh/add-liveness-probe-cmd ["wget" "127.0.0.1:5000"])}) #_(lkh/add-liveness-probe-cmd ["wget" "127.0.0.1:5000"])})
(lk/add-init-container #_(lk/add-init-container
pod pod
(keyword (str app-name "-init-migrations")) (keyword (str app-name "-init-migrations"))
app-image app-image
@ -131,13 +152,13 @@
(lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}]) (lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}])
(lkh/add-to-spec :command ["./manage.py" "migrate"]))) (lkh/add-to-spec :command ["./manage.py" "migrate"])))
(lk/add-init-container #_(lk/add-init-container
pod pod
(keyword (str app-name "-init-static-files")) (keyword (str app-name "-init-static-files"))
app-image app-image
(-> {} (-> {}
(lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}]) (lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}])
(lkh/add-to-spec :command ["./manage.py" "collectstatic"]))) (lkh/add-to-spec :command ["./manage.py" "collectstatic" "--no-input"])))
(if (nil? app-serve-static) (if (nil? app-serve-static)
pod pod
@ -154,15 +175,7 @@
(lk/add-volume :static-files (lk/add-volume :static-files
{:emptyDir {}} {:emptyDir {}}
{app-nginx-container-name "/usr/share/nginx/html/static/" {app-nginx-container-name "/usr/share/nginx/html/static/"
app-gunicorn-container-name "/app/staticfiles"}) app-gunicorn-container-name "/app/staticfiles"})))
;{:mountPath "/usr/share/nginx/html/static/"
; :readOnly true}
#_(lk/expose-cluster-ip app-nginx-service-name
(lk/port app-nginx-container-name :nginx-port 80 80))))
; order does matter here, deployment after initcontainers ; order does matter here, deployment after initcontainers
@ -170,9 +183,6 @@
;(lku/wait-for-service-port redis :redis) ;(lku/wait-for-service-port redis :redis)
#_(lk/add-volume :static-files {:configMap {:name :static-files-config-map}}
{app-nginx-container-name "/app/staticfiles"}
app-gunicorn-container-name "/app/staticfiles")
; wrap in a deployment ; wrap in a deployment
(lk/deployment pod 1) (lk/deployment pod 1)
(if (nil? app-serve-static) (if (nil? app-serve-static)
@ -186,8 +196,7 @@
pod pod
app-service-name app-service-name
(lk/port app-gunicorn-container-name :gunicorn-port 5000 5000)) (lk/port app-gunicorn-container-name :gunicorn-port 5000 5000))
#_(lk/expose-cluster-ip app-name )))
(lk/port app-nginx-container-name :nginx-port 80 80)))))
; inject the ingress required to serve to gunicorn app ; inject the ingress required to serve to gunicorn app
(lk/rule (keyword (str app-name "-ingress-rule")) [] (lk/rule (keyword (str app-name "-ingress-rule")) []
@ -213,6 +222,40 @@
; (lk/add-annotation :certmanager.k8s.io/cluster-issuer "letsencrypt-production") ; (lk/add-annotation :certmanager.k8s.io/cluster-issuer "letsencrypt-production")
(lk/add-annotation :kubernetes.io/ingress.class "nginx"))))))))) (lk/add-annotation :kubernetes.io/ingress.class "nginx")))))))))
(defn django-huey
([kube-injector]
(gunicorn kube-injector {}))
([kube-injector settings]
(let [app-name (get settings :app-name "huey")
app-pod-name (keyword (str app-name "-pod"))
app-rule-name (keyword (str app-name "-rule"))
app-container-name (keyword (str app-name "-container"))
app-dependencies [] ;(get settings :dependencies [])
app-containers 1
app-labels (get settings :labels {:app app-name})
app-image (get settings :image "python:3")
app-resources (get settings :resources resources-small)]
(-> kube-injector
(lk/rule app-rule-name []
(fn []
(-> (lk/pod app-pod-name
{:app :hackspace
:env :stage
:role :master
:tier :queue}
{:imagePullSecrets [{:name "docker-registry"}]})
(lk/add-container
app-container-name
app-image
(-> {}
(lkh/add-to-spec :resources resources-small)
(lkh/add-to-spec :command ["/app/manage.py" "run_huey"])
(lkh/add-to-spec :envFrom [{:secretRef {:name "environment"}}])))
(lk/deployment 2))))))))
;; (into [] (flatten ["c" [:b 2]] )) ;; (into [] (flatten ["c" [:b 2]] ))

View File

@ -498,6 +498,7 @@
(defn build [{:keys [config namespace blocks] :as service}] (defn build [{:keys [config namespace blocks] :as service}]
(println "Deploying" config namespace) (println "Deploying" config namespace)
(println (str namespace "-store.yaml"))
(if (.exists (io/file (str namespace "-config.edn"))) (if (.exists (io/file (str namespace "-config.edn")))
(do (reset! conf (clojure.edn/read-string (slurp (str namespace "-config.edn")))) (do (reset! conf (clojure.edn/read-string (slurp (str namespace "-config.edn"))))
(create-namespace-if-not-exists service) (create-namespace-if-not-exists service)
@ -505,10 +506,8 @@
(-> injector (-> injector
(make-environment-secrets :environment (:vars @conf)) (make-environment-secrets :environment (:vars @conf))
;(make-registry-secrets :docker-registry {:.dockerconfigjson (:registry @conf)}) ;(make-registry-secrets :docker-registry {:.dockerconfigjson (:registry @conf)})
;; make-ingress-hackspace ;(apply-blocks [:postgres] @conf)
;; database ;(apply-blocks [:django-gunicorn] @conf)
;; redis
;; hackspace
(apply-blocks blocks @conf) (apply-blocks blocks @conf)
lk/standard-descs lk/standard-descs
(lk/get-deployable deployment-config) (lk/get-deployable deployment-config)