blob: 7d60aa3d818f2494988afae184f6ffd09b68f705 [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 (
4 "embed"
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +04005 "fmt"
giolekva8aa73e82022-07-09 11:34:39 +04006 "log"
7 "text/template"
8)
giolekva050609f2021-12-29 15:51:40 +04009
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040010//go:embed values-tmpl
11var valuesTmpls embed.FS
12
giolekva050609f2021-12-29 15:51:40 +040013type App struct {
14 Name string
15 Templates []*template.Template
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040016 Schema string
17 Readme *template.Template
giolekva050609f2021-12-29 15:51:40 +040018}
19
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040020type AppRepository interface {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040021 GetAll() ([]App, error)
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +040022 Find(name string) (*App, error)
23}
24
25type InMemoryAppRepository struct {
26 apps []App
27}
28
29func NewInMemoryAppRepository(apps []App) AppRepository {
30 return &InMemoryAppRepository{
31 apps,
32 }
33}
34
35func (r InMemoryAppRepository) Find(name string) (*App, error) {
36 for _, a := range r.apps {
37 if a.Name == name {
38 return &a, nil
39 }
40 }
41 return nil, fmt.Errorf("Application not found: %s", name)
42}
giolekva8aa73e82022-07-09 11:34:39 +040043
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040044func (r InMemoryAppRepository) GetAll() ([]App, error) {
45 return r.apps, nil
46}
47
giolekva8aa73e82022-07-09 11:34:39 +040048func CreateAllApps() []App {
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040049 tmpls, err := template.ParseFS(valuesTmpls, "values-tmpl/*")
giolekva8aa73e82022-07-09 11:34:39 +040050 if err != nil {
51 log.Fatal(err)
52 }
giolekvaef76a3e2022-01-10 12:22:28 +040053 return []App{
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040054 // CreateAppIngressPublic(tmpls),
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040055 CreateAppIngressPrivate(valuesTmpls, tmpls),
56 CreateAppCoreAuth(valuesTmpls, tmpls),
57 CreateAppVaultwarden(valuesTmpls, tmpls),
58 CreateAppMatrix(valuesTmpls, tmpls),
59 CreateAppPihole(valuesTmpls, tmpls),
60 CreateAppMaddy(valuesTmpls, tmpls),
61 CreateAppQBittorrent(valuesTmpls, tmpls),
62 CreateAppJellyfin(valuesTmpls, tmpls),
63 CreateAppRpuppy(valuesTmpls, tmpls),
64 CreateAppHeadscale(valuesTmpls, tmpls),
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040065 }
66}
67
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040068func CreateAppIngressPublic(fs embed.FS, tmpls *template.Template) App {
69 schema, err := fs.ReadFile("values-tmpl/ingress-public.jsonschema")
70 if err != nil {
71 panic(err)
72 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040073 return App{
74 "ingress-public",
75 []*template.Template{
76 tmpls.Lookup("ingress-public.yaml"),
77 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040078 string(schema),
79 nil,
giolekvaef76a3e2022-01-10 12:22:28 +040080 }
81}
82
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040083func CreateAppIngressPrivate(fs embed.FS, tmpls *template.Template) App {
84 schema, err := fs.ReadFile("values-tmpl/ingress-private.jsonschema")
85 if err != nil {
86 panic(err)
87 }
giolekva050609f2021-12-29 15:51:40 +040088 return App{
89 "ingress-private",
90 []*template.Template{
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040091 // tmpls.Lookup("vpn-mesh-config.yaml"),
giolekva050609f2021-12-29 15:51:40 +040092 tmpls.Lookup("ingress-private.yaml"),
93 tmpls.Lookup("certificate-issuer.yaml"),
94 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +040095 string(schema),
96 nil,
giolekva050609f2021-12-29 15:51:40 +040097 }
98}
99
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400100func CreateAppCoreAuth(fs embed.FS, tmpls *template.Template) App {
101 schema, err := fs.ReadFile("values-tmpl/core-auth.jsonschema")
102 if err != nil {
103 panic(err)
104 }
giolekva050609f2021-12-29 15:51:40 +0400105 return App{
106 "core-auth",
107 []*template.Template{
108 tmpls.Lookup("core-auth-storage.yaml"),
109 tmpls.Lookup("core-auth.yaml"),
110 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400111 string(schema),
112 nil,
giolekva050609f2021-12-29 15:51:40 +0400113 }
114}
115
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400116func CreateAppVaultwarden(fs embed.FS, tmpls *template.Template) App {
117 schema, err := fs.ReadFile("values-tmpl/vaultwarden.jsonschema")
118 if err != nil {
119 panic(err)
120 }
giolekva050609f2021-12-29 15:51:40 +0400121 return App{
122 "vaultwarden",
123 []*template.Template{
124 tmpls.Lookup("vaultwarden.yaml"),
125 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400126 string(schema),
127 nil,
giolekva050609f2021-12-29 15:51:40 +0400128 }
129}
130
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400131func CreateAppMatrix(fs embed.FS, tmpls *template.Template) App {
132 schema, err := fs.ReadFile("values-tmpl/matrix.jsonschema")
133 if err != nil {
134 panic(err)
135 }
giolekva050609f2021-12-29 15:51:40 +0400136 return App{
137 "matrix",
138 []*template.Template{
139 tmpls.Lookup("matrix-storage.yaml"),
140 tmpls.Lookup("matrix.yaml"),
141 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400142 string(schema),
143 nil,
giolekva050609f2021-12-29 15:51:40 +0400144 }
145}
146
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400147func CreateAppPihole(fs embed.FS, tmpls *template.Template) App {
148 schema, err := fs.ReadFile("values-tmpl/pihole.jsonschema")
149 if err != nil {
150 panic(err)
151 }
giolekva050609f2021-12-29 15:51:40 +0400152 return App{
153 "pihole",
154 []*template.Template{
155 tmpls.Lookup("pihole.yaml"),
156 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400157 string(schema),
158 nil,
giolekva050609f2021-12-29 15:51:40 +0400159 }
160}
161
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400162func CreateAppMaddy(fs embed.FS, tmpls *template.Template) App {
163 schema, err := fs.ReadFile("values-tmpl/maddy.jsonschema")
164 if err != nil {
165 panic(err)
166 }
giolekva050609f2021-12-29 15:51:40 +0400167 return App{
168 "maddy",
169 []*template.Template{
170 tmpls.Lookup("maddy.yaml"),
171 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400172 string(schema),
173 nil,
giolekva050609f2021-12-29 15:51:40 +0400174 }
175}
giolekvaef76a3e2022-01-10 12:22:28 +0400176
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400177func CreateAppQBittorrent(fs embed.FS, tmpls *template.Template) App {
178 schema, err := fs.ReadFile("values-tmpl/qbittorrent.jsonschema")
179 if err != nil {
180 panic(err)
181 }
giolekvaef76a3e2022-01-10 12:22:28 +0400182 return App{
183 "qbittorrent",
184 []*template.Template{
185 tmpls.Lookup("qbittorrent.yaml"),
186 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400187 string(schema),
188 nil,
giolekvaef76a3e2022-01-10 12:22:28 +0400189 }
190}
191
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400192func CreateAppJellyfin(fs embed.FS, tmpls *template.Template) App {
193 schema, err := fs.ReadFile("values-tmpl/jellyfin.jsonschema")
194 if err != nil {
195 panic(err)
196 }
giolekvaef76a3e2022-01-10 12:22:28 +0400197 return App{
198 "jellyfin",
199 []*template.Template{
200 tmpls.Lookup("jellyfin.yaml"),
201 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400202 string(schema),
203 nil,
giolekvaef76a3e2022-01-10 12:22:28 +0400204 }
205}
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400206
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400207func CreateAppRpuppy(fs embed.FS, tmpls *template.Template) App {
208 schema, err := fs.ReadFile("values-tmpl/rpuppy.jsonschema")
209 if err != nil {
210 panic(err)
211 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400212 return App{
213 "rpuppy",
214 []*template.Template{
215 tmpls.Lookup("rpuppy.yaml"),
216 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400217 string(schema),
218 tmpls.Lookup("rpuppy.md"),
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400219 }
220}
221
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400222func CreateAppHeadscale(fs embed.FS, tmpls *template.Template) App {
223 schema, err := fs.ReadFile("values-tmpl/headscale.jsonschema")
224 if err != nil {
225 panic(err)
226 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400227 return App{
228 "headscale",
229 []*template.Template{
230 tmpls.Lookup("headscale.yaml"),
231 },
Giorgi Lekveishvili7efe22f2023-05-30 13:01:53 +0400232 string(schema),
Giorgi Lekveishvili3a907052023-05-30 13:33:32 +0400233 tmpls.Lookup("headscale.md"),
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400234 }
235}