blob: 49351691b9da72d62bab21f97d849f9609d10f43 [file] [log] [blame]
giolekva8aa73e82022-07-09 11:34:39 +04001package installer
giolekva050609f2021-12-29 15:51:40 +04002
giolekva8aa73e82022-07-09 11:34:39 +04003import (
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +04004 "archive/tar"
5 "compress/gzip"
giolekva8aa73e82022-07-09 11:34:39 +04006 "embed"
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +04007 "encoding/json"
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +04008 "fmt"
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +04009 htemplate "html/template"
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +040010 "io"
giolekva8aa73e82022-07-09 11:34:39 +040011 "log"
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +040012 "net/http"
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040013 "strings"
giolekva8aa73e82022-07-09 11:34:39 +040014 "text/template"
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040015
16 "github.com/Masterminds/sprig/v3"
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +040017 "github.com/go-git/go-billy/v5"
18 "sigs.k8s.io/yaml"
giolekva8aa73e82022-07-09 11:34:39 +040019)
giolekva050609f2021-12-29 15:51:40 +040020
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040021//go:embed values-tmpl
22var valuesTmpls embed.FS
23
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040024type Named interface {
25 Nam() string
26}
27
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +040028type appConfig struct {
29 Name string `json:"name"`
30 Version string `json:"version"`
31 Description string `json:"description"`
32 Namespaces []string `json:"namespaces"`
33 Icon htemplate.HTML `json:"icon"`
34}
35
giolekva050609f2021-12-29 15:51:40 +040036type App struct {
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040037 Name string
38 Namespaces []string
39 Templates []*template.Template
40 Schema string
41 Readme *template.Template
giolekva050609f2021-12-29 15:51:40 +040042}
43
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040044func (a App) ConfigSchema() map[string]any {
45 ret := make(map[string]any)
46 if err := json.NewDecoder(strings.NewReader(a.Schema)).Decode(&ret); err != nil {
47 panic(err) // TODO(giolekva): prevalidate
48 }
49 return ret
50}
51
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040052type StoreApp struct {
53 App
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040054 Icon htemplate.HTML
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040055 ShortDescription string
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040056}
57
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040058func (a App) Nam() string {
59 return a.Name
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040060}
61
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040062func (a StoreApp) Nam() string {
63 return a.Name
64}
65
66type AppRepository[A Named] interface {
67 GetAll() ([]A, error)
68 Find(name string) (*A, error)
69}
70
71type InMemoryAppRepository[A Named] struct {
72 apps []A
73}
74
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +040075func NewInMemoryAppRepository[A Named](apps []A) InMemoryAppRepository[A] {
76 return InMemoryAppRepository[A]{
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040077 apps,
78 }
79}
80
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040081func (r InMemoryAppRepository[A]) Find(name string) (*A, error) {
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040082 for _, a := range r.apps {
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040083 if a.Nam() == name {
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040084 return &a, nil
85 }
86 }
87 return nil, fmt.Errorf("Application not found: %s", name)
88}
giolekva8aa73e82022-07-09 11:34:39 +040089
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040090func (r InMemoryAppRepository[A]) GetAll() ([]A, error) {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040091 return r.apps, nil
92}
93
giolekva8aa73e82022-07-09 11:34:39 +040094func CreateAllApps() []App {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040095 tmpls, err := template.New("root").Funcs(template.FuncMap(sprig.FuncMap())).ParseFS(valuesTmpls, "values-tmpl/*")
giolekva8aa73e82022-07-09 11:34:39 +040096 if err != nil {
97 log.Fatal(err)
98 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +040099 ret := []App{
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400100 CreateAppIngressPrivate(valuesTmpls, tmpls),
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400101 CreateCertificateIssuerPublic(valuesTmpls, tmpls),
102 CreateCertificateIssuerPrivate(valuesTmpls, tmpls),
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400103 CreateAppCoreAuth(valuesTmpls, tmpls),
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400104 CreateAppHeadscale(valuesTmpls, tmpls),
Giorgi Lekveishvili39913692023-12-05 08:58:08 +0400105 CreateAppHeadscaleUser(valuesTmpls, tmpls),
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400106 CreateAppTailscaleProxy(valuesTmpls, tmpls),
Giorgi Lekveishvili4fc29432023-07-20 10:03:28 +0400107 CreateMetallbIPAddressPool(valuesTmpls, tmpls),
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400108 CreateEnvManager(valuesTmpls, tmpls),
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400109 CreateWelcome(valuesTmpls, tmpls),
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400110 CreateAppManager(valuesTmpls, tmpls),
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400111 CreateIngressPublic(valuesTmpls, tmpls),
112 CreateCertManager(valuesTmpls, tmpls),
113 CreateCertManagerWebhookGandi(valuesTmpls, tmpls),
114 CreateCertManagerWebhookGandiRole(valuesTmpls, tmpls),
115 CreateCSIDriverSMB(valuesTmpls, tmpls),
116 CreateResourceRendererController(valuesTmpls, tmpls),
117 CreateHeadscaleController(valuesTmpls, tmpls),
Giorgi Lekveishvili106a9352023-12-04 11:20:11 +0400118 CreateDNSZoneManager(valuesTmpls, tmpls),
giolekvaef76a3e2022-01-10 12:22:28 +0400119 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400120 for _, a := range CreateStoreApps() {
121 ret = append(ret, a.App)
122 }
123 return ret
124}
125
126func CreateStoreApps() []StoreApp {
127 tmpls, err := template.New("root").Funcs(template.FuncMap(sprig.FuncMap())).ParseFS(valuesTmpls, "values-tmpl/*")
128 if err != nil {
129 log.Fatal(err)
130 }
131 return []StoreApp{
132 CreateAppVaultwarden(valuesTmpls, tmpls),
133 CreateAppMatrix(valuesTmpls, tmpls),
134 CreateAppPihole(valuesTmpls, tmpls),
135 CreateAppMaddy(valuesTmpls, tmpls),
136 CreateAppQBittorrent(valuesTmpls, tmpls),
137 CreateAppJellyfin(valuesTmpls, tmpls),
Giorgi Lekveishvili672af5d2023-07-12 11:57:51 +0400138 CreateAppSoftServe(valuesTmpls, tmpls),
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400139 CreateAppRpuppy(valuesTmpls, tmpls),
140 }
giolekvaef76a3e2022-01-10 12:22:28 +0400141}
142
Giorgi Lekveishvili4d2784d2023-06-01 14:27:32 +0400143// TODO(gio): service account needs permission to create/update secret
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400144func CreateAppIngressPrivate(fs embed.FS, tmpls *template.Template) App {
145 schema, err := fs.ReadFile("values-tmpl/ingress-private.jsonschema")
146 if err != nil {
147 panic(err)
148 }
giolekva050609f2021-12-29 15:51:40 +0400149 return App{
150 "ingress-private",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400151 []string{"ingress-private"},
giolekva050609f2021-12-29 15:51:40 +0400152 []*template.Template{
giolekva050609f2021-12-29 15:51:40 +0400153 tmpls.Lookup("ingress-private.yaml"),
giolekva050609f2021-12-29 15:51:40 +0400154 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400155 string(schema),
Giorgi Lekveishvili4d2784d2023-06-01 14:27:32 +0400156 tmpls.Lookup("ingress-private.md"),
giolekva050609f2021-12-29 15:51:40 +0400157 }
158}
159
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400160func CreateCertificateIssuerPrivate(fs embed.FS, tmpls *template.Template) App {
161 schema, err := fs.ReadFile("values-tmpl/certificate-issuer-private.jsonschema")
162 if err != nil {
163 panic(err)
164 }
165 return App{
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400166 "certificate-issuer-private",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400167 []string{},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400168 []*template.Template{
169 tmpls.Lookup("certificate-issuer-private.yaml"),
170 },
171 string(schema),
172 tmpls.Lookup("certificate-issuer-private.md"),
173 }
174}
175
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400176func CreateCertificateIssuerPublic(fs embed.FS, tmpls *template.Template) App {
177 schema, err := fs.ReadFile("values-tmpl/certificate-issuer-public.jsonschema")
178 if err != nil {
179 panic(err)
180 }
181 return App{
182 "certificate-issuer-public",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400183 []string{},
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400184 []*template.Template{
185 tmpls.Lookup("certificate-issuer-public.yaml"),
186 },
187 string(schema),
188 tmpls.Lookup("certificate-issuer-public.md"),
189 }
190}
191
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400192func CreateAppCoreAuth(fs embed.FS, tmpls *template.Template) App {
193 schema, err := fs.ReadFile("values-tmpl/core-auth.jsonschema")
194 if err != nil {
195 panic(err)
196 }
giolekva050609f2021-12-29 15:51:40 +0400197 return App{
198 "core-auth",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400199 []string{"core-auth"},
giolekva050609f2021-12-29 15:51:40 +0400200 []*template.Template{
201 tmpls.Lookup("core-auth-storage.yaml"),
202 tmpls.Lookup("core-auth.yaml"),
203 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400204 string(schema),
Giorgi Lekveishvili3ca1f3f2023-05-30 14:33:02 +0400205 tmpls.Lookup("core-auth.md"),
giolekva050609f2021-12-29 15:51:40 +0400206 }
207}
208
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400209func CreateAppVaultwarden(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400210 schema, err := fs.ReadFile("values-tmpl/vaultwarden.jsonschema")
211 if err != nil {
212 panic(err)
213 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400214 return StoreApp{
215 App: App{
216 "vaultwarden",
217 []string{"app-vaultwarden"},
218 []*template.Template{
219 tmpls.Lookup("vaultwarden.yaml"),
220 },
221 string(schema),
222 tmpls.Lookup("vaultwarden.md"),
giolekva050609f2021-12-29 15:51:40 +0400223 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400224 Icon: `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 48 48"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M35.38 25.63V9.37H24v28.87a34.93 34.93 0 0 0 5.41-3.48q6-4.66 6-9.14Zm4.87-19.5v19.5A11.58 11.58 0 0 1 39.4 30a16.22 16.22 0 0 1-2.11 3.81a23.52 23.52 0 0 1-3 3.24a34.87 34.87 0 0 1-3.22 2.62c-1 .69-2 1.35-3.07 2s-1.82 1-2.27 1.26l-1.08.51a1.53 1.53 0 0 1-1.32 0l-1.08-.51c-.45-.22-1.21-.64-2.27-1.26s-2.09-1.27-3.07-2A34.87 34.87 0 0 1 13.7 37a23.52 23.52 0 0 1-3-3.24A16.22 16.22 0 0 1 8.6 30a11.58 11.58 0 0 1-.85-4.32V6.13A1.64 1.64 0 0 1 9.38 4.5h29.24a1.64 1.64 0 0 1 1.63 1.63Z"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400225 ShortDescription: "Open source implementation of Bitwarden password manager. Can be used with official client applications.",
giolekva050609f2021-12-29 15:51:40 +0400226 }
227}
228
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400229func CreateAppMatrix(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400230 schema, err := fs.ReadFile("values-tmpl/matrix.jsonschema")
231 if err != nil {
232 panic(err)
233 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400234 return StoreApp{
235 App{
236 "matrix",
237 []string{"app-matrix"},
238 []*template.Template{
239 tmpls.Lookup("matrix-storage.yaml"),
240 tmpls.Lookup("matrix.yaml"),
241 },
242 string(schema),
243 nil,
giolekva050609f2021-12-29 15:51:40 +0400244 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400245 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 24 24"><path fill="currentColor" d="M.632.55v22.9H2.28V24H0V0h2.28v.55zm7.043 7.26v1.157h.033a3.312 3.312 0 0 1 1.117-1.024c.433-.245.936-.365 1.5-.365c.54 0 1.033.107 1.481.314c.448.208.785.582 1.02 1.108c.254-.374.6-.706 1.034-.992c.434-.287.95-.43 1.546-.43c.453 0 .872.056 1.26.167c.388.11.716.286.993.53c.276.245.489.559.646.951c.152.392.23.863.23 1.417v5.728h-2.349V11.52c0-.286-.01-.559-.032-.812a1.755 1.755 0 0 0-.18-.66a1.106 1.106 0 0 0-.438-.448c-.194-.11-.457-.166-.785-.166c-.332 0-.6.064-.803.189a1.38 1.38 0 0 0-.48.499a1.946 1.946 0 0 0-.231.696a5.56 5.56 0 0 0-.06.785v4.768h-2.35v-4.8c0-.254-.004-.503-.018-.752a2.074 2.074 0 0 0-.143-.688a1.052 1.052 0 0 0-.415-.503c-.194-.125-.476-.19-.854-.19c-.111 0-.259.024-.439.074c-.18.051-.36.143-.53.282a1.637 1.637 0 0 0-.439.595c-.12.259-.18.6-.18 1.02v4.966H5.46V7.81zm15.693 15.64V.55H21.72V0H24v24h-2.28v-.55z"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400246 "An open network for secure, decentralised communication",
giolekva050609f2021-12-29 15:51:40 +0400247 }
248}
249
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400250func CreateAppPihole(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400251 schema, err := fs.ReadFile("values-tmpl/pihole.jsonschema")
252 if err != nil {
253 panic(err)
254 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400255 return StoreApp{
256 App{
257 "pihole",
258 []string{"app-pihole"},
259 []*template.Template{
260 tmpls.Lookup("pihole.yaml"),
261 },
262 string(schema),
263 tmpls.Lookup("pihole.md"),
giolekva050609f2021-12-29 15:51:40 +0400264 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400265 // "simple-icons:pihole",
266 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 24 24"><path fill="currentColor" d="M4.344 0c.238 4.792 3.256 7.056 6.252 7.376c.165-1.692-4.319-5.6-4.319-5.6c-.008-.011.009-.025.019-.014c0 0 4.648 4.01 5.423 5.645c2.762-.15 5.196-1.947 5-4.912c0 0-4.12-.613-5 4.618C11.48 2.753 8.993 0 4.344 0zM12 7.682v.002a3.68 3.68 0 0 0-2.591 1.077L4.94 13.227a3.683 3.683 0 0 0-.86 1.356a3.31 3.31 0 0 0-.237 1.255A3.681 3.681 0 0 0 4.92 18.45l4.464 4.466a3.69 3.69 0 0 0 2.251 1.06l.002.001c.093.01.187.015.28.017l-.1-.008c.06.003.117.009.177.009l-.077-.001L12 24l-.004-.005a3.68 3.68 0 0 0 2.61-1.077l4.469-4.465a3.683 3.683 0 0 0 1.006-1.888l.012-.063a3.682 3.682 0 0 0 .057-.541l.003-.061c0-.017.003-.05.004-.06h-.002a3.683 3.683 0 0 0-1.077-2.607l-4.466-4.468a3.694 3.694 0 0 0-1.564-.927l-.07-.02a3.43 3.43 0 0 0-.946-.133L12 7.682zm3.165 3.357c.023 1.748-1.33 3.078-1.33 4.806c.164 2.227 1.733 3.207 3.266 3.146c-.035.003-.068.007-.104.009c-1.847.135-3.209-1.326-5.002-1.326c-2.23.164-3.21 1.736-3.147 3.27l-.008-.104c-.133-1.847 1.328-3.21 1.328-5.002c-.173-2.32-1.867-3.284-3.46-3.132c.1-.011.203-.021.31-.027c1.847-.133 3.209 1.328 5.002 1.328c2.082-.155 3.074-1.536 3.145-2.968zM4.344 0c.238 4.792 3.256 7.056 6.252 7.376c.165-1.692-4.319-5.6-4.319-5.6c-.008-.011.009-.025.019-.014c0 0 4.648 4.01 5.423 5.645c2.762-.15 5.196-1.947 5-4.912c0 0-4.12-.613-5 4.618C11.48 2.753 8.993 0 4.344 0zM12 7.682v.002a3.68 3.68 0 0 0-2.591 1.077L4.94 13.227a3.683 3.683 0 0 0-.86 1.356a3.31 3.31 0 0 0-.237 1.255A3.681 3.681 0 0 0 4.92 18.45l4.464 4.466a3.69 3.69 0 0 0 2.251 1.06l.002.001c.093.01.187.015.28.017l-.1-.008c.06.003.117.009.177.009l-.077-.001L12 24l-.004-.005a3.68 3.68 0 0 0 2.61-1.077l4.469-4.465a3.683 3.683 0 0 0 1.006-1.888l.012-.063a3.682 3.682 0 0 0 .057-.541l.003-.061c0-.017.003-.05.004-.06h-.002a3.683 3.683 0 0 0-1.077-2.607l-4.466-4.468a3.694 3.694 0 0 0-1.564-.927l-.07-.02a3.43 3.43 0 0 0-.946-.133L12 7.682zm3.165 3.357c.023 1.748-1.33 3.078-1.33 4.806c.164 2.227 1.733 3.207 3.266 3.146c-.035.003-.068.007-.104.009c-1.847.135-3.209-1.326-5.002-1.326c-2.23.164-3.21 1.736-3.147 3.27l-.008-.104c-.133-1.847 1.328-3.21 1.328-5.002c-.173-2.32-1.867-3.284-3.46-3.132c.1-.011.203-.021.31-.027c1.847-.133 3.209 1.328 5.002 1.328c2.082-.155 3.074-1.536 3.145-2.968z"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400267 "Pi-hole is a Linux network-level advertisement and Internet tracker blocking application which acts as a DNS sinkhole and optionally a DHCP server, intended for use on a private network.",
giolekva050609f2021-12-29 15:51:40 +0400268 }
269}
270
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400271func CreateAppMaddy(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400272 schema, err := fs.ReadFile("values-tmpl/maddy.jsonschema")
273 if err != nil {
274 panic(err)
275 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400276 return StoreApp{
277 App{
278 "maddy",
279 []string{"app-maddy"},
280 []*template.Template{
281 tmpls.Lookup("maddy.yaml"),
282 },
283 string(schema),
284 nil,
giolekva050609f2021-12-29 15:51:40 +0400285 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400286 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 48 48"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M9.5 13c13.687 13.574 14.825 13.09 29 0"/><rect width="37" height="31" x="5.5" y="8.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" rx="2"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400287 "SMPT/IMAP server to communicate via email.",
giolekva050609f2021-12-29 15:51:40 +0400288 }
289}
giolekvaef76a3e2022-01-10 12:22:28 +0400290
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400291func CreateAppQBittorrent(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400292 schema, err := fs.ReadFile("values-tmpl/qbittorrent.jsonschema")
293 if err != nil {
294 panic(err)
295 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400296 return StoreApp{
297 App{
298 "qbittorrent",
299 []string{"app-qbittorrent"},
300 []*template.Template{
301 tmpls.Lookup("qbittorrent.yaml"),
302 },
303 string(schema),
304 tmpls.Lookup("qbittorrent.md"),
giolekvaef76a3e2022-01-10 12:22:28 +0400305 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400306 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 48 48"><circle cx="24" cy="24" r="21.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M26.651 22.364a5.034 5.034 0 0 1 5.035-5.035h0a5.034 5.034 0 0 1 5.034 5.035v3.272a5.034 5.034 0 0 1-5.034 5.035h0a5.034 5.034 0 0 1-5.035-5.035m0 5.035V10.533m-5.302 15.103a5.034 5.034 0 0 1-5.035 5.035h0a5.034 5.034 0 0 1-5.034-5.035v-3.272a5.034 5.034 0 0 1 5.034-5.035h0a5.034 5.034 0 0 1 5.035 5.035m0-5.035v20.138"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400307 "qBittorrent is a cross-platform free and open-source BitTorrent client written in native C++. It relies on Boost, Qt 6 toolkit and the libtorrent-rasterbar library, with an optional search engine written in Python.",
giolekvaef76a3e2022-01-10 12:22:28 +0400308 }
309}
310
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400311func CreateAppJellyfin(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400312 schema, err := fs.ReadFile("values-tmpl/jellyfin.jsonschema")
313 if err != nil {
314 panic(err)
315 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400316 return StoreApp{
317 App{
318 "jellyfin",
319 []string{"app-jellyfin"},
320 []*template.Template{
321 tmpls.Lookup("jellyfin.yaml"),
322 },
323 string(schema),
324 nil,
giolekvaef76a3e2022-01-10 12:22:28 +0400325 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400326 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 48 48"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M24 20c-1.62 0-6.85 9.48-6.06 11.08s11.33 1.59 12.12 0S25.63 20 24 20Z"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M24 5.5c-4.89 0-20.66 28.58-18.25 33.4s34.13 4.77 36.51 0S28.9 5.5 24 5.5Zm12 29.21c-1.56 3.13-22.35 3.17-23.93 0S20.8 12.83 24 12.83s13.52 18.76 12 21.88Z"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400327 "Jellyfin is a free and open-source media server and suite of multimedia applications designed to organize, manage, and share digital media files to networked devices.",
giolekvaef76a3e2022-01-10 12:22:28 +0400328 }
329}
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400330
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400331func CreateAppRpuppy(fs embed.FS, tmpls *template.Template) StoreApp {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400332 schema, err := fs.ReadFile("values-tmpl/rpuppy.jsonschema")
333 if err != nil {
334 panic(err)
335 }
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400336 return StoreApp{
337 App{
338 "rpuppy",
339 []string{"app-rpuppy"},
340 []*template.Template{
341 tmpls.Lookup("rpuppy.yaml"),
342 },
343 string(schema),
344 tmpls.Lookup("rpuppy.md"),
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400345 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400346 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 256 256"><path fill="currentColor" d="M100 140a8 8 0 1 1-8-8a8 8 0 0 1 8 8Zm64 8a8 8 0 1 0-8-8a8 8 0 0 0 8 8Zm64.94-9.11a12.12 12.12 0 0 1-5 1.11a11.83 11.83 0 0 1-9.35-4.62l-2.59-3.29V184a36 36 0 0 1-36 36H80a36 36 0 0 1-36-36v-51.91l-2.53 3.27A11.88 11.88 0 0 1 32.1 140a12.08 12.08 0 0 1-5-1.11a11.82 11.82 0 0 1-6.84-13.14l16.42-88a12 12 0 0 1 14.7-9.43h.16L104.58 44h46.84l53.08-15.6h.16a12 12 0 0 1 14.7 9.43l16.42 88a11.81 11.81 0 0 1-6.84 13.06ZM97.25 50.18L49.34 36.1a4.18 4.18 0 0 0-.92-.1a4 4 0 0 0-3.92 3.26l-16.42 88a4 4 0 0 0 7.08 3.22ZM204 121.75L150 52h-44l-54 69.75V184a28 28 0 0 0 28 28h44v-18.34l-14.83-14.83a4 4 0 0 1 5.66-5.66L128 186.34l13.17-13.17a4 4 0 0 1 5.66 5.66L132 193.66V212h44a28 28 0 0 0 28-28Zm23.92 5.48l-16.42-88a4 4 0 0 0-4.84-3.16l-47.91 14.11l62.11 80.28a4 4 0 0 0 7.06-3.23Z"/></svg>`,
Giorgi Lekveishvili27b2b572023-06-30 10:44:45 +0400347 "Delights users with randomly generate puppy pictures. Can be configured to be reachable only from private network or publicly.",
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400348 }
349}
350
Giorgi Lekveishvili672af5d2023-07-12 11:57:51 +0400351func CreateAppSoftServe(fs embed.FS, tmpls *template.Template) StoreApp {
352 schema, err := fs.ReadFile("values-tmpl/soft-serve.jsonschema")
353 if err != nil {
354 panic(err)
355 }
356 return StoreApp{
357 App{
358 "soft-serve",
359 []string{"app-soft-serve"},
360 []*template.Template{
361 tmpls.Lookup("soft-serve.yaml"),
362 },
363 string(schema),
364 tmpls.Lookup("soft-serve.md"),
365 },
366 `<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 48 48"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="4"><path stroke-linejoin="round" d="M15.34 22.5L21 37l3 6l3-6l5.66-14.5"/><path d="M19 32h10"/><path stroke-linejoin="round" d="M24 3c-6 0-8 6-8 6s-6 2-6 7s5 7 5 7s3.5-2 9-2s9 2 9 2s5-2 5-7s-6-7-6-7s-2-6-8-6Z"/></g></svg>`,
367 "A tasty, self-hostable Git server for the command line. 🍦",
368 }
369}
370
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400371func CreateAppHeadscale(fs embed.FS, tmpls *template.Template) App {
372 schema, err := fs.ReadFile("values-tmpl/headscale.jsonschema")
373 if err != nil {
374 panic(err)
375 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400376 return App{
377 "headscale",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400378 []string{"app-headscale"},
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400379 []*template.Template{
380 tmpls.Lookup("headscale.yaml"),
381 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400382 string(schema),
Giorgi Lekveishvili3a907052023-05-30 13:33:32 +0400383 tmpls.Lookup("headscale.md"),
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400384 }
385}
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400386
Giorgi Lekveishvili39913692023-12-05 08:58:08 +0400387func CreateAppHeadscaleUser(fs embed.FS, tmpls *template.Template) App {
388 schema, err := fs.ReadFile("values-tmpl/headscale-user.jsonschema")
389 if err != nil {
390 panic(err)
391 }
392 return App{
393 "headscale-user",
394 []string{"app-headscale"},
395 []*template.Template{
396 tmpls.Lookup("headscale-user.yaml"),
397 },
398 string(schema),
399 tmpls.Lookup("headscale-user.md"),
400 }
401}
402
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400403func CreateAppTailscaleProxy(fs embed.FS, tmpls *template.Template) App {
404 schema, err := fs.ReadFile("values-tmpl/tailscale-proxy.jsonschema")
405 if err != nil {
406 panic(err)
407 }
408 return App{
409 "tailscale-proxy",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400410 []string{"tailscale-proxy"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400411 []*template.Template{
412 tmpls.Lookup("tailscale-proxy.yaml"),
413 },
414 string(schema),
415 tmpls.Lookup("tailscale-proxy.md"),
416 }
417}
418
Giorgi Lekveishvili4fc29432023-07-20 10:03:28 +0400419func CreateMetallbIPAddressPool(fs embed.FS, tmpls *template.Template) App {
420 schema, err := fs.ReadFile("values-tmpl/metallb-ipaddresspool.jsonschema")
421 if err != nil {
422 panic(err)
423 }
424 return App{
425 "metallb-ipaddresspool",
426 []string{"metallb-ipaddresspool"},
427 []*template.Template{
428 tmpls.Lookup("metallb-ipaddresspool.yaml"),
429 },
430 string(schema),
431 tmpls.Lookup("metallb-ipaddresspool.md"),
432 }
433}
434
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400435func CreateEnvManager(fs embed.FS, tmpls *template.Template) App {
436 schema, err := fs.ReadFile("values-tmpl/env-manager.jsonschema")
437 if err != nil {
438 panic(err)
439 }
440 return App{
441 "env-manager",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400442 []string{"env-manager"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400443 []*template.Template{
444 tmpls.Lookup("env-manager.yaml"),
445 },
446 string(schema),
447 tmpls.Lookup("env-manager.md"),
448 }
449}
450
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400451func CreateWelcome(fs embed.FS, tmpls *template.Template) App {
452 schema, err := fs.ReadFile("values-tmpl/welcome.jsonschema")
453 if err != nil {
454 panic(err)
455 }
456 return App{
457 "welcome",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400458 []string{"app-welcome"},
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400459 []*template.Template{
460 tmpls.Lookup("welcome.yaml"),
461 },
462 string(schema),
463 tmpls.Lookup("welcome.md"),
464 }
465}
466
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400467func CreateAppManager(fs embed.FS, tmpls *template.Template) App {
468 schema, err := fs.ReadFile("values-tmpl/appmanager.jsonschema")
469 if err != nil {
470 panic(err)
471 }
472 return App{
473 "app-manager",
474 []string{"core-appmanager"},
475 []*template.Template{
476 tmpls.Lookup("appmanager.yaml"),
477 },
478 string(schema),
479 tmpls.Lookup("appmanager.md"),
480 }
481}
482
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400483func CreateIngressPublic(fs embed.FS, tmpls *template.Template) App {
484 schema, err := fs.ReadFile("values-tmpl/ingress-public.jsonschema")
485 if err != nil {
486 panic(err)
487 }
488 return App{
489 "ingress-public",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400490 []string{"ingress-public"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400491 []*template.Template{
492 tmpls.Lookup("ingress-public.yaml"),
493 },
494 string(schema),
495 tmpls.Lookup("ingress-public.md"),
496 }
497}
498
499func CreateCertManager(fs embed.FS, tmpls *template.Template) App {
500 schema, err := fs.ReadFile("values-tmpl/cert-manager.jsonschema")
501 if err != nil {
502 panic(err)
503 }
504 return App{
505 "cert-manager",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400506 []string{"cert-manager"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400507 []*template.Template{
508 tmpls.Lookup("cert-manager.yaml"),
509 },
510 string(schema),
511 tmpls.Lookup("cert-manager.md"),
512 }
513}
514
515func CreateCertManagerWebhookGandi(fs embed.FS, tmpls *template.Template) App {
516 schema, err := fs.ReadFile("values-tmpl/cert-manager-webhook-gandi.jsonschema")
517 if err != nil {
518 panic(err)
519 }
520 return App{
521 "cert-manager-webhook-gandi",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400522 []string{},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400523 []*template.Template{
524 tmpls.Lookup("cert-manager-webhook-gandi.yaml"),
525 },
526 string(schema),
527 tmpls.Lookup("cert-manager-webhook-gandi.md"),
528 }
529}
530
531func CreateCertManagerWebhookGandiRole(fs embed.FS, tmpls *template.Template) App {
532 schema, err := fs.ReadFile("values-tmpl/cert-manager-webhook-gandi-role.jsonschema")
533 if err != nil {
534 panic(err)
535 }
536 return App{
537 "cert-manager-webhook-gandi-role",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400538 []string{},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400539 []*template.Template{
540 tmpls.Lookup("cert-manager-webhook-gandi-role.yaml"),
541 },
542 string(schema),
543 tmpls.Lookup("cert-manager-webhook-gandi-role.md"),
544 }
545}
546
547func CreateCSIDriverSMB(fs embed.FS, tmpls *template.Template) App {
548 schema, err := fs.ReadFile("values-tmpl/csi-driver-smb.jsonschema")
549 if err != nil {
550 panic(err)
551 }
552 return App{
553 "csi-driver-smb",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400554 []string{"csi-driver-smb"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400555 []*template.Template{
556 tmpls.Lookup("csi-driver-smb.yaml"),
557 },
558 string(schema),
559 tmpls.Lookup("csi-driver-smb.md"),
560 }
561}
562
563func CreateResourceRendererController(fs embed.FS, tmpls *template.Template) App {
564 schema, err := fs.ReadFile("values-tmpl/resource-renderer-controller.jsonschema")
565 if err != nil {
566 panic(err)
567 }
568 return App{
569 "resource-renderer-controller",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400570 []string{"rr-controller"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400571 []*template.Template{
572 tmpls.Lookup("resource-renderer-controller.yaml"),
573 },
574 string(schema),
575 tmpls.Lookup("resource-renderer-controller.md"),
576 }
577}
578
579func CreateHeadscaleController(fs embed.FS, tmpls *template.Template) App {
580 schema, err := fs.ReadFile("values-tmpl/headscale-controller.jsonschema")
581 if err != nil {
582 panic(err)
583 }
584 return App{
585 "headscale-controller",
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400586 []string{"headscale-controller"},
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400587 []*template.Template{
588 tmpls.Lookup("headscale-controller.yaml"),
589 },
590 string(schema),
591 tmpls.Lookup("headscale-controller.md"),
592 }
593}
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400594
Giorgi Lekveishvili106a9352023-12-04 11:20:11 +0400595func CreateDNSZoneManager(fs embed.FS, tmpls *template.Template) App {
596 schema, err := fs.ReadFile("values-tmpl/dns-zone-controller.jsonschema")
597 if err != nil {
598 panic(err)
599 }
600 return App{
601 "dns-zone-manager",
602 []string{"dns-zone-manager"},
603 []*template.Template{
604 tmpls.Lookup("dns-zone-storage.yaml"),
605 tmpls.Lookup("coredns.yaml"),
606 tmpls.Lookup("dns-zone-controller.yaml"),
607 },
608 string(schema),
609 tmpls.Lookup("dns-zone-controller.md"),
610 }
611}
612
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400613type httpAppRepository struct {
614 apps []StoreApp
615}
616
617type appVersion struct {
618 Version string `json:"version"`
619 Urls []string `json:"urls"`
620}
621
622type allAppsResp struct {
623 ApiVersion string `json:"apiVersion"`
624 Entries map[string][]appVersion `json:"entries"`
625}
626
627func FetchAppsFromHTTPRepository(addr string, fs billy.Filesystem) error {
628 resp, err := http.Get(addr)
629 if err != nil {
630 return err
631 }
632 b, err := io.ReadAll(resp.Body)
633 if err != nil {
634 return err
635 }
636 var apps allAppsResp
637 if err := yaml.Unmarshal(b, &apps); err != nil {
638 return err
639 }
640 for name, conf := range apps.Entries {
641 for _, version := range conf {
642 resp, err := http.Get(version.Urls[0])
643 if err != nil {
644 return err
645 }
646 nameVersion := fmt.Sprintf("%s-%s", name, version.Version)
647 if err := fs.MkdirAll(nameVersion, 0700); err != nil {
648 return err
649 }
650 sub, err := fs.Chroot(nameVersion)
651 if err != nil {
652 return err
653 }
654 if err := extractApp(resp.Body, sub); err != nil {
655 return err
656 }
657 }
658 }
659 return nil
660}
661
662func extractApp(archive io.Reader, fs billy.Filesystem) error {
663 uncompressed, err := gzip.NewReader(archive)
664 if err != nil {
665 return err
666 }
667 tarReader := tar.NewReader(uncompressed)
668 for true {
669 header, err := tarReader.Next()
670 if err == io.EOF {
671 break
672 }
673 if err != nil {
674 return err
675 }
676 switch header.Typeflag {
677 case tar.TypeDir:
678 if err := fs.MkdirAll(header.Name, 0755); err != nil {
679 return err
680 }
681 case tar.TypeReg:
682 out, err := fs.Create(header.Name)
683 if err != nil {
684 return err
685 }
686 defer out.Close()
687 if _, err := io.Copy(out, tarReader); err != nil {
688 return err
689 }
690 default:
691 return fmt.Errorf("Uknown type: %s", header.Name)
692 }
693 }
694 return nil
695}
696
697type fsAppRepository struct {
698 InMemoryAppRepository[StoreApp]
699 fs billy.Filesystem
700}
701
702func NewFSAppRepository(fs billy.Filesystem) (AppRepository[StoreApp], error) {
703 all, err := fs.ReadDir(".")
704 if err != nil {
705 return nil, err
706 }
707 apps := make([]StoreApp, 0)
708 for _, e := range all {
709 if !e.IsDir() {
710 continue
711 }
712 appFS, err := fs.Chroot(e.Name())
713 if err != nil {
714 return nil, err
715 }
716 app, err := loadApp(appFS)
717 if err != nil {
718 log.Printf("Ignoring directory %s: %s", e.Name(), err)
719 continue
720 }
721 apps = append(apps, app)
722 }
723 return &fsAppRepository{
724 NewInMemoryAppRepository[StoreApp](apps),
725 fs,
726 }, nil
727}
728
729func loadApp(fs billy.Filesystem) (StoreApp, error) {
730 cfg, err := fs.Open("Chart.yaml")
731 if err != nil {
732 return StoreApp{}, err
733 }
734 defer cfg.Close()
735 b, err := io.ReadAll(cfg)
736 if err != nil {
737 return StoreApp{}, err
738 }
739 var appCfg appConfig
740 if err := yaml.Unmarshal(b, &appCfg); err != nil {
741 return StoreApp{}, err
742 }
743 rb, err := fs.Open("README.md")
744 if err != nil {
745 return StoreApp{}, err
746 }
747 defer rb.Close()
748 readme, err := io.ReadAll(rb)
749 if err != nil {
750 return StoreApp{}, err
751 }
752 readmeTmpl, err := template.New("README.md").Parse(string(readme))
753 if err != nil {
754 return StoreApp{}, err
755 }
756 sb, err := fs.Open("schema.json")
757 if err != nil {
758 return StoreApp{}, err
759 }
760 defer sb.Close()
761 schema, err := io.ReadAll(sb)
762 if err != nil {
763 return StoreApp{}, err
764 }
765 tFiles, err := fs.ReadDir("templates")
766 if err != nil {
767 return StoreApp{}, err
768 }
769 tmpls := make([]*template.Template, 0)
770 for _, t := range tFiles {
771 if !strings.HasSuffix(t.Name(), ".yaml") {
772 continue
773 }
774 inp, err := fs.Open(fs.Join("templates", t.Name()))
775 if err != nil {
776 return StoreApp{}, err
777 }
778 b, err := io.ReadAll(inp)
779 if err != nil {
780 return StoreApp{}, err
781 }
782 tmpl, err := template.New(t.Name()).Parse(string(b))
783 if err != nil {
784 return StoreApp{}, err
785 }
786 tmpls = append(tmpls, tmpl)
787 }
788 return StoreApp{
789 App: App{
790 Name: appCfg.Name,
791 Readme: readmeTmpl,
792 Schema: string(schema),
793 Namespaces: appCfg.Namespaces,
794 Templates: tmpls,
795 },
796 ShortDescription: appCfg.Description,
797 Icon: appCfg.Icon,
798 }, nil
799}