refactor: decrease compile time for golang plugins
This change refactors the compiled golang plugins into 3 distinct binaries: - commands: already existing - subcommands/subcommands: entrypoint into all subcommands - triggers: entrypoint into all triggers It then further symlinks triggers and subcommands to the built binaries. This results in both a much faster build process as well as smaller package size.
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := flag.NewFlagSet("resource:limit-clear", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to clear")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
err := resource.CommandLimitClear(args.Args(), *processType)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := flag.NewFlagSet("resource:limit", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to manage")
|
||||
cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by")
|
||||
memory := args.String("memory", "", "memory: The amount of memory to limit processes by")
|
||||
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by")
|
||||
network := args.String("network", "", "network: The amount of network bandwidth to limit processes by")
|
||||
networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to limit processes by")
|
||||
networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to limit processes by")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
resources := resource.Resource{
|
||||
CPU: *cpu,
|
||||
Memory: *memory,
|
||||
MemorySwap: *memorySwap,
|
||||
Network: *network,
|
||||
NetworkIngress: *networkIngress,
|
||||
NetworkEgress: *networkEgress,
|
||||
}
|
||||
|
||||
err := resource.CommandLimit(args.Args(), *processType, resources)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
// displays a resource report for one or more apps
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
infoFlag := flag.Arg(2)
|
||||
|
||||
if strings.HasPrefix(appName, "--") {
|
||||
common.LogFail("The resource:report command does not support flags without an app name")
|
||||
}
|
||||
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, appName := range apps {
|
||||
resource.ReportSingleApp(appName, infoFlag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resource.ReportSingleApp(appName, infoFlag)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := flag.NewFlagSet("resource:reserve-clear", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to clear")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
err := resource.CommandReserveClear(args.Args(), *processType)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := flag.NewFlagSet("resource:reserve", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to manage")
|
||||
cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes")
|
||||
memory := args.String("memory", "", "memory: The amount of memory to reserve for processes")
|
||||
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes")
|
||||
network := args.String("network", "", "network: The amount of network bandwidth to reserve for processes")
|
||||
networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to reserve for processes")
|
||||
networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to reserve for processes")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
resources := resource.Resource{
|
||||
CPU: *cpu,
|
||||
Memory: *memory,
|
||||
MemorySwap: *memorySwap,
|
||||
Network: *network,
|
||||
NetworkIngress: *networkIngress,
|
||||
NetworkEgress: *networkEgress,
|
||||
}
|
||||
|
||||
err := resource.CommandReserve(args.Args(), *processType, resources)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
84
plugins/resource/src/subcommands/subcommands.go
Normal file
84
plugins/resource/src/subcommands/subcommands.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
// main entrypoint to all subcommands
|
||||
func main() {
|
||||
parts := strings.Split(os.Args[0], "/")
|
||||
subcommand := parts[len(parts)-1]
|
||||
|
||||
var err error
|
||||
switch subcommand {
|
||||
case "limit":
|
||||
args := flag.NewFlagSet("resource:limit", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to manage")
|
||||
cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by")
|
||||
memory := args.String("memory", "", "memory: The amount of memory to limit processes by")
|
||||
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by")
|
||||
network := args.String("network", "", "network: The amount of network bandwidth to limit processes by")
|
||||
networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to limit processes by")
|
||||
networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to limit processes by")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
resources := resource.Resource{
|
||||
CPU: *cpu,
|
||||
Memory: *memory,
|
||||
MemorySwap: *memorySwap,
|
||||
Network: *network,
|
||||
NetworkIngress: *networkIngress,
|
||||
NetworkEgress: *networkEgress,
|
||||
}
|
||||
|
||||
err = resource.CommandLimit(args.Args(), *processType, resources)
|
||||
case "limit-clear":
|
||||
args := flag.NewFlagSet("resource:limit-clear", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to clear")
|
||||
args.Parse(os.Args[2:])
|
||||
err = resource.CommandLimitClear(args.Args(), *processType)
|
||||
case "report":
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
infoFlag := flag.Arg(2)
|
||||
resource.CommandReport(appName, infoFlag)
|
||||
case "reserve":
|
||||
args := flag.NewFlagSet("resource:reserve", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to manage")
|
||||
cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes")
|
||||
memory := args.String("memory", "", "memory: The amount of memory to reserve for processes")
|
||||
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes")
|
||||
network := args.String("network", "", "network: The amount of network bandwidth to reserve for processes")
|
||||
networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to reserve for processes")
|
||||
networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to reserve for processes")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
resources := resource.Resource{
|
||||
CPU: *cpu,
|
||||
Memory: *memory,
|
||||
MemorySwap: *memorySwap,
|
||||
Network: *network,
|
||||
NetworkIngress: *networkIngress,
|
||||
NetworkEgress: *networkEgress,
|
||||
}
|
||||
|
||||
err = resource.CommandReserve(args.Args(), *processType, resources)
|
||||
case "reserve-clear":
|
||||
args := flag.NewFlagSet("resource:reserve-clear", flag.ExitOnError)
|
||||
processType := args.String("process-type", "", "process-type: A process type to clear")
|
||||
args.Parse(os.Args[2:])
|
||||
err = resource.CommandReserveClear(args.Args(), *processType)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// outputs the process-specific docker options
|
||||
func main() {
|
||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(3)
|
||||
|
||||
if os.Getenv("DOKKU_OMIT_RESOURCE_ARGS") == "1" {
|
||||
fmt.Print(string(stdin))
|
||||
return
|
||||
}
|
||||
|
||||
resources, err := common.PropertyGetAll("resource", appName)
|
||||
if err != nil {
|
||||
fmt.Print(string(stdin))
|
||||
return
|
||||
}
|
||||
|
||||
limits := make(map[string]string)
|
||||
reservations := make(map[string]string)
|
||||
|
||||
validLimits := map[string]bool{
|
||||
"cpu": true,
|
||||
"memory": true,
|
||||
"memory-swap": true,
|
||||
}
|
||||
validReservations := map[string]bool{
|
||||
"memory": true,
|
||||
}
|
||||
validPrefixes := []string{"_default_.", fmt.Sprintf("%s.", processType)}
|
||||
for _, validPrefix := range validPrefixes {
|
||||
for key, value := range resources {
|
||||
if !strings.HasPrefix(key, validPrefix) {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(key, validPrefix), ".", 2)
|
||||
if parts[0] == "limit" {
|
||||
if !validLimits[parts[1]] {
|
||||
continue
|
||||
}
|
||||
|
||||
if parts[1] == "cpu" {
|
||||
parts[1] = "cpus"
|
||||
}
|
||||
|
||||
limits[parts[1]] = value
|
||||
}
|
||||
if parts[0] == "reserve" {
|
||||
if !validReservations[parts[1]] {
|
||||
continue
|
||||
}
|
||||
|
||||
reservations[parts[1]] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, value := range limits {
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Printf(" --%s=%s ", key, value)
|
||||
}
|
||||
|
||||
for key, value := range reservations {
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Printf(" --%s-reservation=%s ", key, value)
|
||||
}
|
||||
|
||||
fmt.Print(string(stdin))
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// runs the install step for the resource plugin
|
||||
func main() {
|
||||
if err := common.PropertySetup("resource"); err != nil {
|
||||
common.LogFail(fmt.Sprintf("Unable to install the resource plugin: %s", err.Error()))
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// destroys the resource property for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
err := common.PropertyDestroy("resource", appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
// displays a resource report for one or more apps
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
resource.ReportSingleApp(appName, "")
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
// writes the resource key to stdout for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
resourceType := flag.Arg(2)
|
||||
key := flag.Arg(3)
|
||||
|
||||
value, err := resource.GetResourceValue(appName, processType, resourceType, key)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stdout, value)
|
||||
}
|
||||
46
plugins/resource/src/triggers/triggers.go
Normal file
46
plugins/resource/src/triggers/triggers.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/resource"
|
||||
)
|
||||
|
||||
// main entrypoint to all triggers
|
||||
func main() {
|
||||
parts := strings.Split(os.Args[0], "/")
|
||||
trigger := parts[len(parts)-1]
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "docker-args-process-deploy":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(3)
|
||||
err = resource.TriggerDockerArgsProcessDeploy(appName, processType)
|
||||
case "install":
|
||||
err = resource.TriggerInstall()
|
||||
case "post-delete":
|
||||
appName := flag.Arg(0)
|
||||
err = resource.TriggerPostDelete(appName)
|
||||
case "report":
|
||||
appName := flag.Arg(0)
|
||||
resource.ReportSingleApp(appName, "")
|
||||
case "resource-get-property":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
resourceType := flag.Arg(2)
|
||||
key := flag.Arg(3)
|
||||
err = resource.TriggerResourceGetProperty(appName, processType, resourceType, key)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user