fix: correct stickler-ci errors and remove unused code
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
|||||||
shellquote "github.com/kballard/go-shellquote"
|
shellquote "github.com/kballard/go-shellquote"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppJson struct {
|
type AppJSON struct {
|
||||||
Scripts struct {
|
Scripts struct {
|
||||||
Dokku struct {
|
Dokku struct {
|
||||||
Predeploy string `json:"predeploy"`
|
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
|
// getPhaseScript extracts app.json from app image and returns the appropriate json key/value
|
||||||
func getPhaseScript(appName string, image string, phase string) (string, error) {
|
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 {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Cannot create temporary file: %v", err)
|
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())
|
common.CopyFromImage(appName, image, "app.json", appJSONFile.Name())
|
||||||
if !common.FileExists(appJsonFile.Name()) {
|
if !common.FileExists(appJSONFile.Name()) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(appJsonFile.Name())
|
b, err := ioutil.ReadFile(appJSONFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Cannot read app.json file: %v", err)
|
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
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var appJson AppJson
|
var appJSON AppJSON
|
||||||
if err = json.Unmarshal(b, &appJson); err != nil {
|
if err = json.Unmarshal(b, &appJSON); err != nil {
|
||||||
return "", fmt.Errorf("Cannot parse app.json: %v", err)
|
return "", fmt.Errorf("Cannot parse app.json: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if phase == "predeploy" {
|
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
|
// getReleaseCommand extracts the release command from a given app's procfile
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package appjson
|
package appjson
|
||||||
|
|
||||||
|
// TriggerPostDeploy is a trigger to execute the postdeploy deployment task
|
||||||
func TriggerPostDeploy(appName string, imageTag string) error {
|
func TriggerPostDeploy(appName string, imageTag string) error {
|
||||||
if err := executeScript(appName, imageTag, "postdeploy"); err != nil {
|
if err := executeScript(appName, imageTag, "postdeploy"); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -7,6 +8,7 @@ func TriggerPostDeploy(appName string, imageTag string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TriggerPreDeploy is a trigger to execute predeploy and release deployment tasks
|
||||||
func TriggerPreDeploy(appName string, imageTag string) error {
|
func TriggerPreDeploy(appName string, imageTag string) error {
|
||||||
if err := executeScript(appName, imageTag, "predeploy"); err != nil {
|
if err := executeScript(appName, imageTag, "predeploy"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func NewShellCmd(command string) *ShellCmd {
|
|||||||
return NewShellCmdWithArgs(cmd, args...)
|
return NewShellCmdWithArgs(cmd, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewShellCmd returns a new ShellCmd struct
|
// NewShellCmdWithArgs returns a new ShellCmd struct
|
||||||
func NewShellCmdWithArgs(cmd string, args ...string) *ShellCmd {
|
func NewShellCmdWithArgs(cmd string, args ...string) *ShellCmd {
|
||||||
commandString := strings.Join(append([]string{cmd}, args...), " ")
|
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()
|
env := os.Environ()
|
||||||
for k, v := range sc.Env {
|
for k, v := range sc.Env {
|
||||||
env = append(env, fmt.Sprintf("%s=%s", k, v))
|
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
|
// Execute is a lightweight wrapper around exec.Command
|
||||||
func (sc *ShellCmd) Execute() bool {
|
func (sc *ShellCmd) Execute() bool {
|
||||||
sc.Setup()
|
sc.setup()
|
||||||
|
|
||||||
if err := sc.Command.Run(); err != nil {
|
if err := sc.Command.Run(); err != nil {
|
||||||
return false
|
return false
|
||||||
@@ -74,13 +74,13 @@ func (sc *ShellCmd) Execute() bool {
|
|||||||
|
|
||||||
// Output is a lightweight wrapper around exec.Command.Output()
|
// Output is a lightweight wrapper around exec.Command.Output()
|
||||||
func (sc *ShellCmd) Output() ([]byte, error) {
|
func (sc *ShellCmd) Output() ([]byte, error) {
|
||||||
sc.Setup()
|
sc.setup()
|
||||||
return sc.Command.Output()
|
return sc.Command.Output()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CombinedOutput is a lightweight wrapper around exec.Command.CombinedOutput()
|
// CombinedOutput is a lightweight wrapper around exec.Command.CombinedOutput()
|
||||||
func (sc *ShellCmd) CombinedOutput() ([]byte, error) {
|
func (sc *ShellCmd) CombinedOutput() ([]byte, error) {
|
||||||
sc.Setup()
|
sc.setup()
|
||||||
return sc.Command.CombinedOutput()
|
return sc.Command.CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func AppRoot(appName string) string {
|
|||||||
return fmt.Sprintf("%v/%v", dokkuRoot, appName)
|
return fmt.Sprintf("%v/%v", dokkuRoot, appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppRoot returns the app root path
|
// AppHostRoot returns the app root path
|
||||||
func AppHostRoot(appName string) string {
|
func AppHostRoot(appName string) string {
|
||||||
dokkuHostRoot := MustGetEnv("DOKKU_HOST_ROOT")
|
dokkuHostRoot := MustGetEnv("DOKKU_HOST_ROOT")
|
||||||
return fmt.Sprintf("%v/%v", dokkuHostRoot, appName)
|
return fmt.Sprintf("%v/%v", dokkuHostRoot, appName)
|
||||||
@@ -920,31 +920,3 @@ func pruneUnusedImages(appName string) {
|
|||||||
pruneCmd.Command.Stderr = &stderr
|
pruneCmd.Command.Stderr = &stderr
|
||||||
pruneCmd.Execute()
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user