Compare commits
10 Commits
42b6716850
...
477c639936
| Author | SHA1 | Date | |
|---|---|---|---|
|
477c639936
|
|||
|
dd4a209ea0
|
|||
|
c1cae5c38e
|
|||
|
532c6318d0
|
|||
|
7880f4d25c
|
|||
|
5646d5e812
|
|||
|
dfc621a9ff
|
|||
| c3e5976368 | |||
| 5f016ab217 | |||
| 442dc1c5b1 |
0
.clj-kondo/.cache/v1/lock
Normal file
0
.clj-kondo/.cache/v1/lock
Normal file
0
iac/.gitignore → .gitignore
vendored
0
iac/.gitignore → .gitignore
vendored
1
.lsp/.cache/db.transit.json
Normal file
1
.lsp/.cache/db.transit.json
Normal file
@@ -0,0 +1 @@
|
||||
["^ ","~:classpath",["~#set",[]],"~:project-hash","","~:project-root","/home/jaggar/test/testing/dotfiles","~:settings-hash","99914b932bd37a50b983c5e7c90ae93b","~:kondo-config-hash","3441188a0ae696dd7db6273edada45b0fbb0c1bf9c0b0ae82173bbb4454b7c50","~:dependency-scheme","jar","~:analysis",null,"~:analysis-checksums",["^ "],"~:project-analysis-type","~:project-and-full-dependencies","~:version",12,"~:stubs-generation-namespaces",["^1",[]]]
|
||||
@@ -110,11 +110,19 @@ It may be helpful to redesign the stack mechanism entirely so that resources and
|
||||
]})
|
||||
Where this provides much clearer association and each resource has its options readily available. As such you could declare duplicate keys in the same config. It would make resource associations much more explicit and cleaner written.
|
||||
It would require a decent amount of revision, so no rush on this.
|
||||
|
||||
|
||||
Mentioned above a bit, but eventually rewriting the specs for defaults to match whatever stack configs given is likely the most optimal choice. Basically utilizing the homoiconic nature of Clojure and consuming the first program to generate the final one. Stubbing in the replacements as we walk through it.
|
||||
|
||||
|
||||
Component spec really needs to be moved out of stack_processor as it is just such a large block of data that so better belongs w/ the providers themselves.
|
||||
|
||||
---
|
||||
|
||||
#### Goals
|
||||
The long term goal is for this to be a mostly uninteractive, to completion set up of my cloud services. Since it'll be IaC should I ever choose down the road to migrate certain ones to local nodes I run then that effort should also be more or less feasible.
|
||||
|
||||
More immediately, as we've closed in on a functional end-to-end alpha build and learned several choices we could've made to better design a next build, we'll actually use this to move our services off a single VPS w/ a docker compose and into a cluster fully generated by this with no setup or involvement on our part.
|
||||
|
||||
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
(ns base
|
||||
(:require
|
||||
["@pulumi/pulumi" :as pulumi]
|
||||
["@pulumi/vault" :as vault]
|
||||
["@pulumiverse/harbor" :as harbor]
|
||||
["@pulumi/kubernetes" :as k8s]
|
||||
[utils.general :as general]
|
||||
[utils.providers :refer [provider-apply]]
|
||||
[infra.init :as infra]
|
||||
[service-registries :refer [base-resources-definition initialize-resources-definition shared-resources-definition preparation-resources-definition deployment-resources-definition]]
|
||||
)
|
||||
(:require-macros [utils.general :refer [p->]]))
|
||||
|
||||
|
||||
(defn extended-exports [init]
|
||||
(let [;;exports (base.build-exports init)
|
||||
app-outputs (get init :setup)]
|
||||
#_(assoc exports :nextcloudUrl (.apply app-outputs #(get-in % [:nextcloud :nextcloud-url])))))
|
||||
|
||||
(defn mod-apps [pulumi-cfg resource-configs]
|
||||
"Scans the registry, builds all needed providers, and calls deploy."
|
||||
(provider-apply resource-configs pulumi-cfg))
|
||||
|
||||
|
||||
(defn mod-init [configs]
|
||||
(let [pulumi-cfg (pulumi/Config.)]
|
||||
(mod-apps pulumi-cfg configs)))
|
||||
|
||||
(defn mod-quick-deploy [configs exports]
|
||||
(->
|
||||
(mod-init configs)
|
||||
(exports)
|
||||
(clj->js)))
|
||||
|
||||
(defn quick-deploy-base []
|
||||
(base/mod-quick-deploy
|
||||
base-resources-definition
|
||||
(fn [init]
|
||||
(let [kcfg (p-> init .-cluster "generic:execute" .-kubeconfig)]
|
||||
#js {:kubeconfig kcfg}))))
|
||||
|
||||
(defn quick-deploy-init []
|
||||
(base/mod-quick-deploy
|
||||
initialize-resources-definition
|
||||
(fn [init]
|
||||
(let [vaultToken (p-> init .-openbao "generic:execute" "root-token")
|
||||
vaultAddress (p-> init .-openbao "generic:execute" .-address)]
|
||||
#js {:vaultAddress vaultAddress
|
||||
:vaultToken vaultToken}))))
|
||||
|
||||
(defn quick-deploy-shared []
|
||||
(base/mod-quick-deploy
|
||||
shared-resources-definition
|
||||
(fn [init]
|
||||
(let [secrets (p-> init .-harbor "vault:prepare" "stringData")]
|
||||
{:url (p-> secrets .-host #(str "https://" %))
|
||||
:username (p-> secrets .-username)
|
||||
:password (p-> secrets .-password)}))))
|
||||
|
||||
|
||||
|
||||
(defn quick-deploy-prepare []
|
||||
(base/mod-quick-deploy preparation-resources-definition extended-exports))
|
||||
|
||||
(defn quick-deploy-services []
|
||||
(base/mod-quick-deploy deployment-resources-definition extended-exports))
|
||||
@@ -1,104 +0,0 @@
|
||||
(ns core
|
||||
(:require
|
||||
["@pulumi/pulumi" :as pulumi]
|
||||
["@pulumi/pulumi/automation" :as pulumi-auto]
|
||||
["child_process" :as cp]
|
||||
[promesa.core :as p]
|
||||
[base :as base]
|
||||
[configs :refer [cfg]]))
|
||||
|
||||
|
||||
(def base-stack (clj->js {:projectName "hetzner-k3s"
|
||||
:stackName "base"
|
||||
:workDir "/home/jaggar/dotfiles/iac"
|
||||
:program base/quick-deploy-base}))
|
||||
|
||||
(def init-stack (clj->js {:projectName "hetzner-k3s"
|
||||
:stackName "init"
|
||||
:workDir "/home/jaggar/dotfiles/iac"
|
||||
:program base/quick-deploy-init}))
|
||||
|
||||
(def shared-platform-stack (clj->js {:projectName "hetzner-k3s"
|
||||
:stackName "shared"
|
||||
:workDir "/home/jaggar/dotfiles/iac"
|
||||
:program base/quick-deploy-shared}))
|
||||
|
||||
(def prepare-deployment-stack (clj->js {:projectName "hetzner-k3s"
|
||||
:stackName "prepare"
|
||||
:workDir "/home/jaggar/dotfiles/iac"
|
||||
:program base/quick-deploy-prepare}))
|
||||
|
||||
(def deployment-stack (clj->js {:projectName "hetzner-k3s"
|
||||
:stackName "deployment"
|
||||
:workDir "/home/jaggar/dotfiles/iac"
|
||||
:program base/quick-deploy-services}))
|
||||
|
||||
(defn deploy-stack
|
||||
([stack-definition configs]
|
||||
(deploy-stack stack-definition configs 0))
|
||||
|
||||
([stack-definition configs post-delay]
|
||||
(p/let
|
||||
[stack (.createOrSelectStack pulumi-auto/LocalWorkspace stack-definition)
|
||||
_ (p/doseq [config configs]
|
||||
(.setConfig stack (:name config) (clj->js (dissoc config :name))))
|
||||
_ (.up stack #js {:onOutput println})
|
||||
outputs (.outputs stack)
|
||||
_ (p/delay post-delay)]
|
||||
outputs)))
|
||||
|
||||
(defn run []
|
||||
(p/let [_ (println "Deploying cluster")
|
||||
base-outputs (deploy-stack base-stack [{:name "hetzner-k3s:sshKeyName" :value (-> cfg :sshKeyName) :secret false}
|
||||
{:name "hetzner-k3s:sshPersonalKeyName" :value (-> cfg :sshPersonalKeyName) :secret false}
|
||||
{:name "hcloud:token" :value (-> cfg :hcloudToken) :secret true}
|
||||
{:name "hetzner-k3s:privateKeySsh" :value (-> cfg :privateKeySsh) :secret true}])
|
||||
|
||||
reused-configs [{:name "kubeconfig" :value (-> base-outputs (aget "kubeconfig") (.-value)) :secret true}]
|
||||
|
||||
init-outputs (deploy-stack init-stack reused-configs 1000)
|
||||
port-forward (cp/spawn "kubectl"
|
||||
#js ["port-forward"
|
||||
"svc/openbao"
|
||||
"8200:8200"
|
||||
"-n"
|
||||
"vault"])
|
||||
|
||||
reused-configs (conj reused-configs {:name "vault:token" :value (-> init-outputs (aget "vaultToken") (.-value)) :secret true})
|
||||
reused-configs (conj reused-configs {:name "vault:address" :value (-> init-outputs (aget "vaultAddress") (.-value)) :secret true})
|
||||
|
||||
shared-outputs (deploy-stack shared-platform-stack
|
||||
(conj reused-configs {:name "hetzner-k3s:apiToken" :value (-> cfg :apiToken) :secret true})
|
||||
1000)
|
||||
prepare-outputs (deploy-stack prepare-deployment-stack reused-configs 3000)
|
||||
deployment-outputs (deploy-stack deployment-stack reused-configs 2000)
|
||||
|
||||
_ (.kill port-forward)]
|
||||
"All stacks deployed and cleaned up successfully."))
|
||||
|
||||
|
||||
(defn main! []
|
||||
(-> (run)
|
||||
(p/then #(println %))
|
||||
(p/catch #(println "An error occurred:" %))))
|
||||
|
||||
;; Checks for changes on the core and prevents deleting the app-stack needlessly.
|
||||
;; Important for the Openbao vault as it is deployed here and configured on the app-stack generally
|
||||
;;core-preview-result (.preview core-stack #js {:onOutput println})
|
||||
;;core-change-summary (js->clj (.-changeSummary core-preview-result) :keywordize-keys true)
|
||||
#_core-result #_(when (or (zero? (:delete core-change-summary 0))
|
||||
(pos? (:update core-change-summary 0))
|
||||
(pos? (:create core-change-summary 0)))
|
||||
(.up core-stack #js {:onOutput println}))
|
||||
|
||||
(defn config-core [stack kubeconfig vault-token vault-address]
|
||||
(p/do
|
||||
;;(.setConfig stack "hetzner-k3s:sshKeyName" #js {:value (-> cfg :sshKeyName) :secret false})
|
||||
;;(.setConfig stack "hetzner-k3s:sshPersonalKeyName" #js {:value (-> cfg :sshPersonalKeyName) :secret false})
|
||||
;;(.setConfig stack "hetzner-k3s:privateKeySsh" #js {:value (-> cfg :privateKeySsh) :secret true})
|
||||
(.setConfig stack "kubeconfig" #js {:value kubeconfig :secret true})
|
||||
(.setConfig stack "vault:token" #js {:value vault-token :secret true})
|
||||
;;(.setConfig stack "hcloud:token" #js {:value (-> cfg :hcloudToken) :secret true})
|
||||
(.setConfig stack "vault:address" #js {:value vault-address :secret true})
|
||||
;;(.setConfig stack "hetzner-k3s:apiToken" #js {:value (-> cfg :apiToken) :secret true})
|
||||
))
|
||||
@@ -1,12 +0,0 @@
|
||||
(ns utils.defaults
|
||||
(:require ["path" :as path]
|
||||
[configs :refer [cfg]]
|
||||
[utils.k8s :as k8s]
|
||||
[utils.harbor :as harbor]
|
||||
[utils.docker :as docker]))
|
||||
|
||||
|
||||
(def defaults
|
||||
{:k8s k8s/defaults
|
||||
:harbor harbor/defaults
|
||||
:docker docker/defaults})
|
||||
166
src/main/core.cljs
Normal file
166
src/main/core.cljs
Normal file
@@ -0,0 +1,166 @@
|
||||
(ns core
|
||||
(:require
|
||||
["@pulumi/pulumi" :as pulumi]
|
||||
["@pulumi/pulumi/automation" :as pulumi-auto]
|
||||
["child_process" :as cp]
|
||||
[promesa.core :as p]
|
||||
[base :as base]
|
||||
[configs :refer [cfg]]
|
||||
[utils.execution.general :as general]
|
||||
[utils.execution.providers :refer [execute]]
|
||||
[service-registries :refer [base-resources-definition
|
||||
initialize-resources-definition
|
||||
shared-resources-definition
|
||||
preparation-resources-definition
|
||||
deployment-resources-definition]]
|
||||
)
|
||||
(:require-macros [utils.execution.general :refer [p->]]))
|
||||
|
||||
|
||||
(defn define-stack [project-name stack-name work-dir program]
|
||||
(clj->js {:projectName project-name
|
||||
:stackName stack-name
|
||||
:workDir work-dir
|
||||
:program program}))
|
||||
|
||||
|
||||
(def base-stack
|
||||
(define-stack
|
||||
"hetzner-k3s"
|
||||
"base"
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
base-resources-definition
|
||||
#(#js {:kubeconfig (p-> % .-cluster "generic:execute" .-kubeconfig)}))))
|
||||
|
||||
(def init-stack
|
||||
(define-stack
|
||||
"hetzner-k3s"
|
||||
"init"
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
initialize-resources-definition
|
||||
#(#js {:vaultAddress (p-> % .-openbao "generic:execute" .-address)
|
||||
:vaultToken (p-> % .-openbao "generic:execute" "root-token")}))))
|
||||
|
||||
(def shared-platform-stack
|
||||
(define-stack
|
||||
"hetzner-k3s"
|
||||
"shared"
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
shared-resources-definition
|
||||
#(let [secrets (p-> % .-harbor "vault:prepare" "stringData")]
|
||||
#js {:url (p-> secrets .-host (fn [x] (str "https://" x)))
|
||||
:username (p-> secrets .-username)
|
||||
:password (p-> secrets .-password)}))))
|
||||
|
||||
(def prepare-deployment-stack
|
||||
(define-stack
|
||||
"hetzner-k3s"
|
||||
"prepare"
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute preparation-resources-definition (fn [output] {}))))
|
||||
|
||||
(def deployment-stack
|
||||
(define-stack
|
||||
"hetzner-k3s"
|
||||
"deployment"
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute deployment-resources-definition (fn [output] {}))))
|
||||
|
||||
|
||||
(defn deploy-stack
|
||||
([stack-definition inputs]
|
||||
(deploy-stack stack-definition inputs 0))
|
||||
|
||||
([stack-definition inputs post-delay]
|
||||
(p/let
|
||||
[stack (.createOrSelectStack pulumi-auto/LocalWorkspace stack-definition)
|
||||
_ (p/doseq [input inputs]
|
||||
(.setConfig stack (:name input) (clj->js (dissoc confinputig :name))))
|
||||
_ (.up stack #js {:onOutput println})
|
||||
outputs (.outputs stack)
|
||||
_ (p/delay post-delay)]
|
||||
outputs)))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn run []
|
||||
(p/let [_ (println "Deploying cluster")
|
||||
base-outputs (deploy-stack
|
||||
base-stack
|
||||
[{:name "hetzner-k3s:sshKeyName" :value (-> cfg :sshKeyName) :secret false}
|
||||
{:name "hetzner-k3s:sshPersonalKeyName" :value (-> cfg :sshPersonalKeyName) :secret false}
|
||||
{:name "hcloud:token" :value (-> cfg :hcloudToken) :secret true}
|
||||
{:name "hetzner-k3s:privateKeySsh" :value (-> cfg :privateKeySsh) :secret true}])
|
||||
|
||||
reused-configs [{:name "kubeconfig" :value (-> base-outputs (aget "kubeconfig") (.-value)) :secret true}]
|
||||
|
||||
init-outputs (deploy-stack init-stack reused-configs 1000)
|
||||
port-forward (cp/spawn "kubectl"
|
||||
#js ["port-forward"
|
||||
"svc/openbao"
|
||||
"8200:8200"
|
||||
"-n"
|
||||
"vault"])
|
||||
|
||||
reused-configs (conj reused-configs {:name "vault:token" :value (-> init-outputs (aget "vaultToken") (.-value)) :secret true})
|
||||
reused-configs (conj reused-configs {:name "vault:address" :value (-> init-outputs (aget "vaultAddress") (.-value)) :secret true})
|
||||
|
||||
shared-outputs (deploy-stack shared-platform-stack
|
||||
(conj reused-configs {:name "hetzner-k3s:apiToken" :value (-> cfg :apiToken) :secret true})
|
||||
1000)
|
||||
prepare-outputs (deploy-stack prepare-deployment-stack reused-configs 3000)
|
||||
deployment-outputs (deploy-stack deployment-stack reused-configs 2000)
|
||||
|
||||
_ (.kill port-forward)]
|
||||
"All stacks deployed and cleaned up successfully."))
|
||||
|
||||
|
||||
(defn main! []
|
||||
(-> (run)
|
||||
(p/then #(println %))
|
||||
(p/catch #(println "An error occurred:" %))))
|
||||
|
||||
|
||||
;; Combo later w/ a reader to make a dynamic *stack* config
|
||||
#_(defn test-stack [inputs project-name config-declarations outputs]
|
||||
{:pulumi-stack (clj->js {:projectName project-name
|
||||
:stackName stack-name
|
||||
:workDir work-dir
|
||||
:program #(execute config-declarations outputs)})
|
||||
:inputs inputs
|
||||
:outputs outputs})
|
||||
|
||||
#_(define-stack
|
||||
[{:name "hetzner-k3s:sshKeyName" :value (-> cfg :sshKeyName) :secret false}
|
||||
{:name "hetzner-k3s:sshPersonalKeyName" :value (-> cfg :sshPersonalKeyName) :secret false}
|
||||
{:name "hcloud:token" :value (-> cfg :hcloudToken) :secret true}
|
||||
{:name "hetzner-k3s:privateKeySsh" :value (-> cfg :privateKeySsh) :secret true}]
|
||||
"base"
|
||||
base-resources-definition
|
||||
#(#js {:kubeconfig (p-> % .-cluster "generic:execute" .-kubeconfig)}))
|
||||
|
||||
|
||||
;; Checks for changes on the core and prevents deleting the app-stack needlessly.
|
||||
;; Important for the Openbao vault as it is deployed here and configured on the app-stack generally
|
||||
;;core-preview-result (.preview core-stack #js {:onOutput println})
|
||||
;;core-change-summary (js->clj (.-changeSummary core-preview-result) :keywordize-keys true)
|
||||
#_core-result #_(when (or (zero? (:delete core-change-summary 0))
|
||||
(pos? (:update core-change-summary 0))
|
||||
(pos? (:create core-change-summary 0)))
|
||||
(.up core-stack #js {:onOutput println}))
|
||||
|
||||
(defn config-core [stack kubeconfig vault-token vault-address]
|
||||
(p/do
|
||||
;;(.setConfig stack "hetzner-k3s:sshKeyName" #js {:value (-> cfg :sshKeyName) :secret false})
|
||||
;;(.setConfig stack "hetzner-k3s:sshPersonalKeyName" #js {:value (-> cfg :sshPersonalKeyName) :secret false})
|
||||
;;(.setConfig stack "hetzner-k3s:privateKeySsh" #js {:value (-> cfg :privateKeySsh) :secret true})
|
||||
(.setConfig stack "kubeconfig" #js {:value kubeconfig :secret true})
|
||||
(.setConfig stack "vault:token" #js {:value vault-token :secret true})
|
||||
;;(.setConfig stack "hcloud:token" #js {:value (-> cfg :hcloudToken) :secret true})
|
||||
(.setConfig stack "vault:address" #js {:value vault-address :secret true})
|
||||
;;(.setConfig stack "hetzner-k3s:apiToken" #js {:value (-> cfg :apiToken) :secret true})
|
||||
))
|
||||
@@ -1,11 +1,11 @@
|
||||
(ns k8s.services.gitea.service)
|
||||
|
||||
(def config
|
||||
{:stack [:vault-secrets :deployment :service :ingress]
|
||||
{:stack [:vault:prepare :k8s:deployment :k8s:service :k8s:httproute]
|
||||
:image-port 3000
|
||||
:app-namespace "generic"
|
||||
:app-name "gitea"
|
||||
:deployment-opts {:spec {:template {:spec {:initContainers [
|
||||
:k8s:deployment-opts {:spec {:template {:spec {:initContainers [
|
||||
{:name "init-permissions"
|
||||
:image "busybox:latest"
|
||||
:command ["sh" "-c" "chown -R 1000:1000 /var/lib/gitea && chown -R 1000:1000 /etc/gitea"]
|
||||
@@ -21,4 +21,5 @@
|
||||
:volumes [{:name "gitea-data" :hostPath {:path "/opt/gitea/data" :type "DirectoryOrCreate"}}
|
||||
{:name "gitea-config" :hostPath {:path "/opt/gitea/config" :type "DirectoryOrCreate"}}
|
||||
{:name "timezone" :hostPath {:path "/etc/timezone" :type "File"}}
|
||||
{:name "localtime" :hostPath {:path "/etc/localtime" :type "File"}}]}}}}})
|
||||
{:name "localtime" :hostPath {:path "/etc/localtime" :type "File"}}]}}}}
|
||||
:k8s:httproute-opts {:spec {::hostnames ['host]}}})
|
||||
@@ -8,9 +8,9 @@
|
||||
{:stack [:vault:prepare
|
||||
:harbor:robot-account
|
||||
:docker:image
|
||||
[:k8s :namespace :deployment :service :ingress :httproute]]
|
||||
[:k8s :namespace :deployment :service :httproute]]
|
||||
:app-name "mesite"
|
||||
:namespace "generic"
|
||||
:app-namespace "generic"
|
||||
:docker:image-opts {:context {:location "https://codeberg.org/Gigia/mesite.git"}
|
||||
:imageName '(str registry-base "/" registry-namespace "/" app-name ":latest")
|
||||
:registry {:server '(str registry-base "/" registry-namespace)
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.general
|
||||
(ns utils.execution.general
|
||||
(:require
|
||||
[clojure.walk]))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.general (:require [clojure.walk :as walk]))
|
||||
(ns utils.execution.general (:require [clojure.walk :as walk]))
|
||||
|
||||
|
||||
(defn new-resource [resource-type resource-name final-args provider dependencies]
|
||||
@@ -1,12 +1,12 @@
|
||||
(ns utils.providers
|
||||
(ns utils.execution.providers
|
||||
(:require
|
||||
["@pulumi/pulumi" :as pulumi] ["@pulumi/vault" :as vault] ["@pulumiverse/harbor" :as harbor] ["@pulumi/kubernetes" :as k8s]
|
||||
[clojure.string :as str] [clojure.walk :as walk]
|
||||
[utils.general :refer [resolve-template]]
|
||||
[utils.k8s :as k8s-utils]
|
||||
[utils.harbor :as harbor-utils]
|
||||
[utils.docker :as docker-utils] [utils.vault :as vault-utils]
|
||||
[utils.stack-processor :refer [deploy! component-specs]]))
|
||||
[utils.execution.general :refer [resolve-template]]
|
||||
[utils.providers.k8s :as k8s-utils]
|
||||
[utils.providers.harbor :as harbor-utils]
|
||||
[utils.providers.docker :as docker-utils] [utils.providers.vault :as vault-utils]
|
||||
[utils.execution.stack-processor :refer [deploy! component-specs]]))
|
||||
|
||||
(defn resolve-provider-template [constructor name config]
|
||||
{:constructor constructor
|
||||
@@ -19,19 +19,6 @@
|
||||
:harbor harbor-utils/provider-template
|
||||
:k8s k8s-utils/provider-template})))
|
||||
|
||||
(defn get-provider-outputs-config []
|
||||
{:vault {:stack :init
|
||||
:outputs ["vaultAddress" "vaultToken"]}
|
||||
:harbor {:stack :shared
|
||||
:outputs ["username" "password" "url"]}
|
||||
:k8s {:stack :init
|
||||
:outputs ["kubeconfig"]}})
|
||||
|
||||
|
||||
#_(defn get-stack-refs []
|
||||
{:init (new pulumi/StackReference "init")
|
||||
:shared (new pulumi/StackReference "shared")})
|
||||
|
||||
(defn get-stack-refs [stack-ref-array]
|
||||
(into {}
|
||||
(map (fn [stack-name]
|
||||
@@ -132,4 +119,12 @@
|
||||
{:pulumi-cfg pulumi-cfg
|
||||
:resource-configs (:resource-configs stack-resources-definition)
|
||||
:all-providers instantiated-providers
|
||||
:pre-deploy-deps pre-deploy-results})))))))))
|
||||
:pre-deploy-deps pre-deploy-results})))))))))
|
||||
|
||||
|
||||
(defn execute [configs exports]
|
||||
(->
|
||||
(let [pulumi-cfg (pulumi/Config.)]
|
||||
(provider-apply pulumi-cfg configs))
|
||||
(exports)
|
||||
(clj->js)))
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.safe-fns)
|
||||
(ns utils.execution.safe-fns)
|
||||
|
||||
(defn make-paths [& path-groups]
|
||||
(mapcat (fn [{:keys [paths backend]}]
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.stack-processor
|
||||
(ns utils.execution.stack-processor
|
||||
(:require
|
||||
["@pulumi/kubernetes" :as k8s]
|
||||
["@local/crds/gateway" :as gateway-api]
|
||||
@@ -6,28 +6,20 @@
|
||||
["@pulumi/pulumi" :as pulumi]
|
||||
["@pulumi/vault" :as vault]
|
||||
["@pulumiverse/harbor" :as harbor]
|
||||
[utils.defaults :as default]
|
||||
[utils.vault :as vault-utils]
|
||||
[utils.general :refer [deep-merge new-resource resource-factory deploy-stack-factory iterate-stack]]
|
||||
[utils.providers.defaults :as default]
|
||||
[utils.providers.vault :as vault-utils]
|
||||
[utils.execution.general :refer [deep-merge new-resource resource-factory deploy-stack-factory iterate-stack]]
|
||||
["@pulumi/docker" :as docker]
|
||||
["@pulumi/docker-build" :as docker-build]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.string :as str]
|
||||
["path" :as path]
|
||||
[configs :refer [cfg]]
|
||||
[utils.k8s :as k8s-utils]
|
||||
[utils.harbor :as harbor-utils]
|
||||
[utils.docker :as docker-utils]
|
||||
[utils.safe-fns :refer [safe-fns]])
|
||||
(:require-macros [utils.general :refer [p-> build-registry]]))
|
||||
|
||||
|
||||
#_(def component-specs-defs
|
||||
{:k8s k8s-utils/component-specs-defs
|
||||
:harbor harbor-utils/component-specs-defs
|
||||
:docker docker-utils/component-specs-defs})
|
||||
|
||||
#_(def component-specs (build-registry component-specs-defs))
|
||||
[utils.providers.k8s :as k8s-utils]
|
||||
[utils.providers.harbor :as harbor-utils]
|
||||
[utils.providers.docker :as docker-utils]
|
||||
[utils.execution.safe-fns :refer [safe-fns]])
|
||||
(:require-macros [utils.execution.general :refer [p-> build-registry]]))
|
||||
|
||||
(defn safe-parse-int [s]
|
||||
(let [n (js/parseInt s 10)]
|
||||
@@ -142,6 +134,10 @@
|
||||
:provider-key :k8s
|
||||
:defaults-fn (fn [env] ((get-in default/defaults [:k8s :storage-class]) (:options env)))}
|
||||
|
||||
:k8s:pvc {:constructor (.. k8s -storage -v1 -PVC)
|
||||
:provider-key :k8s
|
||||
:defaults-fn (fn [env] ((get-in default/defaults [:k8s :pvc]) (:options env)))}
|
||||
|
||||
:k8s:gateway {:constructor (.. gateway-api -v1 -Gateway)
|
||||
:provider-key :k8s
|
||||
:defaults-fn (fn [env] ((get-in default/defaults [:k8s :gateway]) (:options env)))}
|
||||
@@ -152,7 +148,7 @@
|
||||
|
||||
:k8s:cluster-issuer {:constructor (.. cert-manager -v1 -ClusterIssuer)
|
||||
:provider-key :k8s
|
||||
:defaults-fn (fn [env] ((get-in default/defaults [:k8s :cluster-issuer]) (:options env)))}
|
||||
:defaults-fn (fn [env] ((get-in default/defaults [:k8s :cluster-issuer]) (:options env)))}
|
||||
|
||||
:k8s:certificates
|
||||
{:constructor (.. cert-manager -v1 -Certificate)
|
||||
@@ -378,25 +374,23 @@
|
||||
stack-items)]
|
||||
(:resources-map result)))
|
||||
|
||||
(defn deploy! [{:keys [pulumi-cfg resource-configs all-providers]}]
|
||||
(let [
|
||||
|
||||
deployment-results
|
||||
(defn deploy! [{:keys [pulumi-cfg resource-configs all-providers]}]
|
||||
(let [deployment-results
|
||||
(into
|
||||
{}
|
||||
(for [config resource-configs]
|
||||
(let [
|
||||
{:keys [stack app-name]} config
|
||||
(let [{:keys [stack app-name]} config
|
||||
_ (when (nil? config)
|
||||
(throw (js/Error. "Resource configs contain a nil value!")))
|
||||
|
||||
common-opts (merge
|
||||
all-providers
|
||||
(select-keys config [:app-name :app-namespace])
|
||||
{:pulumi-cfg pulumi-cfg})
|
||||
]
|
||||
{:pulumi-cfg pulumi-cfg})]
|
||||
|
||||
[app-name (process-stack stack config common-opts)])))
|
||||
]
|
||||
[app-name (process-stack stack config common-opts)])))]
|
||||
(clj->js deployment-results)))
|
||||
|
||||
|
||||
|
||||
12
src/main/utils/providers/defaults.cljs
Normal file
12
src/main/utils/providers/defaults.cljs
Normal file
@@ -0,0 +1,12 @@
|
||||
(ns utils.providers.defaults
|
||||
(:require ["path" :as path]
|
||||
[configs :refer [cfg]]
|
||||
[utils.providers.k8s :as k8s]
|
||||
[utils.providers.harbor :as harbor]
|
||||
[utils.providers.docker :as docker]))
|
||||
|
||||
|
||||
(def defaults
|
||||
{:k8s k8s/defaults
|
||||
:harbor harbor/defaults
|
||||
:docker docker/defaults})
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns utils.docker
|
||||
(ns utils.providers.docker
|
||||
(:require
|
||||
[utils.general :refer [generic-transform deep-merge new-resource component-factory resource-factory deploy-stack-factory iterate-stack]]
|
||||
[utils.execution.general :refer [generic-transform deep-merge new-resource component-factory resource-factory deploy-stack-factory iterate-stack]]
|
||||
["@pulumi/docker-build" :as docker]
|
||||
["path" :as path]
|
||||
[configs :refer [cfg]]))
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.harbor
|
||||
(ns utils.providers.harbor
|
||||
(:require
|
||||
["@pulumiverse/harbor" :as harbor]))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.k8s (:require ["@pulumi/kubernetes" :as k8s]))
|
||||
(ns utils.providers.k8s (:require ["@pulumi/kubernetes" :as k8s]))
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns utils.vault
|
||||
(ns utils.providers.vault
|
||||
(:require
|
||||
["@pulumi/kubernetes" :as k8s]
|
||||
["@pulumi/pulumi" :as pulumi]
|
||||
@@ -10,9 +10,10 @@
|
||||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user