Skip to content

Commit d41a803

Browse files
author
Oleg Sucharevich
authored
create venonacli docker image
* respect KUBE_NAMESPACE , KUBE_CONTEXT, API_HOST, API_TOKEN
1 parent 26394cd commit d41a803

File tree

5 files changed

+84
-23
lines changed

5 files changed

+84
-23
lines changed

.codefresh/codefresh.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,31 @@ steps:
164164
branch:
165165
ignore:
166166
- master
167+
168+
build_cli_image:
169+
title: "Building venona cli image"
170+
type: build
171+
stage: Build & Test
172+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
173+
working_directory: ${{main_clone}}/venonactl
174+
image_name: codefresh/venonacli
175+
when:
176+
steps:
177+
- name: build_binaries
178+
on:
179+
- success
180+
181+
push_cli_image:
182+
title: "Push image with venona cli"
183+
stage: Release
184+
type: push
185+
candidate: ${{build_cli_image}}
186+
tags:
187+
- latest
188+
- ${{VERSION}}
189+
registry: "dockerhub"
190+
when:
191+
steps:
192+
- name: build_cli_image
193+
on:
194+
- success

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "venona",
3-
"version": "0.11.1",
3+
"version": "0.12.0",
44
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
55
"main": "index.js",
66
"scripts": {

venonactl/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM scratch
2+
3+
COPY dist/linux_386/venona /
4+
5+
ENTRYPOINT [ "/venona" ]
6+
7+
CMD [ "--help" ]

venonactl/cmd/install.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/codefresh-io/venona/venonactl/pkg/codefresh"
3030
runtimectl "github.com/codefresh-io/venona/venonactl/pkg/operators"
3131
"github.com/spf13/cobra"
32+
"github.com/spf13/viper"
3233
)
3334

