fix: correct stickler-ci errors and remove unused code

This commit is contained in:
Jose Diaz-Gonzalez
2020-08-31 18:44:00 -04:00
parent 2b65def123
commit b8b6d64f75
3 changed files with 18 additions and 44 deletions

View File

@@ -13,7 +13,7 @@ import (
shellquote "github.com/kballard/go-shellquote"
)
type AppJson struct {
type AppJSON struct {
Scripts struct {
Dokku struct {
Predeploy string `json:"predeploy"`
@@ -74,19 +74,19 @@ func constructScript(command string, shell string, isHerokuishImage bool, hasEnt
// getPhaseScript extracts app.json from app image and returns the appropriate json key/value
func getPhaseScript(appName string, image string, phase string) (string, error) {
appJsonFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "getPhaseScript"))
appJSONFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "getPhaseScript"))
if err != nil {
return "", fmt.Errorf("Cannot create temporary file: %v", err)
}
defer os.Remove(appJsonFile.Name())
defer os.Remove(appJSONFile.Name())
common.CopyFromImage(appName, image, "app.json", appJsonFile.Name())
if !common.FileExists(appJsonFile.Name()) {
common.CopyFromImage(appName, image, "app.json", appJSONFile.Name())
if !common.FileExists(appJSONFile.Name()) {
return "", nil
}
b, err := ioutil.ReadFile(appJsonFile.Name())
b, err := ioutil.ReadFile(appJSONFile.Name())
if err != nil {
return "", fmt.Errorf("Cannot read app.json file: %v", err)
}
@@ -95,16 +95,16 @@ func getPhaseScript(appName string, image string, phase string) (string, error)
return "", nil
}
var appJson AppJson
if err = json.Unmarshal(b, &appJson); err != nil {
var appJSON AppJSON
if err = json.Unmarshal(b, &appJSON); err != nil {
return "", fmt.Errorf("Cannot parse app.json: %v", err)
}
if phase == "predeploy" {
return appJson.Scripts.Dokku.Predeploy, nil
return appJSON.Scripts.Dokku.Predeploy, nil
}
return appJson.Scripts.Dokku.Postdeploy, nil
return appJSON.Scripts.Dokku.Postdeploy, nil
}
// getReleaseCommand extracts the release command from a given app's procfile

View File

@@ -1,5 +1,6 @@
package appjson
// TriggerPostDeploy is a trigger to execute the postdeploy deployment task
func TriggerPostDeploy(appName string, imageTag string) error {
if err := executeScript(appName, imageTag, "postdeploy"); err != nil {
return err
@@ -7,6 +8,7 @@ func TriggerPostDeploy(appName string, imageTag string) error {
return nil
}
// TriggerPreDeploy is a trigger to execute predeploy and release deployment tasks
func TriggerPreDeploy(appName string, imageTag string) error {
if err := executeScript(appName, imageTag, "predeploy"); err != nil {
return err

View File

@@ -38,7 +38,7 @@ func NewShellCmd(command string) *ShellCmd {
return NewShellCmdWithArgs(cmd, args...)
}
// NewShellCmd returns a new ShellCmd struct
// NewShellCmdWithArgs returns a new ShellCmd struct
func NewShellCmdWithArgs(cmd string, args ...string) *ShellCmd {
commandString := strings.Join(append([]string{cmd}, args...), " ")
@@ -50,7 +50,7 @@ func NewShellCmdWithArgs(cmd string, args ...string) *ShellCmd {
}
}
func (sc *ShellCmd) Setup() {
func (sc *ShellCmd) setup() {
env := os.Environ()
for k, v := range sc.Env {
env = append(env, fmt.Sprintf("%s=%s", k, v))
@@ -64,7 +64,7 @@ func (sc *ShellCmd) Setup() {
// Execute is a lightweight wrapper around exec.Command
func (sc *ShellCmd) Execute() bool {
sc.Setup()
sc.setup()
if err := sc.Command.Run(); err != nil {
return false
@@ -74,13 +74,13 @@ func (sc *ShellCmd) Execute() bool {
// Output is a lightweight wrapper around exec.Command.Output()
func (sc *ShellCmd) Output() ([]byte, error) {
sc.Setup()
sc.setup()
return sc.Command.Output()
}
// CombinedOutput is a lightweight wrapper around exec.Command.CombinedOutput()
func (sc *ShellCmd) CombinedOutput() ([]byte, error) {
sc.Setup()
sc.setup()
return sc.Command.CombinedOutput()
}
@@ -90,7 +90,7 @@ func AppRoot(appName string) string {
return fmt.Sprintf("%v/%v", dokkuRoot, appName)
}
// AppRoot returns the app root path
// AppHostRoot returns the app root path
func AppHostRoot(appName string) string {
dokkuHostRoot := MustGetEnv("DOKKU_HOST_ROOT")
return fmt.Sprintf("%v/%v", dokkuHostRoot, appName)
@@ -920,31 +920,3 @@ func pruneUnusedImages(appName string) {
pruneCmd.Command.Stderr = &stderr
pruneCmd.Execute()
}
func ConfigGet(appName string, key string, defaultValue string) (string, error) {
b, err := PlugnTriggerOutput("config-get", []string{appName, key}...)
if err != nil {
return defaultValue, err
}
value := defaultValue
if string(b[:]) != "" {
value = string(b[:])
}
return value, nil
}
func ConfigGetGlobal(key string, defaultValue string) (string, error) {
b, err := PlugnTriggerOutput("config-get-global", []string{key}...)
if err != nil {
return defaultValue, err
}
value := defaultValue
if string(b[:]) != "" {
value = string(b[:])
}
return value, nil
}