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:
2
plugins/repo/.gitignore
vendored
2
plugins/repo/.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
/commands
|
||||
/subcommands/*
|
||||
/triggers/*
|
||||
/triggers
|
||||
|
||||
@@ -1,37 +1,6 @@
|
||||
include ../../common.mk
|
||||
|
||||
GO_ARGS ?= -a
|
||||
|
||||
SUBCOMMANDS = subcommands/gc subcommands/purge-cache
|
||||
TRIGGERS = triggers/pre-delete
|
||||
build-in-docker: clean
|
||||
docker run --rm \
|
||||
-v $$PWD/../..:$(GO_REPO_ROOT) \
|
||||
-w $(GO_REPO_ROOT)/plugins/repo \
|
||||
$(BUILD_IMAGE) \
|
||||
bash -c "GO_ARGS='$(GO_ARGS)' make -j4 build" || exit $$?
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = repo
|
||||
|
||||
build: commands subcommands triggers
|
||||
$(MAKE) triggers-copy
|
||||
|
||||
commands: **/**/commands.go
|
||||
go build $(GO_ARGS) -o commands src/commands/commands.go
|
||||
|
||||
subcommands: $(SUBCOMMANDS)
|
||||
|
||||
subcommands/%: src/subcommands/*/%.go
|
||||
go build $(GO_ARGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf commands subcommands triggers pre-delete
|
||||
|
||||
src-clean:
|
||||
rm -rf .gitignore src triggers vendor Makefile *.go glide.*
|
||||
|
||||
triggers: $(TRIGGERS)
|
||||
|
||||
triggers/%: src/triggers/*/%.go
|
||||
go build $(GO_ARGS) -o $@ $<
|
||||
|
||||
triggers-copy:
|
||||
cp triggers/* .
|
||||
include ../../common.mk
|
||||
|
||||
1
plugins/repo/pre-delete
Symbolic link
1
plugins/repo/pre-delete
Symbolic link
@@ -0,0 +1 @@
|
||||
triggers
|
||||
@@ -1,22 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// deletes the contents of the build cache stored in the repository
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
}
|
||||
|
||||
err := repo.PurgeCache(appName)
|
||||
if err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
35
plugins/repo/src/subcommands/subcommands.go
Normal file
35
plugins/repo/src/subcommands/subcommands.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// main entrypoint to all subcommands
|
||||
func main() {
|
||||
parts := strings.Split(os.Args[0], "/")
|
||||
subcommand := parts[len(parts)-1]
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
switch subcommand {
|
||||
case "gc":
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
err = repo.CommandGc(appName)
|
||||
case "purge-cache":
|
||||
appName := flag.Arg(1)
|
||||
err = repo.CommandPurgeCache(appName)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// destroys the buildpacks property for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
err := repo.PurgeCache(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
31
plugins/repo/src/triggers/triggers.go
Normal file
31
plugins/repo/src/triggers/triggers.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// 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 "pre-delete":
|
||||
appName := flag.Arg(0)
|
||||
err = repo.PurgeCache(appName)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,20 @@
|
||||
package main
|
||||
package repo
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// runs 'git gc --aggressive' against the application's repo
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
// CommandGc runs 'git gc --aggressive' against the application's repo
|
||||
func CommandGc(appName string) error {
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
return errors.New("Please specify an app to run the command on")
|
||||
}
|
||||
err := common.VerifyAppName(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
||||
@@ -26,4 +24,14 @@ func main() {
|
||||
gitGcCmd := common.NewShellCmd("git gc --aggressive")
|
||||
gitGcCmd.Env = cmdEnv
|
||||
gitGcCmd.Execute()
|
||||
return nil
|
||||
}
|
||||
|
||||
// CommandPurgeCache deletes the contents of the build cache stored in the repository
|
||||
func CommandPurgeCache(appName string) error {
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
}
|
||||
|
||||
return PurgeCache(appName)
|
||||
}
|
||||
Reference in New Issue
Block a user