3435
var (
@@ -37,6 +38,9 @@ var (
3738
skipRuntimeInstallation bool
3839
installOnlyRuntimeEnvironment bool
3940
setDefaultRuntime bool
41+
42+
kubeNamespace string
43+
kubeContextName string
4044
)
4145

4246
// installCmd represents the install command
@@ -46,16 +50,16 @@ var installCmd = &cobra.Command{
4650
Run: func(cmd *cobra.Command, args []string) {
4751
s := store.GetStore()
4852

49-
kubeContextName := cmd.Flag("kube-context-name").Value.String()
50-
kubeNamespace := cmd.Flag("kube-namespace").Value.String()
51-
5253
if kubeContextName == "" {
5354
config := clientcmd.GetConfigFromFileOrDie(s.KubernetesAPI.ConfigPath)
5455
kubeContextName = config.CurrentContext
5556
logrus.WithFields(logrus.Fields{
5657
"Kube-Context-Name": kubeContextName,
5758
}).Debug("Kube Context is not set, using current context")
5859
}
60+
if kubeNamespace == "" {
61+
kubeNamespace = "default"
62+
}
5963
s.KubernetesAPI.ContextName = kubeContextName
6064
s.KubernetesAPI.Namespace = kubeNamespace
6165

@@ -96,14 +100,18 @@ var installCmd = &cobra.Command{
96100

97101
func init() {
98102
rootCmd.AddCommand(installCmd)
103+
104+
viper.BindEnv("kube-namespace", "KUBE_NAMESPACE")
105+
viper.BindEnv("kube-context", "KUBE_CONTEXT")
106+
99107
installCmd.Flags().StringVar(&clusterName, "cluster-name", "", "cluster name (if not passed runtime-environment will be created cluster-less)")
100108
installCmd.Flags().String("venona-version", "", "Version of venona to install (default is the latest)")
101109
installCmd.Flags().BoolVar(&skipRuntimeInstallation, "skip-runtime-installation", false, "Set flag if you already have a configured runtime-environment, add --runtime-environment flag with name")
102110
installCmd.Flags().String("runtime-environment", "", "if --skip-runtime-installation set, will try to configure venona on current runtime-environment")
103111
installCmd.Flags().BoolVar(&installOnlyRuntimeEnvironment, "only-runtime-environment", false, "Set to true to onlky configure namespace as runtime-environment for Codefresh")
104112
installCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Set to true to simulate installation")
105-
installCmd.Flags().String("kube-namespace", "default", "Name of the namespace on which venona should be installed")
106-
installCmd.Flags().String("kube-context-name", "", "Name of the kubernetes context on which venona should be installed (default is current-context)")
113+
installCmd.Flags().StringVar(&kubeNamespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace on which venona should be installed [$KUBE_NAMESPACE]")
114+
installCmd.Flags().StringVar(&kubeContextName, "kube-context-name", viper.GetString("kube-context"), "Name of the kubernetes context on which venona should be installed (default is current-context) [$KUBE_CONTEXT]")
107115
installCmd.Flags().BoolVar(&setDefaultRuntime, "set-default", false, "Mark the install runtime-environment as default one after installation")
108116
}
109117

venonactl/cmd/root.go

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ var (
4747
// set to false by default, when running hack/build.sh will change to true
4848
// to prevent version checking during development
4949
localDevFlow = "false"
50+
51+
configPath string
52+
cfAPIHost string
53+
cfAPIToken string
54+
cfContext string
55+
56+
kubeConfigPath string
5057
)
5158

5259
var rootCmd = &cobra.Command{
@@ -59,23 +66,30 @@ var rootCmd = &cobra.Command{
5966
logrus.SetLevel(logrus.DebugLevel)
6067
}
6168

62-
configPath := cmd.Flag("cfconfig").Value.String()
6369
if configPath == "" {
6470
configPath = fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME"))
6571
}
66-
context, err := sdkUtils.ReadAuthContext(configPath, cmd.Flag("context").Value.String())
67-
if err != nil {
68-
return err
72+
73+
if cfAPIHost == "" && cfAPIToken == "" {
74+
context, err := sdkUtils.ReadAuthContext(configPath, cfContext)
75+
if err != nil {
76+
return err
77+
}
78+
cfAPIHost = context.URL
79+
cfAPIToken = context.Token
80+
81+
logrus.WithFields(logrus.Fields{
82+
"Context-Name": context.Name,
83+
"Codefresh-Host": cfAPIHost,
84+
}).Debug("Using codefresh context")
85+
} else {
86+
logrus.Debug("Using creentials from environment variables")
6987
}
70-
logrus.WithFields(logrus.Fields{
71-
"Context-Name": context.Name,
72-
"Codefresh-Host": context.URL,
73-
}).Debug("Using codefresh context")
7488
client := codefresh.New(&codefresh.ClientOptions{
7589
Auth: codefresh.AuthOptions{
76-
Token: context.Token,
90+
Token: cfAPIToken,
7791
},
78-
Host: context.URL,
92+
Host: cfAPIHost,
7993
})
8094

8195
s := store.GetStore()
@@ -118,8 +132,6 @@ var rootCmd = &cobra.Command{
118132
}
119133
}
120134

121-
kubeConfigPath := cmd.Flag("kube-config-path").Value.String()
122-
123135
if kubeConfigPath == "" {
124136
currentUser, _ := user.Current()
125137
kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config")
@@ -134,8 +146,8 @@ var rootCmd = &cobra.Command{
134146
}
135147
s.ClusterInCodefresh = clusterName
136148
s.CodefreshAPI = &store.CodefreshAPI{
137-
Host: context.URL,
138-
Token: context.Token,
149+
Host: cfAPIHost,
150+
Token: cfAPIToken,
139151
Client: client,
140152
}
141153
s.Mode = store.ModeInCluster
@@ -157,9 +169,15 @@ func init() {
157169
viper.BindEnv("kubeconfig", "KUBECONFIG")
158170
viper.BindEnv("cfconfig", "CFCONFIG")
159171

160-
rootCmd.PersistentFlags().String("cfconfig", viper.GetString("cfconfig"), "Config file (default is $HOME/.cfconfig) [$CFCONFIG]")
161-
rootCmd.PersistentFlags().String("context", "", "Name of the context from --cfconfig (default is current-context)")
162-
rootCmd.PersistentFlags().String("kube-config-path", viper.GetString("kubeconfig"), "Path to kubeconfig file (default is $HOME/.kube/config) [$KUBECONFIG]")
172+
viper.BindEnv("apihost", "API_HOST")
173+
viper.BindEnv("apitoken", "API_TOKEN")
174+
175+
rootCmd.PersistentFlags().StringVar(&configPath, "cfconfig", viper.GetString("cfconfig"), "Config file (default is $HOME/.cfconfig) [$CFCONFIG]")
176+
rootCmd.PersistentFlags().StringVar(&cfAPIHost, "api-host", viper.GetString("apihost"), "Host of codefresh [$API_HOST]")
177+
rootCmd.PersistentFlags().StringVar(&cfAPIToken, "api-token", viper.GetString("apitoken"), "Codefresh API token [$API_TOKEN]")
178+
rootCmd.PersistentFlags().StringVar(&cfContext, "context", "", "Name of the context from --cfconfig (default is current-context)")
179+
180+
rootCmd.PersistentFlags().StringVar(&kubeConfigPath, "kube-config-path", viper.GetString("kubeconfig"), "Path to kubeconfig file (default is $HOME/.kube/config) [$KUBECONFIG]")
163181
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Print logs")
164182
rootCmd.PersistentFlags().BoolVar(&skipVerionCheck, "skip-version-check", false, "Do not compare current Venona's version with latest")
165183

0 commit comments

Comments
 (0)