Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 797f58d

Browse files
committed
big update of the installer with the docker options
1 parent 3fdc0b7 commit 797f58d

30 files changed

Lines changed: 1256 additions & 1801 deletions

cmd/create.go

Lines changed: 9 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -19,229 +19,36 @@
1919
package cmd
2020

2121
import (
22-
"github.com/a8m/envsubst"
23-
"github.com/joho/godotenv"
22+
"github.com/epos-eu/opensource-kubernetes/cmd/methods"
2423
"github.com/spf13/cobra"
25-
"os"
26-
"os/exec"
27-
"regexp"
28-
"strings"
29-
"time"
30-
)
31-
32-
var (
33-
lineBreakRegExp = regexp.MustCompile(`\r?\n`)
3424
)
3525

3626
var deployCmd = &cobra.Command{
3727
Use: "deploy",
3828
Short: "Deploy an environment on Kubernetes",
3929
Long: `Deploy an enviroment with .env set up on Kubernetes`,
40-
Run: func(cmd *cobra.Command, args []string) {
30+
RunE: func(cmd *cobra.Command, args []string) error {
4131
env, _ := cmd.Flags().GetString("env")
4232
context, _ := cmd.Flags().GetString("context")
4333
namespace, _ := cmd.Flags().GetString("namespace")
4434
tag, _ := cmd.Flags().GetString("tag")
45-
isDefaultEnv := false
46-
if env == "" {
47-
env = generateTempFile(configurations)
48-
isDefaultEnv = true
49-
}
50-
fileContents, err := os.ReadFile(env)
51-
if err != nil {
52-
printError("Loading env variables from " + env + " cause: " + err.Error())
53-
os.Exit(0)
54-
}
55-
fileLines := lineBreakRegExp.Split(string(fileContents), -1)
56-
for _, line := range fileLines {
57-
if strings.Contains(line, "=") {
58-
res1 := strings.Split(line, "=")
59-
os.Setenv(res1[0], res1[1])
60-
}
61-
}
62-
63-
os.Setenv("CONTEXT", context)
64-
os.Setenv("DEPLOY_TAG", tag)
65-
os.Setenv("NAMESPACE", namespace)
66-
os.Setenv("DEPLOY_PATH", "/"+namespace+"/")
67-
os.Setenv("BASE_CONTEXT", "/"+namespace)
68-
os.Setenv("POSTGRESQL_CONNECTION_STRING", "jdbc:postgresql://"+os.Getenv("POSTGRESQL_HOST")+"/"+os.Getenv("POSTGRES_DB")+"?user="+os.Getenv("POSTGRES_USER")+"&password="+os.Getenv("POSTGRESQL_PASSWORD")+"")
69-
if isDefaultEnv {
70-
checkImagesUpdate()
71-
}
72-
setupIPs()
73-
74-
operator, err = envsubst.Bytes([]byte(operator))
75-
if err != nil {
76-
printError("Updating env variables of " + string(operator) + " cause: " + err.Error())
77-
os.Exit(0)
78-
}
79-
rabbitmqoperatorfile := generateTempFile(operator)
80-
81-
rabbitmq, err = envsubst.Bytes([]byte(rabbitmq))
82-
if err != nil {
83-
printError("Updating env variables of " + string(rabbitmq) + " cause: " + err.Error())
84-
os.Exit(0)
85-
}
86-
rabbitmqfile := generateTempFile(rabbitmq)
87-
88-
logging, err = envsubst.Bytes([]byte(logging))
89-
if err != nil {
90-
printError("Updating env variables of " + string(logging) + " cause: " + err.Error())
91-
os.Exit(0)
92-
}
93-
loggingfile := generateTempFile(logging)
94-
95-
secrets, err = envsubst.Bytes([]byte(secrets))
96-
if err != nil {
97-
printError("Updating env variables of " + string(secrets) + " cause: " + err.Error())
98-
os.Exit(0)
99-
}
100-
secretsfile := generateTempFile(secrets)
101-
102-
backoffice, err = envsubst.Bytes([]byte(backoffice))
103-
if err != nil {
104-
printError("Updating env variables of " + string(backoffice) + " cause: " + err.Error())
105-
os.Exit(0)
106-
}
107-
backofficefile := generateTempFile(backoffice)
108-
109-
dataMetadata, err = envsubst.Bytes([]byte(dataMetadata))
110-
if err != nil {
111-
printError("Updating env variables of " + string(dataMetadata) + " cause: " + err.Error())
112-
os.Exit(0)
113-
}
114-
datametadatafile := generateTempFile(dataMetadata)
115-
116-
externalAccess, err = envsubst.Bytes([]byte(externalAccess))
117-
if err != nil {
118-
printError("Updating env variables of " + string(externalAccess) + " cause: " + err.Error())
119-
os.Exit(0)
120-
}
121-
externalaccessfile := generateTempFile(externalAccess)
122-
123-
ingestor, err = envsubst.Bytes([]byte(ingestor))
124-
if err != nil {
125-
printError("Updating env variables of " + string(ingestor) + " cause: " + err.Error())
126-
os.Exit(0)
127-
}
128-
ingestorfile := generateTempFile(ingestor)
129-
130-
metadataDatabase, err = envsubst.Bytes([]byte(metadataDatabase))
131-
if err != nil {
132-
printError("Updating env variables of " + string(metadataDatabase) + " cause: " + err.Error())
133-
os.Exit(0)
134-
}
135-
metadatadatabasefile := generateTempFile(metadataDatabase)
35+
autoupdate, _ := cmd.Flags().GetString("autoupdate")
36+
update, _ := cmd.Flags().GetString("update")
13637

137-
redisDatabase, err = envsubst.Bytes([]byte(redisDatabase))
138-
if err != nil {
139-
printError("Updating env variables of " + string(redisDatabase) + " cause: " + err.Error())
140-
os.Exit(0)
38+
if err := methods.CreateEnvironment(env, context, namespace, tag, autoupdate, update); err != nil {
39+
return err
14140
}
142-
redisdatabasefile := generateTempFile(redisDatabase)
143-
144-
resources, err = envsubst.Bytes([]byte(resources))
145-
if err != nil {
146-
printError("Updating env variables of " + string(resources) + " cause: " + err.Error())
147-
os.Exit(0)
148-
}
149-
resourcesfile := generateTempFile(resources)
150-
151-
gateway, err = envsubst.Bytes([]byte(gateway))
152-
if err != nil {
153-
printError("Updating env variables of " + string(gateway) + " cause: " + err.Error())
154-
os.Exit(0)
155-
}
156-
gatewayfile := generateTempFile(gateway)
157-
158-
converter, err = envsubst.Bytes([]byte(converter))
159-
if err != nil {
160-
printError("Updating env variables of " + string(converter) + " cause: " + err.Error())
161-
os.Exit(0)
162-
}
163-
converterfile := generateTempFile(converter)
164-
165-
list_of_services := [13]string{rabbitmqoperatorfile, rabbitmqfile, loggingfile, secretsfile, metadatadatabasefile,
166-
backofficefile, datametadatafile, externalaccessfile, ingestorfile,
167-
redisdatabasefile, resourcesfile, gatewayfile, converterfile}
168-
169-
if err := godotenv.Load(env); err != nil {
170-
printError("Error loading env variables from " + env + " cause: " + err.Error())
171-
os.Exit(0)
172-
}
173-
174-
printSetup(env, context, namespace, tag)
175-
printTask("Switching context to " + context)
176-
177-
execute_command(cmd, exec.Command("kubectl",
178-
"config",
179-
"use-context",
180-
context))
181-
182-
printTask("Deploy of ingress nginx")
183-
184-
execute_command(cmd, exec.Command("kubectl",
185-
"apply",
186-
"-f",
187-
"https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml"))
188-
189-
printTask("Creating namespace: " + namespace)
190-
execute_command(cmd, exec.Command("kubectl",
191-
"create",
192-
"ns",
193-
namespace))
194-
195-
time.Sleep(10 * time.Second)
196-
197-
printTask("Deploy of " + list_of_services[0])
198-
199-
execute_command(cmd, exec.Command("kubectl",
200-
"apply",
201-
"-f",
202-
list_of_services[0]))
203-
204-
time.Sleep(10 * time.Second)
205-
206-
for i := 1; i < 13; i++ {
207-
printTask("Deploy of " + list_of_services[i])
208-
execute_command(cmd, exec.Command(
209-
"kubectl",
210-
"apply",
211-
"-f",
212-
list_of_services[i],
213-
"-n",
214-
namespace))
215-
printTask("Waiting for conditions met")
216-
execute_command(cmd, exec.Command("kubectl",
217-
"wait",
218-
"--for=condition=Ready",
219-
"pods",
220-
"--all",
221-
"-n",
222-
namespace))
223-
224-
time.Sleep(10 * time.Second)
225-
}
226-
227-
print_urls()
228-
41+
return nil
22942
},
23043
}
23144

232-
func execute_command(cmd *cobra.Command, command *exec.Cmd) {
233-
command.Stdout = os.Stdout
234-
command.Stderr = os.Stderr
235-
if err := command.Run(); err != nil {
236-
printError("Error on executing command, cause: " + err.Error())
237-
}
238-
}
239-
24045
func init() {
24146
deployCmd.Flags().String("context", "", "Kubernetes context")
24247
deployCmd.MarkFlagRequired("context")
24348
deployCmd.Flags().String("namespace", "", "Kubernetes namespace")
24449
deployCmd.MarkFlagRequired("namespace")
24550
deployCmd.Flags().String("tag", "", "Version Tag")
24651
deployCmd.MarkFlagRequired("tag")
52+
deployCmd.Flags().String("autoupdate", "", "Auto update the images versions (true|false)")
53+
deployCmd.Flags().String("update", "", "Update of an existing deployment (true|false), default false")
24754
}

cmd/delete.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,23 @@ package cmd
2020

2121
import (
2222
_ "embed"
23+
24+
"github.com/epos-eu/opensource-kubernetes/cmd/methods"
2325
"github.com/spf13/cobra"
24-
"os"
25-
"os/exec"
2626
)
2727

2828
var deleteCmd = &cobra.Command{
2929
Use: "delete",
3030
Short: "Delete an environment on Kubernetes",
3131
Long: `Delete an enviroment on Kubernetes using Namespace`,
32-
Run: func(cmd *cobra.Command, args []string) {
32+
RunE: func(cmd *cobra.Command, args []string) error {
3333
context, _ := cmd.Flags().GetString("context")
3434
namespace, _ := cmd.Flags().GetString("namespace")
35-
setupIPs()
36-
printSetupShort(context, namespace)
37-
command := exec.Command("kubectl",
38-
"config",
39-
"use-context",
40-
context)
41-
command.Stdout = os.Stdout
42-
command.Stderr = os.Stderr
43-
if err := command.Run(); err != nil {
44-
printError("Error on executing command, cause:" + err.Error())
45-
}
46-
command = exec.Command("kubectl",
47-
"delete",
48-
"ns",
49-
namespace)
50-
command.Stdout = os.Stdout
51-
command.Stderr = os.Stderr
52-
if err := command.Run(); err != nil {
53-
printError("Error on executing command, cause:" + err.Error())
35+
36+
if err := methods.DeleteEnvironment(context, namespace); err != nil {
37+
return err
5438
}
39+
return nil
5540
},
5641
}
5742

cmd/export.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ package cmd
2020

2121
import (
2222
_ "embed"
23+
24+
"github.com/epos-eu/opensource-kubernetes/cmd/methods"
2325
"github.com/spf13/cobra"
2426
)
2527

2628
var exportCmd = &cobra.Command{
2729
Use: "export",
2830
Short: "Export configuration files in output folder, options: [env]",
2931
Long: `Export configuration files for customization in output folder, options: [env]`,
30-
Run: func(cmd *cobra.Command, args []string) {
32+
RunE: func(cmd *cobra.Command, args []string) error {
3133

3234
file, _ := cmd.Flags().GetString("file")
3335
output, _ := cmd.Flags().GetString("output")
3436

35-
switch file {
36-
case "env":
37-
generateFile(configurations, output+"/configurations.env")
38-
default:
39-
printError("Invalid option, available options: [env]")
37+
if err := methods.ExportVariablesEnvironment(file, output); err != nil {
38+
return err
4039
}
40+
return nil
4141
},
4242
}
4343

cmd/kubernetes-resources/redis-database.yaml

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)