forked from alexellis/arkade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_app.go
133 lines (105 loc) · 3.88 KB
/
jenkins_app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) arkade author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package apps
import (
"fmt"
"strconv"
"strings"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/k8s"
"github.com/alexellis/arkade/pkg/types"
"github.com/alexellis/arkade/pkg"
"github.com/spf13/cobra"
)
func MakeInstallJenkins() *cobra.Command {
var jenkins = &cobra.Command{
Use: "jenkins",
Short: "Install jenkins",
Long: `Install jenkins`,
Example: ` arkade install jenkins`,
SilenceUsage: true,
}
jenkins.Flags().Bool("update-repo", true, "Update the helm repo")
jenkins.Flags().String("namespace", "default", "Kubernetes namespace for the application")
jenkins.Flags().Bool("persistence", false, "Enable persistence")
jenkins.Flags().StringArray("set", []string{},
"Use custom flags or override existing flags \n(example --set persistence.enabled=true)")
jenkins.PreRunE = func(command *cobra.Command, args []string) error {
_, err := command.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("error with --kubeconfig usage: %s", err)
}
_, err = command.Flags().GetBool("wait")
if err != nil {
return fmt.Errorf("error with --wait usage: %s", err)
}
_, err = command.Flags().GetBool("persistence")
if err != nil {
return fmt.Errorf("error with --persistence usage: %s", err)
}
_, err = command.Flags().GetString("namespace")
if err != nil {
return fmt.Errorf("error with --namespace usage: %s", err)
}
_, err = command.Flags().GetBool("update-repo")
if err != nil {
return fmt.Errorf("error with --update-repo usage: %s", err)
}
_, err = command.Flags().GetStringArray("set")
if err != nil {
return fmt.Errorf("error with --set usage: %s", err)
}
return nil
}
jenkins.RunE = func(command *cobra.Command, args []string) error {
wait, _ := command.Flags().GetBool("wait")
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
updateRepo, _ := jenkins.Flags().GetBool("update-repo")
ns, _ := command.Flags().GetString("namespace")
persistence, _ := command.Flags().GetBool("persistence")
customFlags, _ := command.Flags().GetStringArray("set")
overrides := map[string]string{}
overrides["persistence.enabled"] = strings.ToLower(strconv.FormatBool(persistence))
// set custom flags
if err := mergeFlags(overrides, customFlags); err != nil {
return err
}
arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)
if arch != IntelArch {
return fmt.Errorf(OnlyIntelArch)
}
jenkinsAppOptions := types.DefaultInstallOptions().
WithNamespace(ns).
WithHelmRepo("jenkins/jenkins").
WithHelmURL("https://charts.jenkins.io/").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath).
WithWait(wait)
_, err := apps.MakeInstallChart(jenkinsAppOptions)
if err != nil {
return err
}
fmt.Println(jenkinsInstallMsg)
return nil
}
return jenkins
}
const JenkinsInfoMsg = `# Jenkins can take several minutes to install, check its status with:
kubectl rollout status deploy/jenkins --timeout 10m
# Get the Jenkins credentials:
export USER=$(kubectl get secret jenkins \
-o jsonpath="{.data.jenkins-admin-user}" | base64 --decode)
export PASS=$(kubectl get secret jenkins \
-o jsonpath="{.data.jenkins-admin-password}" | base64 --decode)
echo "Credentials: $USER / $PASS"
# Port-forward the Jenkins service
kubectl port-forward svc/jenkins 8080:8080 &
# Open the Jenkins UI at:
echo http://127.0.0.1:8080
`
var jenkinsInstallMsg = `=======================================================================
= Jenkins has been installed. =
=======================================================================` +
"\n\n" + JenkinsInfoMsg + "\n\n" + pkg.ThanksForUsing