Compare commits
9 Commits
2.0.0-beta
...
2.0.0-beta
Author | SHA1 | Date | |
---|---|---|---|
8cf3ff9f73
|
|||
114fab4870
|
|||
5fc8c06d8b
|
|||
51ca4e81d1
|
|||
a6f6b91ab9
|
|||
63afc3066b
|
|||
|
1e8fd44857 | ||
|
1403f9b198 | ||
|
22ef9211ec |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ docker-compose*
|
|||||||
!examples/**/docker-compose*
|
!examples/**/docker-compose*
|
||||||
.credentials
|
.credentials
|
||||||
release.id
|
release.id
|
||||||
|
configs/
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<div style="text-align:center">
|
<div style="text-align:center; margin: auto" align="center">
|
||||||
<img src="./misc/logo.png" alt="Katenary Logo" />
|
<img src="./misc/logo.png" alt="Katenary Logo" style="max-width: 90%" align="center"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Katenary is a tool to help transforming `docker-compose` files to a working Helm Chart for Kubernetes.
|
Katenary is a tool to help transforming `docker-compose` files to a working Helm Chart for Kubernetes.
|
||||||
@@ -8,7 +8,7 @@ Katenary is a tool to help transforming `docker-compose` files to a working Helm
|
|||||||
|
|
||||||
This project is partially made at [Smile](https://www.smile.eu)
|
This project is partially made at [Smile](https://www.smile.eu)
|
||||||
|
|
||||||
<div style="text-align:center">
|
<div style="text-align:center" align="center">
|
||||||
<a href="https://www.smile.eu"><img src="./misc/Logo_Smile.png" alt="Smile Logo" width="250" /></a>
|
<a href="https://www.smile.eu"><img src="./misc/Logo_Smile.png" alt="Smile Logo" width="250" /></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -264,6 +264,10 @@ func buildConfigMapFromPath(name, path string) *helm.ConfigMap {
|
|||||||
c, _ := ioutil.ReadFile(f)
|
c, _ := ioutil.ReadFile(f)
|
||||||
files[filename] = string(c)
|
files[filename] = string(c)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c, _ := ioutil.ReadFile(path)
|
||||||
|
_, filename := filepath.Split(path)
|
||||||
|
files[filename] = string(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
cm := helm.NewConfigMap(name, GetRelPath(path))
|
cm := helm.NewConfigMap(name, GetRelPath(path))
|
||||||
@@ -356,7 +360,6 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
|
|||||||
pointToFile := ""
|
pointToFile := ""
|
||||||
if !stat.IsDir() {
|
if !stat.IsDir() {
|
||||||
pointToFile = filepath.Base(volname)
|
pointToFile = filepath.Base(volname)
|
||||||
volname = filepath.Dir(volname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the volume is a path and it's explicitally asked to be a configmap in labels
|
// the volume is a path and it's explicitally asked to be a configmap in labels
|
||||||
@@ -364,6 +367,7 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
|
|||||||
cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname)
|
cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname)
|
||||||
|
|
||||||
// build a configmapRef for this volume
|
// build a configmapRef for this volume
|
||||||
|
volname := PathToName(volname)
|
||||||
volumes = append(volumes, map[string]interface{}{
|
volumes = append(volumes, map[string]interface{}{
|
||||||
"name": volname,
|
"name": volname,
|
||||||
"configMap": map[string]string{
|
"configMap": map[string]string{
|
||||||
@@ -386,7 +390,8 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
|
|||||||
fileGeneratorChan <- cm
|
fileGeneratorChan <- cm
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// rmove minus sign from volume name
|
// It's a Volume. Mount this from PVC to declare.
|
||||||
|
|
||||||
volname = strings.ReplaceAll(volname, "-", "")
|
volname = strings.ReplaceAll(volname, "-", "")
|
||||||
|
|
||||||
isEmptyDir := false
|
isEmptyDir := false
|
||||||
@@ -568,6 +573,15 @@ func prepareEnvFromFiles(name string, s *types.ServiceConfig, container *helm.Co
|
|||||||
secretsFiles = strings.Split(v, ",")
|
secretsFiles = strings.Split(v, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var secretVars []string
|
||||||
|
if v, ok := s.Labels[helm.LABEL_SECRETVARS]; ok {
|
||||||
|
secretVars = strings.Split(v, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, s := range secretVars {
|
||||||
|
secretVars[i] = strings.TrimSpace(s)
|
||||||
|
}
|
||||||
|
|
||||||
// manage environment files (env_file in compose)
|
// manage environment files (env_file in compose)
|
||||||
for _, envfile := range s.EnvFile {
|
for _, envfile := range s.EnvFile {
|
||||||
f := PathToName(envfile)
|
f := PathToName(envfile)
|
||||||
@@ -589,7 +603,7 @@ func prepareEnvFromFiles(name string, s *types.ServiceConfig, container *helm.Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
envfile = filepath.Join(compose.GetCurrentDir(), envfile)
|
envfile = filepath.Join(compose.GetCurrentDir(), envfile)
|
||||||
if err := store.AddEnvFile(envfile); err != nil {
|
if err := store.AddEnvFile(envfile, secretVars); err != nil {
|
||||||
logger.ActivateColors = true
|
logger.ActivateColors = true
|
||||||
logger.Red(err.Error())
|
logger.Red(err.Error())
|
||||||
logger.ActivateColors = false
|
logger.ActivateColors = false
|
||||||
|
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// replaceChars replaces some chars in a string.
|
// replaceChars replaces some chars in a string.
|
||||||
const replaceChars = `[^a-zA-Z0-9._]`
|
const replaceChars = `[^a-zA-Z0-9_]+`
|
||||||
|
|
||||||
// GetRelPath return the relative path from the root of the project.
|
// GetRelPath return the relative path from the root of the project.
|
||||||
func GetRelPath(path string) string {
|
func GetRelPath(path string) string {
|
||||||
|
14
generator/utils_test.go
Normal file
14
generator/utils_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package generator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"katenary/compose"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_PathToName(t *testing.T) {
|
||||||
|
path := compose.GetCurrentDir() + "/envéfoo.file"
|
||||||
|
name := PathToName(path)
|
||||||
|
if name != "env-foo-file" {
|
||||||
|
t.Error("Expected env-foo-file, got ", name)
|
||||||
|
}
|
||||||
|
}
|
@@ -77,6 +77,7 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
service.Ports = make([]types.ServicePortConfig, 0)
|
service.Ports = make([]types.ServicePortConfig, 0)
|
||||||
}
|
}
|
||||||
for _, port := range strings.Split(ports, ",") {
|
for _, port := range strings.Split(ports, ",") {
|
||||||
|
port = strings.TrimSpace(port)
|
||||||
target, err := strconv.Atoi(port)
|
target, err := strconv.Atoi(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
3
go.mod
3
go.mod
@@ -3,10 +3,9 @@ module katenary
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/compose-spec/compose-go v1.2.4
|
github.com/compose-spec/compose-go v1.2.5
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414 // indirect
|
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414 // indirect
|
||||||
github.com/kr/pretty v0.2.0 // indirect
|
github.com/kr/pretty v0.2.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||||
golang.org/x/mod v0.5.1
|
golang.org/x/mod v0.5.1
|
||||||
|
11
go.sum
11
go.sum
@@ -30,8 +30,8 @@ github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0Bsq
|
|||||||
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
|
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
|
||||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/compose-spec/compose-go v1.2.4 h1:nzTFqM8+2J7Veao5Pq5U451thinv3U1wChIvcjX59/A=
|
github.com/compose-spec/compose-go v1.2.5 h1:yGaACRJrWTQMFW89/ck2o1qd3gIxAji4EQkgewH3hqc=
|
||||||
github.com/compose-spec/compose-go v1.2.4/go.mod h1:pAy7Mikpeft4pxkFU565/DRHEbDfR84G6AQuiL+Hdg8=
|
github.com/compose-spec/compose-go v1.2.5/go.mod h1:a/H2RY5UejNRhzbNXHygSAxBARTpLmLlaCkh58xfStM=
|
||||||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
@@ -47,8 +47,6 @@ github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11
|
|||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e/go.mod h1:xpWTC2KnJMiDLkoawhsPQcXjvwATEBcbq0xevG2YR9M=
|
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e/go.mod h1:xpWTC2KnJMiDLkoawhsPQcXjvwATEBcbq0xevG2YR9M=
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20220504180456-7a6b9e3042bd h1:KRoLSsR7wZ4H2dueR/O6BGBIXDxfOxUVmaMiu1QiQPw=
|
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20220504180456-7a6b9e3042bd/go.mod h1:qLi7jGj1b5TUaYTB3ekkHiocxHJi8+3CFhXM54MGKBs=
|
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414 h1:KfVB1Z5fm10trO24Rn5Zzocd8sTm5k/gS24ijxQ1aJU=
|
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414 h1:KfVB1Z5fm10trO24Rn5Zzocd8sTm5k/gS24ijxQ1aJU=
|
||||||
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414/go.mod h1:2oyLKljQFnsI1tzJxjUg4GI+HEpDfzFP3LrGM04rKg0=
|
github.com/distribution/distribution/v3 v3.0.0-20220505155552-985711c1f414/go.mod h1:2oyLKljQFnsI1tzJxjUg4GI+HEpDfzFP3LrGM04rKg0=
|
||||||
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
|
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
|
||||||
@@ -121,7 +119,6 @@ github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lL
|
|||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
|
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
|
||||||
@@ -299,6 +296,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk=
|
gotest.tools/v3 v3.2.0 h1:I0DwBVMGAx26dttAj1BtJLAkVGncrkkUXfJLC4Flt/I=
|
||||||
gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ=
|
gotest.tools/v3 v3.2.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
@@ -9,11 +9,14 @@ import (
|
|||||||
|
|
||||||
// InlineConfig is made to represent a configMap or a secret
|
// InlineConfig is made to represent a configMap or a secret
|
||||||
type InlineConfig interface {
|
type InlineConfig interface {
|
||||||
AddEnvFile(filename string) error
|
AddEnvFile(filename string, filter []string) error
|
||||||
AddEnv(key, val string) error
|
AddEnv(key, val string) error
|
||||||
Metadata() *Metadata
|
Metadata() *Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ InlineConfig = (*ConfigMap)(nil)
|
||||||
|
var _ InlineConfig = (*Secret)(nil)
|
||||||
|
|
||||||
// ConfigMap is made to represent a configMap with data.
|
// ConfigMap is made to represent a configMap with data.
|
||||||
type ConfigMap struct {
|
type ConfigMap struct {
|
||||||
*K8sBase `yaml:",inline"`
|
*K8sBase `yaml:",inline"`
|
||||||
@@ -42,7 +45,7 @@ func (c *ConfigMap) Metadata() *Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEnvFile adds an environment file to the configMap.
|
// AddEnvFile adds an environment file to the configMap.
|
||||||
func (c *ConfigMap) AddEnvFile(file string) error {
|
func (c *ConfigMap) AddEnvFile(file string, filter []string) error {
|
||||||
content, err := ioutil.ReadFile(file)
|
content, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -50,15 +53,26 @@ func (c *ConfigMap) AddEnvFile(file string) error {
|
|||||||
|
|
||||||
lines := strings.Split(string(content), "\n")
|
lines := strings.Split(string(content), "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
|
//Check if the line is a comment
|
||||||
l = strings.TrimSpace(l)
|
l = strings.TrimSpace(l)
|
||||||
if len(l) == 0 {
|
isComment := strings.HasPrefix(l, "#")
|
||||||
|
if len(l) == 0 || isComment {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parts := strings.SplitN(l, "=", 2)
|
parts := strings.SplitN(l, "=", 2)
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
return errors.New("The environment file " + file + " is not valid")
|
return errors.New("The environment file " + file + " is not valid")
|
||||||
}
|
}
|
||||||
c.Data[parts[0]] = parts[1]
|
|
||||||
|
var skip bool
|
||||||
|
for _, filterEnv := range filter {
|
||||||
|
if parts[0] == filterEnv {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !skip {
|
||||||
|
c.Data[parts[0]] = parts[1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -91,7 +105,7 @@ func NewSecret(name, path string) *Secret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEnvFile adds an environment file to the secret.
|
// AddEnvFile adds an environment file to the secret.
|
||||||
func (s *Secret) AddEnvFile(file string) error {
|
func (s *Secret) AddEnvFile(file string, filter []string) error {
|
||||||
content, err := ioutil.ReadFile(file)
|
content, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -100,14 +114,24 @@ func (s *Secret) AddEnvFile(file string) error {
|
|||||||
lines := strings.Split(string(content), "\n")
|
lines := strings.Split(string(content), "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
l = strings.TrimSpace(l)
|
l = strings.TrimSpace(l)
|
||||||
if len(l) == 0 {
|
isComment := strings.HasPrefix(l, "#")
|
||||||
|
if len(l) == 0 || isComment {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parts := strings.SplitN(l, "=", 2)
|
parts := strings.SplitN(l, "=", 2)
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
return errors.New("The environment file " + file + " is not valid")
|
return errors.New("The environment file " + file + " is not valid")
|
||||||
}
|
}
|
||||||
s.Data[parts[0]] = fmt.Sprintf(`{{ "%s" | b64enc }}`, parts[1])
|
|
||||||
|
var skip bool
|
||||||
|
for _, filterEnv := range filter {
|
||||||
|
if parts[0] == filterEnv {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !skip {
|
||||||
|
s.Data[parts[0]] = fmt.Sprintf(`{{ "%s" | b64enc }}`, parts[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user