Skip to content
This repository was archived by the owner on Sep 18, 2021. It is now read-only.

Commit de62c96

Browse files
committed
chore(cli): do not copy project definition file
1 parent 8b882ee commit de62c96

1 file changed

Lines changed: 9 additions & 28 deletions

File tree

ansible/inventory.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,69 +37,50 @@ type Inventory struct {
3737
}
3838
}
3939

40-
func copyFile(srcPath string, destPath string) error {
41-
input, err := ioutil.ReadFile(srcPath)
42-
if err != nil {
43-
return err
44-
}
45-
46-
if err = ioutil.WriteFile(destPath, input, 0600); err != nil {
47-
return err
48-
}
49-
return nil
50-
}
51-
5240
// CreateInventoryFile creates a temporary inventory file with the given settings and returns an absolute file path.
5341
// Note: make sure to remove the file when you don't need it anymore!
5442
func CreateInventoryFile(ipAddress string, projectDefinitionFile string) (string, error) {
43+
var err error
44+
5545
conf := Inventory{}
5646
conf.All.Vars.AnsibleUser = "root"
5747
conf.All.Vars.AnsibleConnection = "ssh"
5848
conf.All.Vars.AnsiblePythonInterpreter = "/usr/bin/python3"
5949
conf.All.Hosts.Mackerel.AnsibleHost = ipAddress
6050

61-
webserverModule, err := stackhead.GetWebserverModule()
51+
conf.All.Vars.StackHeadWebserver, err = stackhead.GetWebserverModule()
6252
if err != nil {
6353
return "", err
6454
}
65-
conf.All.Vars.StackHeadWebserver = webserverModule
6655

67-
containerModule, err := stackhead.GetContainerModule()
56+
conf.All.Vars.StackHeadContainer, err = stackhead.GetContainerModule()
6857
if err != nil {
6958
return "", err
7059
}
71-
conf.All.Vars.StackHeadContainer = containerModule
7260

73-
pluginModules, err := stackhead.GetPluginModules()
61+
conf.All.Vars.StackHeadPlugins, err = stackhead.GetPluginModules()
7462
if err != nil {
7563
return "", err
7664
}
77-
conf.All.Vars.StackHeadPlugins = pluginModules
7865

7966
tmpFile, err := ioutil.TempFile("", "inventory")
8067
if err != nil {
8168
return "", err
8269
}
8370

84-
filePath, err := filepath.Abs(tmpFile.Name())
71+
inventoryFilePath, err := filepath.Abs(tmpFile.Name())
8572
if err != nil {
86-
os.Remove(tmpFile.Name())
73+
_ = os.Remove(tmpFile.Name())
8774
return "", err
8875
}
8976

9077
if len(projectDefinitionFile) > 0 {
91-
conf.All.Vars.StackHeadConfigFolder, err = ioutil.TempDir("", "project_definitions")
78+
conf.All.Vars.StackHeadConfigFolder, err = filepath.Abs(filepath.Dir(projectDefinitionFile))
9279
if err != nil {
9380
return "", err
9481
}
9582
projectDefinitionFilePath := filepath.Base(projectDefinitionFile)
9683

97-
// Copy project definition file
98-
err = copyFile(projectDefinitionFile, filepath.Join(conf.All.Vars.StackHeadConfigFolder, projectDefinitionFilePath))
99-
if err != nil {
100-
return "", err
101-
}
102-
10384
projectDefinitionFilePath = strings.TrimSuffix(projectDefinitionFilePath, ".yml")
10485
projectDefinitionFilePath = strings.TrimSuffix(projectDefinitionFilePath, ".yaml")
10586
conf.All.Hosts.Mackerel.Stackhead.Applications = append(conf.All.Hosts.Mackerel.Stackhead.Applications, projectDefinitionFilePath)
@@ -123,5 +104,5 @@ func CreateInventoryFile(ipAddress string, projectDefinitionFile string) (string
123104
return "", err
124105
}
125106

126-
return filePath, nil
107+
return inventoryFilePath, nil
127108
}

0 commit comments

Comments
 (0)