refactor: migrate docker-options subcommands to go
Ports the user-facing CLI subcommands and lifecycle triggers from bash to go, mirroring the layout used by the ports plugin. The on-disk format (`DOCKER_OPTIONS_BUILD/DEPLOY/RUN` files), the `docker-args-build/deploy/run` triggers, and every exported helper consumed by other plugins are unchanged. Reserves the `--process` and `--global` flags on add, remove, and clear so usage today exits with a not-yet-implemented error and the surface is locked in ahead of the process-scoping work tracked in #2441.
This commit is contained in:
65
plugins/docker-options/triggers.go
Normal file
65
plugins/docker-options/triggers.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package dockeroptions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// TriggerPostAppCloneSetup copies docker option files from the source app to the cloned app
|
||||
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
||||
for _, phase := range availablePhases {
|
||||
if err := copyPhaseFile(oldAppName, newAppName, phase); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostAppRenameSetup copies docker option files from the old app name to the new app name
|
||||
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
for _, phase := range availablePhases {
|
||||
if err := copyPhaseFile(oldAppName, newAppName, phase); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostDelete deletes the docker option files for an app
|
||||
func TriggerPostDelete(appName string) error {
|
||||
for _, phase := range availablePhases {
|
||||
if err := removePhaseFile(appName, phase); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyPhaseFile(srcApp string, dstApp string, phase string) error {
|
||||
srcPath := getPhaseFilePath(srcApp, phase)
|
||||
if !common.FileExists(srcPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
src, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to open docker options phase file %s.%s: %s", srcApp, phase, err.Error())
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dstPath := getPhaseFilePath(dstApp, phase)
|
||||
dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to create docker options phase file %s.%s: %s", dstApp, phase, err.Error())
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
return fmt.Errorf("Unable to copy docker options phase file %s.%s to %s.%s: %s", srcApp, phase, dstApp, phase, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user