这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions plugins/ps/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,35 @@ func canScaleApp(appName string) bool {
return common.ToBool(canScale)
}

func getProcfileCommand(procfilePath string, processType string, port int) (string, error) {
func getProcfileCommand(appName string, procfilePath string, processType string, port int) (string, error) {
if !common.FileExists(procfilePath) {
return "", errors.New("No procfile found")
}

configResult, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "config-export",
Args: []string{appName, "false", "true", "envfile"},
})
if err != nil {
return "", err
}

// write the envfile to a temporary file
tempFile, err := os.CreateTemp("", "envfile-*.env")
if err != nil {
return "", err
}
defer os.Remove(tempFile.Name())
if _, err := tempFile.Write(configResult.StdoutBytes()); err != nil {
return "", err
}
if err := tempFile.Close(); err != nil {
return "", err
}

result, err := common.CallExecCommand(common.ExecCommandInput{
Command: "procfile-util",
Args: []string{"show", "--procfile", procfilePath, "--process-type", processType, "--default-port", strconv.Itoa(port)},
Args: []string{"show", "--procfile", procfilePath, "--process-type", processType, "--default-port", strconv.Itoa(port), "--env-file", tempFile.Name()},
})
if err != nil {
return "", fmt.Errorf("Error running procfile-util: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion plugins/ps/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func TriggerProcfileGetCommand(appName string, processType string, port int) err
return nil
}

command, err := getProcfileCommand(getProcessSpecificProcfilePath(appName), processType, port)
command, err := getProcfileCommand(appName, getProcessSpecificProcfilePath(appName), processType, port)
if err != nil {
return err
}
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/ps-general-1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,28 @@ teardown() {
cat <<EOF >"$DOKKU_LIB_ROOT/data/ps/$TEST_APP/Procfile"
web: node web.js --port \$PORT
worker: node worker.js
release: interpolated \$ENV_VAR
EOF
PLUGIN_PATH=/var/lib/dokku/plugins PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available DOKKU_LIB_ROOT=/var/lib/dokku run plugn trigger procfile-get-command "$TEST_APP" web 5001

run /bin/bash -c "dokku config:set '$TEST_APP' ENV_VAR=value"
echo "output: $output"
echo "status: $status"
assert_success

run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' web 5001"
echo "output: $output"
echo "status: $status"
assert_output "node web.js --port 5001"

PLUGIN_PATH=/var/lib/dokku/plugins PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available DOKKU_LIB_ROOT=/var/lib/dokku run plugn trigger procfile-get-command "$TEST_APP" worker
run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' worker"
echo "output: $output"
echo "status: $status"
assert_output "node worker.js"

run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' release 5001"
echo "output: $output"
echo "status: $status"
assert_output "interpolated value"
}

@test "(ps:scale) update formations from Procfile" {
Expand Down
Loading