| giolekva | 8aa73e8 | 2022-07-09 11:34:39 +0400 | [diff] [blame] | 1 | package installer |
| giolekva | 050609f | 2021-12-29 15:51:40 +0400 | [diff] [blame] | 2 | |
| giolekva | 8aa73e8 | 2022-07-09 11:34:39 +0400 | [diff] [blame] | 3 | import ( |
| 4 | "embed" |
| Giorgi Lekveishvili | bd6be7f | 2023-05-26 15:51:28 +0400 | [diff] [blame^] | 5 | "fmt" |
| giolekva | 8aa73e8 | 2022-07-09 11:34:39 +0400 | [diff] [blame] | 6 | "log" |
| 7 | "text/template" |
| 8 | ) |
| giolekva | 050609f | 2021-12-29 15:51:40 +0400 | [diff] [blame] | 9 | |
| Giorgi Lekveishvili | bd6be7f | 2023-05-26 15:51:28 +0400 | [diff] [blame^] | 10 | //go:embed values-tmpl |
| 11 | var valuesTmpls embed.FS |
| 12 | |
| giolekva | 050609f | 2021-12-29 15:51:40 +0400 | [diff] [blame] | 13 | type App struct { |
| 14 | Name string |
| 15 | Templates []*template.Template |
| 16 | } |
| 17 | |
| Giorgi Lekveishvili | bd6be7f | 2023-05-26 15:51:28 +0400 | [diff] [blame^] | 18 | type AppRepository interface { |
| 19 | Find(name string) (*App, error) |
| 20 | } |
| 21 | |
| 22 | type InMemoryAppRepository struct { |
| 23 | apps []App |
| 24 | } |
| 25 | |
| 26 | func NewInMemoryAppRepository(apps []App) AppRepository { |
| 27 | return &InMemoryAppRepository{ |
| 28 | apps, |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func (r InMemoryAppRepository) Find(name string) (*App, error) { |
| 33 | for _, a := range r.apps { |
| 34 | if a.Name == name { |
| 35 | return &a, nil |
| 36 | } |
| 37 | } |
| 38 | return nil, fmt.Errorf("Application not found: %s", name) |
| 39 | } |
| giolekva | 8aa73e8 | 2022-07-09 11:34:39 +0400 | [diff] [blame] | 40 | |
| 41 | func CreateAllApps() []App { |
| 42 | tmpls, err := template.ParseFS(valuesTmpls, "values-tmpl/*.yaml") |
| 43 | if err != nil { |
| 44 | log.Fatal(err) |
| 45 | } |
| giolekva | ef76a3e | 2022-01-10 12:22:28 +0400 | [diff] [blame] | 46 | return []App{ |
| Giorgi Lekveishvili | 23ef7f8 | 2023-05-26 11:57:48 +0400 | [diff] [blame] | 47 | // CreateAppIngressPublic(tmpls), |
| giolekva | ef76a3e | 2022-01-10 12:22:28 +0400 | [diff] [blame] | 48 | CreateAppIngressPrivate(tmpls), |
| 49 | CreateAppCoreAuth(tmpls), |
| 50 | CreateAppVaultwarden(tmpls), |
| 51 | CreateAppMatrix(tmpls), |
| 52 | CreateAppPihole(tmpls), |
| 53 | CreateAppMaddy(tmpls), |
| 54 | CreateAppQBittorrent(tmpls), |
| 55 | CreateAppJellyfin(tmpls), |
| Giorgi Lekveishvili | 23ef7f8 | 2023-05-26 11:57:48 +0400 | [diff] [blame] | 56 | CreateAppRpuppy(tmpls), |
| 57 | CreateAppHeadscale(tmpls), |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func CreateAppIngressPublic(tmpls *template.Template) App { |
| 62 | return App{ |
| 63 | "ingress-public", |
| 64 | []*template.Template{ |
| 65 | tmpls.Lookup("ingress-public.yaml"), |
| 66 | }, |
| giolekva | ef76a3e | 2022-01-10 12:22:28 +0400 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| giolekva | 050609f | 2021-12-29 15:51:40 +0400 | [diff] [blame] | 70 | func CreateAppIngressPrivate(tmpls *template.Template) App { |
| 71 | return App{ |
| 72 | "ingress-private", |
| 73 | []*template.Template{ |
| Giorgi Lekveishvili | 23ef7f8 | 2023-05-26 11:57:48 +0400 | [diff] [blame] | 74 | // tmpls.Lookup("vpn-mesh-config.yaml"), |
| giolekva | 050609f | 2021-12-29 15:51:40 +0400 | [diff] [blame] | 75 | tmpls.Lookup("ingress-private.yaml"), |
| 76 | tmpls.Lookup("certificate-issuer.yaml"), |
| 77 | }, |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func CreateAppCoreAuth(tmpls *template.Template) App { |
| 82 | return App{ |
| 83 | "core-auth", |
| 84 | []*template.Template{ |
| 85 | tmpls.Lookup("core-auth-storage.yaml"), |
| 86 | tmpls.Lookup("core-auth.yaml"), |
| 87 | }, |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func CreateAppVaultwarden(tmpls *template.Template) App { |
| 92 | return App{ |
| 93 | "vaultwarden", |
| 94 | []*template.Template{ |
| 95 | tmpls.Lookup("vaultwarden.yaml"), |
| 96 | }, |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func CreateAppMatrix(tmpls *template.Template) App { |
| 101 | return App{ |
| 102 | "matrix", |
| 103 | []*template.Template{ |
| 104 | tmpls.Lookup("matrix-storage.yaml"), |
| 105 | tmpls.Lookup("matrix.yaml"), |
| 106 | }, |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func CreateAppPihole(tmpls *template.Template) App { |
| 111 | return App{ |
| 112 | "pihole", |
| 113 | []*template.Template{ |
| 114 | tmpls.Lookup("pihole.yaml"), |
| 115 | }, |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | func CreateAppMaddy(tmpls *template.Template) App { |
| 120 | return App{ |
| 121 | "maddy", |
| 122 | []*template.Template{ |
| 123 | tmpls.Lookup("maddy.yaml"), |
| 124 | }, |
| 125 | } |
| 126 | } |
| giolekva | ef76a3e | 2022-01-10 12:22:28 +0400 | [diff] [blame] | 127 | |
| 128 | func CreateAppQBittorrent(tmpls *template.Template) App { |
| 129 | return App{ |
| 130 | "qbittorrent", |
| 131 | []*template.Template{ |
| 132 | tmpls.Lookup("qbittorrent.yaml"), |
| 133 | }, |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func CreateAppJellyfin(tmpls *template.Template) App { |
| 138 | return App{ |
| 139 | "jellyfin", |
| 140 | []*template.Template{ |
| 141 | tmpls.Lookup("jellyfin.yaml"), |
| 142 | }, |
| 143 | } |
| 144 | } |
| Giorgi Lekveishvili | 23ef7f8 | 2023-05-26 11:57:48 +0400 | [diff] [blame] | 145 | |
| 146 | func CreateAppRpuppy(tmpls *template.Template) App { |
| 147 | return App{ |
| 148 | "rpuppy", |
| 149 | []*template.Template{ |
| 150 | tmpls.Lookup("rpuppy.yaml"), |
| 151 | }, |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func CreateAppHeadscale(tmpls *template.Template) App { |
| 156 | return App{ |
| 157 | "headscale", |
| 158 | []*template.Template{ |
| 159 | tmpls.Lookup("headscale.yaml"), |
| 160 | }, |
| 161 | } |
| 162 | } |