🌳
pt0/deployF/k8sF/initialSetupF/regcacheF/doSync.mts
1import * as _ from 'lodash-es'
28const regcacheIngressAnnotationsH = {
29 'nginx.ingress.kubernetes.io/proxy-body-size': '2g',
30 'nginx.ingress.kubernetes.io/client-body-buffer-size': '100m',
31 'nginx.ingress.kubernetes.io/proxy-read-timeout': '600',
32 'nginx.ingress.kubernetes.io/proxy-send-timeout': '600',
35export const k8sRegCache = async ({
36 pvcReplicaCnt, sizeGb=50,
37 regcacheHost, regcacheLanHost,
38}: {
39 pvcReplicaCnt?: number, sizeGb?: number,
40 regcacheHost?: string, regcacheLanHost?: string,
41}) => {
42 const {cluster_name} = getKlusterCtx()
43 const action = getAction()
44 assertDefined(regcacheHost || regcacheLanHost)
45 const name = regcacheName
47 if (action === 'help') {
48 const actionsH = {
49 ..._.pick(k8sBuiltinActions, ['apply', 'delete', 'info', 'fexec']),
50 ..._.pick(resActionsH(), ['logs', 'pods', 'restart']),
51 uses: {cliDescript: 'show k8s resources using this cache'},
52 gc: {cliDescript: regcacheGc.cliDescript},
53 }
54 const {importMetaUrl} = importMetaUrlCtx.getStore() || {}
55 const rawPath = importMetaUrl ? getImportMetaUrlPath(importMetaUrl as any) : null
56 const epPath = rawPath ? absPathToPtPath(rawPath as Parameters<typeof absPathToPtPath>[0]) : '<sync.mjs>'
57 console.log(buildHelpStr({scriptName: `${ptnodeBin} ${epPath} --steps=${name}`, actionsH: actionsH as any}))
58 betLog({regcacheHost, regcacheLanHost, sizeGb})
59 return
60 }
62 if (action == 'uses') {
63 const resA = await getDockRegKubeResA({dockReg: name})
64 betLog(_.map(resA, inspect3KubeRes))
65 return
66 }
68 if (action == 'gc') {
69 await regcacheGc({regcacheHost: regcacheHost!, regcacheLanHost})
70 return
71 }
73 const zotCfgName = `${name}-zotcfg`
74 const htpasswdSecretName = `${name}-htpasswd`
76 let secretsH = {}
77 if (action == 'apply') {
78 const {username, password} = getCreds({dockreg_host: regcacheHost!})
79 // hardcode 'docker' — local `docker run` for htpasswd generation, same as dockreg
80 const {stdout: htpasswd} = await doExec(`docker run --entrypoint htpasswd httpd:2 -Bbn ${username} ${password}`)
81 secretsH = { htpasswd }
82 }
84 const resources = [
86 getZotCfgMap({zotCfgName}),
87 getZotDeploymentTmpl({zotCfgName, htpasswdSecretName}),
88 secretTemplate({name: htpasswdSecretName, secretsH}),
89 regcredSecTempl({dockreg_host: regcacheHost!, dockLanHost: regcacheLanHost}),
90 kubeSvcTmpl({name, portNo: zotPortNo}),
91 genericIngressTmpl({name, hostname: regcacheHost!, portNo: zotPortNo, ingressAnnotationsH: regcacheIngressAnnotationsH}),
92 ]
93 if (regcacheLanHost) {
94 resources.push(genericIngressTmpl({name: name + '-lan', svcName: name, hostname: regcacheLanHost, portNo: zotPortNo, ingressAnnotationsH: regcacheIngressAnnotationsH}))
95 }
97 await kubeActionPvc({action, name, sizeGb, pvcReplicaCnt})
98 await resourcesAction({resources, action, cluster_name})
100 if (action == 'apply') {
101 await ensureSaPullSecret({secretName: regCredSecName({dockreg_host: regcacheHost!}), action, cluster_name})
102 }