Skip to content

Commit 3e0a381

Browse files
committed
include files needed for deployment - env files
1 parent 0301555 commit 3e0a381

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

commands/cloud_deploy.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,17 @@ func (d *KoolDeploy) createReleaseFile() (filename string, err error) {
233233
allFiles = append(allFiles, filepath.Join(d.env.Get("PWD"), "docker-compose.yml"))
234234
}
235235

236+
// we need to include the .env files as well
237+
allFiles = append(allFiles, d.cloudConfig.GetEnvFiles()...)
238+
236239
d.shell.Println("Compressing files:")
237240
for _, file := range allFiles {
238241
d.shell.Println(" -", file)
239242
}
240243

241244
tarball.SourceDir(d.env.Get("PWD"))
242245

243-
filename, err = tarball.CompressFiles(d.handleDeployEnv(allFiles))
246+
filename, err = tarball.CompressFiles(allFiles)
244247

245248
if err == nil {
246249
d.shell.Println("Files compression done.")
@@ -249,32 +252,6 @@ func (d *KoolDeploy) createReleaseFile() (filename string, err error) {
249252
return
250253
}
251254

252-
// handleDeployEnv tackles a special case on kool.deploy.env file.
253-
// This file can or cannot be versioned (good practice not to, since
254-
// it may include sensitive data). In the case of it being ignored
255-
// from GIT, we still are required to send it - it is required for
256-
// the Deploy API.
257-
func (d *KoolDeploy) handleDeployEnv(files []string) []string {
258-
path := filepath.Join(d.env.Get("PWD"), koolDeployEnv)
259-
if _, envErr := os.Stat(path); os.IsNotExist(envErr) {
260-
return files
261-
}
262-
263-
var isAlreadyIncluded bool = false
264-
for _, file := range files {
265-
if file == koolDeployEnv {
266-
isAlreadyIncluded = true
267-
break
268-
}
269-
}
270-
271-
if !isAlreadyIncluded {
272-
files = append(files, koolDeployEnv)
273-
}
274-
275-
return files
276-
}
277-
278255
func (d *KoolDeploy) loadAndValidateConfig() (err error) {
279256
if d.cloudConfig, err = cloud.ParseCloudConfig(d.env.Get("PWD"), setup.KoolDeployFile); err != nil {
280257
return

services/cloud/deploy_validator.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ type DeployConfig struct {
1919
Cloud *CloudConfig
2020
}
2121

22+
func (c *DeployConfig) GetEnvFiles() []string {
23+
files := make(map[string]bool)
24+
25+
for _, srv := range c.Cloud.Services {
26+
if srv.Env != nil {
27+
if env, ok := srv.Env.(map[string]interface{}); ok {
28+
if envFile, okSrc := env["source"].(string); okSrc {
29+
files[envFile] = true
30+
}
31+
}
32+
}
33+
34+
if srv.Environment != nil {
35+
if envFile, ok := srv.Environment.(string); ok {
36+
files[envFile] = true
37+
}
38+
}
39+
}
40+
41+
envs := make([]string, len(files))
42+
43+
for envFile := range files {
44+
envs = append(envs, filepath.Join(c.Meta.WorkingDir, envFile))
45+
}
46+
47+
return envs
48+
}
49+
2250
// CloudConfig is the configuration for a deploy parsed from kool.cloud.yml
2351
type CloudConfig struct {
2452
// version of the Kool.dev Cloud config file
@@ -36,6 +64,7 @@ type DeployConfigService struct {
3664

3765
Public interface{} `yaml:"public,omitempty"`
3866
Environment interface{} `yaml:"environment"`
67+
Env interface{} `yaml:"env"`
3968
}
4069

4170
// DeployConfigBuild is the configuration for a service to be built

0 commit comments

Comments
 (0)