Compare commits
8 Commits
74ddb62096
...
27ed391745
| Author | SHA1 | Date | |
|---|---|---|---|
|
27ed391745
|
|||
|
c8ffa3355f
|
|||
|
53d06281a5
|
|||
|
cd4718ce33
|
|||
|
ac86a96af1
|
|||
|
7b8857ca9b
|
|||
|
e98ea0ef7d
|
|||
|
2b5f5544df
|
6
.gitignore
vendored
6
.gitignore
vendored
@@ -10,4 +10,8 @@
|
||||
.env
|
||||
init-secrets.json
|
||||
.crd2pulumi-checksum
|
||||
/.clj-kondo/
|
||||
/.clj-kondo/
|
||||
kubeconfig.yaml
|
||||
/.cpcache/
|
||||
package-lock.json
|
||||
db.transit.json
|
||||
9
deps.edn
Normal file
9
deps.edn
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
{:paths ["src/main"]
|
||||
;;:deps {gigiaj/pulumicljs {:local/root "../pulumi-clojurescript"}}
|
||||
:deps {gigiaj/pulumicljs
|
||||
{:git/url "https://github.com/GigiaJ/pulumi-clojurescript.git"
|
||||
:git/sha "c14d7aae05eabfc5517a8d8608e223b1c6a0fdb3"
|
||||
}
|
||||
funcool/promesa {:mvn/version "11.0.678"}
|
||||
}}
|
||||
@@ -30,8 +30,8 @@
|
||||
"@pulumi/pulumi": "^3.113.0",
|
||||
"@pulumi/vault": "^7.2.1",
|
||||
"@pulumiverse/harbor": "^3.10.21",
|
||||
"@local/crds": "file:./generated/crds",
|
||||
"bcryptjs": "^3.0.2",
|
||||
"pulumi-extra-crds": "1.0.13",
|
||||
"uuid": "^13.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const crypto = require('crypto');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const PROJECT_ROOT = process.cwd();
|
||||
|
||||
const OUTPUT_DIR = path.join(PROJECT_ROOT, 'generated/crds');
|
||||
const TEMP_DIR = path.join(PROJECT_ROOT, 'temp_crds');
|
||||
const CHECKSUM_FILE = path.join(PROJECT_ROOT, '.crd2pulumi-checksum');
|
||||
|
||||
const GW_VERSION = 'v1.1.0';
|
||||
const GW_URL = `https://github.com/kubernetes-sigs/gateway-api/releases/download/${GW_VERSION}/experimental-install.yaml`;
|
||||
const GW_FILE = 'gateway-api.yaml';
|
||||
|
||||
const CM_VERSION = 'v1.15.0';
|
||||
const CM_URL = `https://github.com/cert-manager/cert-manager/releases/download/${CM_VERSION}/cert-manager.crds.yaml`;
|
||||
const CM_FILE = 'cert-manager.yaml';
|
||||
|
||||
const downloadFile = (url, filename) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const destPath = path.join(TEMP_DIR, filename);
|
||||
const file = fs.createWriteStream(destPath);
|
||||
|
||||
const request = (uri) => {
|
||||
https.get(uri, (response) => {
|
||||
if (response.statusCode === 301 || response.statusCode === 302) {
|
||||
return request(response.headers.location);
|
||||
}
|
||||
if (response.statusCode !== 200) {
|
||||
reject(new Error(`Failed to download ${uri}: ${response.statusCode}`));
|
||||
return;
|
||||
}
|
||||
console.log(`Downloading ${filename}...`);
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
resolve(destPath);
|
||||
});
|
||||
}).on('error', (err) => {
|
||||
fs.unlink(destPath, () => {});
|
||||
reject(err);
|
||||
});
|
||||
};
|
||||
request(url);
|
||||
});
|
||||
};
|
||||
|
||||
const computeHash = (filePaths) => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
filePaths.sort().forEach(fp => hash.update(fs.readFileSync(fp)));
|
||||
return hash.digest('hex');
|
||||
};
|
||||
|
||||
async function main() {
|
||||
if (fs.existsSync(TEMP_DIR)) fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(TEMP_DIR);
|
||||
|
||||
try {
|
||||
const gwPath = await downloadFile(GW_URL, GW_FILE);
|
||||
const cmPath = await downloadFile(CM_URL, CM_FILE);
|
||||
const allFiles = [gwPath, cmPath];
|
||||
const newHash = computeHash(allFiles);
|
||||
|
||||
let oldHash = null;
|
||||
if (fs.existsSync(CHECKSUM_FILE)) {
|
||||
oldHash = fs.readFileSync(CHECKSUM_FILE, 'utf8').trim();
|
||||
}
|
||||
|
||||
if (oldHash === newHash && fs.existsSync(OUTPUT_DIR)) {
|
||||
console.log('CRDs unchanged. Skipping.');
|
||||
} else {
|
||||
console.log('Regenerating CRDs...');
|
||||
if (fs.existsSync(OUTPUT_DIR)) fs.rmSync(OUTPUT_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||
execSync(`crd2pulumi --nodejsPath "${OUTPUT_DIR}" --force "${gwPath}" "${cmPath}"`, { stdio: 'inherit' });
|
||||
|
||||
const pkgPath = path.join(OUTPUT_DIR, 'package.json');
|
||||
if (fs.existsSync(pkgPath)) {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
||||
if (pkg.scripts) delete pkg.scripts;
|
||||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
||||
}
|
||||
|
||||
const tsconfig = {
|
||||
compilerOptions: {
|
||||
target: "es2020",
|
||||
module: "commonjs",
|
||||
moduleResolution: "node",
|
||||
declaration: true,
|
||||
skipLibCheck: true,
|
||||
},
|
||||
include: ["**/*.ts"],
|
||||
exclude: ["node_modules"]
|
||||
};
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'tsconfig.json'), JSON.stringify(tsconfig, null, 2));
|
||||
|
||||
try {
|
||||
execSync('npx tsc', { cwd: OUTPUT_DIR, stdio: 'inherit' });
|
||||
} catch (e) { console.warn("TSC warnings ignored."); }
|
||||
|
||||
fs.writeFileSync(CHECKSUM_FILE, newHash);
|
||||
console.log(`Success!`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
if (fs.existsSync(TEMP_DIR)) fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,10 +1,9 @@
|
||||
{:source-paths ["./src/main"
|
||||
"./generated/crds"]
|
||||
:dependencies [[funcool/promesa "11.0.678"]]
|
||||
{:dependencies []
|
||||
:deps {:aliases []}
|
||||
:builds
|
||||
{:app {;;:target :node-library
|
||||
;; :modules {:main {:entries [base]}}
|
||||
;; :exports {:deployCore base/deploy-core}
|
||||
;; :modules {:main {:entries [base]}}
|
||||
;; :exports {:deployCore base/deploy-core}
|
||||
:target :node-script
|
||||
:output-to "./out/index.js"
|
||||
:compiler-options {:optimizations :simple}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
(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]]
|
||||
[pulumicljs.execution.general :as general]
|
||||
[pulumicljs.execution.providers :refer [execute]]
|
||||
[stack-resource-definitions :refer [base-resources-definition
|
||||
initialize-resources-definition
|
||||
shared-resources-definition
|
||||
preparation-resources-definition
|
||||
deployment-resources-definition]]
|
||||
initialize-resources-definition
|
||||
shared-resources-definition
|
||||
preparation-resources-definition
|
||||
deployment-resources-definition]]
|
||||
)
|
||||
(:require-macros [utils.execution.general :refer [p->]]))
|
||||
(:require-macros [pulumicljs.execution.general :refer [p->]]))
|
||||
|
||||
|
||||
(defn define-stack [project-name stack-name work-dir program]
|
||||
@@ -31,7 +29,8 @@
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
base-resources-definition
|
||||
#(#js {:kubeconfig (p-> % .-cluster "generic:execute" .-kubeconfig)}))))
|
||||
(fn [output] (let [_ (js/console.log output)]
|
||||
#js {:kubeconfig (p-> output .-cluster "generic:execute" .-kubeconfig)})))))
|
||||
|
||||
(def init-stack
|
||||
(define-stack
|
||||
@@ -40,8 +39,8 @@
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
initialize-resources-definition
|
||||
#(#js {:vaultAddress (p-> % .-openbao "generic:execute" .-address)
|
||||
:vaultToken (p-> % .-openbao "generic:execute" "root-token")}))))
|
||||
(fn [output] #js {:vaultAddress (p-> output .-openbao "generic:execute" .-address)
|
||||
:vaultToken (p-> output .-openbao "generic:execute" "root-token")}))))
|
||||
|
||||
(def shared-platform-stack
|
||||
(define-stack
|
||||
@@ -50,10 +49,10 @@
|
||||
"/home/jaggar/dotfiles/iac"
|
||||
(execute
|
||||
shared-resources-definition
|
||||
#(let [secrets (p-> % .-harbor "vault:prepare" "stringData")]
|
||||
(fn [output] (let [secrets (p-> output .-harbor "vault:prepare" "stringData")]
|
||||
#js {:url (p-> secrets .-host (fn [x] (str "https://" x)))
|
||||
:username (p-> secrets .-username)
|
||||
:password (p-> secrets .-password)}))))
|
||||
:password (p-> secrets .-password)})))))
|
||||
|
||||
(def prepare-deployment-stack
|
||||
(define-stack
|
||||
@@ -78,7 +77,7 @@
|
||||
(p/let
|
||||
[stack (.createOrSelectStack pulumi-auto/LocalWorkspace stack-definition)
|
||||
_ (p/doseq [input inputs]
|
||||
(.setConfig stack (:name input) (clj->js (dissoc confinputig :name))))
|
||||
(.setConfig stack (:name input) (clj->js (dissoc input :name))))
|
||||
_ (.up stack #js {:onOutput println})
|
||||
outputs (.outputs stack)
|
||||
_ (p/delay post-delay)]
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
[infra.openbao :as openbao]
|
||||
[k8s.add-ons.csi-driver.hetzner :as hetzner-csi]
|
||||
[infra.dns :as dns]
|
||||
[infra.buildkit :as buildkit]
|
||||
[k8s.preparers.harbor :as harbor-prepare]
|
||||
|
||||
[k8s.add-ons.ingress-controller.caddy :as caddy]
|
||||
|
||||
Reference in New Issue
Block a user