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.
106 lines
2.4 KiB
Go
106 lines
2.4 KiB
Go
package dockeroptions
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// CommandAdd adds a docker option to the specified phases for an app
|
|
func CommandAdd(appName string, phasesArg string, option string) error {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
|
|
phases, err := parsePhases(phasesArg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if option == "" {
|
|
return errors.New("Please specify docker options to add to the phase")
|
|
}
|
|
|
|
return AddDockerOptionToPhases(appName, phases, option)
|
|
}
|
|
|
|
// CommandRemove removes a docker option from the specified phases for an app
|
|
func CommandRemove(appName string, phasesArg string, option string) error {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
|
|
phases, err := parsePhases(phasesArg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if option == "" {
|
|
return errors.New("Please specify docker options to remove from the phase")
|
|
}
|
|
|
|
return RemoveDockerOptionFromPhases(appName, phases, option)
|
|
}
|
|
|
|
// CommandClear removes all docker options for an app, optionally limited to a list of phases
|
|
func CommandClear(appName string, phasesArg string) error {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
|
|
if phasesArg == "" {
|
|
common.LogInfo1(fmt.Sprintf("Clearing docker-options for %s on all phases", appName))
|
|
for _, phase := range availablePhases {
|
|
if err := removePhaseFile(appName, phase); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
phases, err := parsePhases(phasesArg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, phase := range phases {
|
|
common.LogInfo1(fmt.Sprintf("Clearing docker-options for %s on phase %s", appName, phase))
|
|
if err := removePhaseFile(appName, phase); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CommandReport displays a docker-options report for one or more apps
|
|
func CommandReport(appName string, format string, infoFlag string) error {
|
|
if appName == "" {
|
|
apps, err := common.DokkuApps()
|
|
if err != nil {
|
|
if errors.Is(err, common.NoAppsExist) {
|
|
common.LogWarn(err.Error())
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
for _, name := range apps {
|
|
if err := ReportSingleApp(name, format, infoFlag); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
return ReportSingleApp(appName, format, infoFlag)
|
|
}
|
|
|
|
func removePhaseFile(appName string, phase string) error {
|
|
if err := os.Remove(getPhaseFilePath(appName, phase)); err != nil && !os.IsNotExist(err) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|