Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
devtool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
k8s
devtool
Commits
b4cdb18f
Commit
b4cdb18f
authored
Mar 22, 2019
by
Christopher Harm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Imporving support for config init command
parent
8549a7d4
Pipeline
#29407
passed with stages
in 48 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
8 deletions
+63
-8
cmd/config_init.go
cmd/config_init.go
+63
-8
No files found.
cmd/config_init.go
View file @
b4cdb18f
...
...
@@ -16,11 +16,14 @@ package cmd
import
(
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"git.psu.edu/k8s/devtool/environment"
"git.psu.edu/k8s/devtool/config"
"github.com/fatih/color"
...
...
@@ -85,7 +88,7 @@ var initCmd = &cobra.Command{
dockerfiles
:=
findDockerfiles
()
for
_
,
file
:=
range
dockerfiles
{
color
.
Yellow
(
"Found Dockerfile: %s"
,
file
)
color
.
New
(
color
.
FgYellow
)
.
Printf
(
"Found Dockerfile: %s"
,
file
)
prompt
:=
promptui
.
Prompt
{
Label
:
"Include in config"
,
Default
:
"Yes"
,
...
...
@@ -121,6 +124,7 @@ var initCmd = &cobra.Command{
}
deployable
.
Name
=
response
// Ask for Chart
selectPrompt
:=
promptui
.
SelectWithAdd
{
Label
:
"Chart"
,
Items
:
[]
string
{
"cm/eio-swe-service"
,
"cm/eio-swe-cronjob"
,
"cm/angular-client"
,
"cm/eio-swe-jms-processor"
},
...
...
@@ -132,31 +136,53 @@ var initCmd = &cobra.Command{
}
deployable
.
Chart
=
response
prompt
=
promptui
.
Prompt
{
// Ask for Chart Version
availableChartVersions
:=
findChartVersions
(
response
)
selectPrompt
=
promptui
.
SelectWithAdd
{
Label
:
"Chart Version"
,
Items
:
availableChartVersions
,
AddLabel
:
"Other"
,
}
response
,
err
=
p
rompt
.
Run
()
_
,
response
,
err
=
selectP
rompt
.
Run
()
if
err
!=
nil
{
return
}
deployable
.
ChartVersion
=
response
prompt
=
promptui
.
Prompt
{
// Ask for Local Config
availableLocalConfigFiles
:=
findLocalConfigs
()
selectPrompt
=
promptui
.
SelectWithAdd
{
Label
:
"Local Config File"
,
Items
:
availableLocalConfigFiles
,
AddLabel
:
"Other"
,
}
response
,
err
=
p
rompt
.
Run
()
_
,
response
,
err
=
selectP
rompt
.
Run
()
if
err
!=
nil
{
return
}
deployable
.
LocalConfig
=
response
// Create the file if it doesn't exist already
_
,
err
=
os
.
OpenFile
(
response
,
os
.
O_RDONLY
|
os
.
O_CREATE
,
0666
)
if
err
!=
nil
{
color
.
Yellow
(
"Unable to create config file"
)
}
conf
.
Deployables
=
append
(
conf
.
Deployables
,
deployable
)
color
.
Green
(
"Adding Deployment"
)
}
conf
.
LocalEnvVars
=
[]
string
{
"OAUTH_CLIENT_ID"
}
conf
.
LocalEnvVars
=
[]
string
{
"OAUTH_CLIENT_SECRET"
,
"OAUTH_JWK"
}
color
.
Yellow
(
"Writing configuration"
)
conf
.
Write
(
configFile
)
err
=
conf
.
Write
(
configFile
)
if
err
!=
nil
{
color
.
New
(
color
.
FgRed
)
.
Printf
(
"Error writing configuration file: %s"
,
configFile
)
}
},
}
...
...
@@ -195,3 +221,32 @@ func findDockerfiles() []string {
}
return
dockerfiles
}
func
findChartVersions
(
chartName
string
)
[]
string
{
var
versions
[]
string
output
:=
environment
.
RunAndGetOutputRequired
(
"helm"
,
"search"
,
chartName
,
"--versions"
)
for
i
,
line
:=
range
output
{
if
i
==
0
{
continue
}
fields
:=
strings
.
Fields
(
line
)
if
len
(
fields
)
<
4
{
continue
}
versions
=
append
(
versions
,
fields
[
1
])
}
return
versions
}
func
findLocalConfigs
()
[]
string
{
files
,
err
:=
ioutil
.
ReadDir
(
"config/"
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
var
filenames
[]
string
for
_
,
f
:=
range
files
{
filenames
=
append
(
filenames
,
"config/"
+
f
.
Name
())
}
return
filenames
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment