Merge pull request #4419 from dokku/4392-proxy-parallelism
Add parallelism to certain proxy commands
This commit is contained in:
6 files changed
+292
-224
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
# 0.23.0 Migration Guide
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- The commands `proxy:enable`, `proxy:disable` and `proxy:build-config` now support the `--all` flag in addition to general parallelism.
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
> New as of 0.5.0, Enhanced in 0.6.0
|
> New as of 0.5.0, Enhanced in 0.6.0
|
||||||
|
|
||||||
```
|
```
|
||||||
proxy:build-config <app> # (Re)builds config for given app
|
proxy:build-config [--parallel count] [--all|<app>] # (Re)builds config for given app
|
||||||
proxy:disable <app> # Disable proxy for app
|
proxy:disable [--parallel count] [--all|<app>] # Disable proxy for app
|
||||||
proxy:enable <app> # Enable proxy for app
|
proxy:enable [--parallel count] [--all|<app>] # Enable proxy for app
|
||||||
proxy:report [<app>] [<flag>] # Displays a proxy report for one or more apps
|
proxy:report [<app>] [<flag>] # Displays a proxy report for one or more apps
|
||||||
proxy:set <app> <proxy-type> # Set proxy type for app
|
proxy:set <app> <proxy-type> # Set proxy type for app
|
||||||
```
|
```
|
||||||
|
|
||||||
In Dokku 0.5.0, port proxying was decoupled from the `nginx-vhosts` plugin into the proxy plugin. Dokku 0.6.0 introduced the ability to map host ports to specific container ports. In the future this will allow other proxy software - such as HAProxy or Caddy - to be used in place of nginx.
|
In Dokku 0.5.0, port proxying was decoupled from the `nginx-vhosts` plugin into the proxy plugin. Dokku 0.6.0 introduced the ability to map host ports to specific container ports. In the future this will allow other proxy software - such as HAProxy or Caddy - to be used in place of nginx.
|
||||||
@@ -22,11 +22,23 @@ In certain cases, your app proxy configs may drift from the correct config for y
|
|||||||
dokku proxy:build-config node-js-app
|
dokku proxy:build-config node-js-app
|
||||||
```
|
```
|
||||||
|
|
||||||
### Container network interface binding
|
All apps may have their proxy config rebuilt by using the `--all` flag.
|
||||||
|
|
||||||
> Changed as of 0.11.0
|
```shell
|
||||||
|
dokku proxy:build-config --all
|
||||||
|
```
|
||||||
|
|
||||||
From Dokku versions `0.5.0` until `0.11.0`, enabling or disabling an application's proxy would **also** control whether or not the application was bound to all interfaces - e.g. `0.0.0.0`. As of `0.11.0`, this is now controlled by the network plugin. Please see the [network documentation](/docs/networking/network.md#container-network-interface-binding) for more information.
|
By default, rebuilding proxy configs for all apps happens serially. The parallelism may be controlled by the `--parallel` flag.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku proxy:build-config --all --parallel 2
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, the number of parallel workers may be automatically set to the number of CPUs available by setting the `--parallel` flag to `-1`
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku proxy:build-config --all --parallel -1
|
||||||
|
```
|
||||||
|
|
||||||
### Displaying proxy reports for an app
|
### Displaying proxy reports for an app
|
||||||
|
|
||||||
@@ -94,3 +106,9 @@ dokku proxy:set node-js-app nginx
|
|||||||
### Proxy port mapping
|
### Proxy port mapping
|
||||||
|
|
||||||
See the [port management documentation](/docs/networking/port-management.md) for more information on how port mappings are managed for an application.
|
See the [port management documentation](/docs/networking/port-management.md) for more information on how port mappings are managed for an application.
|
||||||
|
|
||||||
|
### Container network interface binding
|
||||||
|
|
||||||
|
> Changed as of 0.11.0
|
||||||
|
|
||||||
|
From Dokku versions `0.5.0` until `0.11.0`, enabling or disabling an application's proxy would **also** control whether or not the application was bound to all interfaces - e.g. `0.0.0.0`. As of `0.11.0`, this is now controlled by the network plugin. Please see the [network documentation](/docs/networking/network.md#container-network-interface-binding) for more information.
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/dokku/dokku/plugins/common"
|
||||||
|
"github.com/dokku/dokku/plugins/config"
|
||||||
|
"github.com/ryanuber/columnize"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addProxyPorts(appName string, proxyPortMap []PortMap) error {
|
||||||
|
allPortMaps := getProxyPortMap(appName)
|
||||||
|
allPortMaps = append(allPortMaps, proxyPortMap...)
|
||||||
|
|
||||||
|
return setProxyPorts(appName, allPortMaps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterAppProxyPorts(appName string, scheme string, hostPort int) []PortMap {
|
||||||
|
var filteredProxyMaps []PortMap
|
||||||
|
for _, portMap := range getProxyPortMap(appName) {
|
||||||
|
if portMap.Scheme == scheme && portMap.HostPort == hostPort {
|
||||||
|
filteredProxyMaps = append(filteredProxyMaps, portMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredProxyMaps
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAppProxyType(appName string) string {
|
||||||
|
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "nginx")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getProxyPortMap(appName string) []PortMap {
|
||||||
|
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
|
||||||
|
portMaps, _ := parseProxyPortMapString(value)
|
||||||
|
return portMaps
|
||||||
|
}
|
||||||
|
|
||||||
|
func inRange(value int, min int, max int) bool {
|
||||||
|
return min < value && value < max
|
||||||
|
}
|
||||||
|
|
||||||
|
func listAppProxyPorts(appName string) error {
|
||||||
|
proxyPortMap := getProxyPortMap(appName)
|
||||||
|
|
||||||
|
if len(proxyPortMap) == 0 {
|
||||||
|
return errors.New("No port mappings configured for app")
|
||||||
|
}
|
||||||
|
|
||||||
|
var lines []string
|
||||||
|
if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
|
||||||
|
lines = append(lines, "-----> scheme:host port:container port")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, portMap := range proxyPortMap {
|
||||||
|
lines = append(lines, portMap.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(lines)
|
||||||
|
common.LogInfo1Quiet(fmt.Sprintf("Port mappings for %s", appName))
|
||||||
|
config := columnize.DefaultConfig()
|
||||||
|
config.Delim = ":"
|
||||||
|
config.Prefix = " "
|
||||||
|
config.Empty = ""
|
||||||
|
fmt.Println(columnize.Format(lines, config))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseProxyPortMapString(stringPortMap string) ([]PortMap, error) {
|
||||||
|
var proxyPortMap []PortMap
|
||||||
|
|
||||||
|
for _, v := range strings.Split(strings.TrimSpace(stringPortMap), " ") {
|
||||||
|
parts := strings.SplitN(v, ":", 3)
|
||||||
|
if len(parts) == 1 {
|
||||||
|
hostPort, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !inRange(hostPort, 0, 65536) {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyPortMap = append(proxyPortMap, PortMap{
|
||||||
|
HostPort: hostPort,
|
||||||
|
Scheme: "__internal__",
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(parts) != 3 {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [len=%d]", v, len(parts))
|
||||||
|
}
|
||||||
|
|
||||||
|
hostPort, err := strconv.Atoi(parts[1])
|
||||||
|
if err != nil {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
containerPort, err := strconv.Atoi(parts[2])
|
||||||
|
if err != nil {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !inRange(hostPort, 0, 65536) {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !inRange(containerPort, 0, 65536) {
|
||||||
|
return proxyPortMap, fmt.Errorf("Invalid port map %s [containerPort=%d]", v, containerPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyPortMap = append(proxyPortMap, PortMap{
|
||||||
|
ContainerPort: containerPort,
|
||||||
|
HostPort: hostPort,
|
||||||
|
Scheme: parts[0],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return uniqueProxyPortMap(proxyPortMap), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeProxyPorts(appName string, proxyPortMap []PortMap) error {
|
||||||
|
toRemove := map[string]bool{}
|
||||||
|
toRemoveByPort := map[int]bool{}
|
||||||
|
|
||||||
|
for _, portMap := range proxyPortMap {
|
||||||
|
if portMap.AllowsPersistence() {
|
||||||
|
toRemoveByPort[portMap.HostPort] = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
toRemove[portMap.String()] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var toSet []PortMap
|
||||||
|
for _, portMap := range getProxyPortMap(appName) {
|
||||||
|
if toRemove[portMap.String()] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if toRemoveByPort[portMap.HostPort] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
toSet = append(toSet, portMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(toSet) == 0 {
|
||||||
|
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
||||||
|
return config.UnsetMany(appName, keys, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return setProxyPorts(appName, toSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setProxyPorts(appName string, proxyPortMap []PortMap) error {
|
||||||
|
var value []string
|
||||||
|
for _, portMap := range uniqueProxyPortMap(proxyPortMap) {
|
||||||
|
if portMap.AllowsPersistence() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
value = append(value, portMap.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(value)
|
||||||
|
entries := map[string]string{
|
||||||
|
"DOKKU_PROXY_PORT_MAP": strings.Join(value, " "),
|
||||||
|
}
|
||||||
|
return config.SetMany(appName, entries, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func uniqueProxyPortMap(proxyPortMap []PortMap) []PortMap {
|
||||||
|
var unique []PortMap
|
||||||
|
existingPortMaps := map[string]bool{}
|
||||||
|
|
||||||
|
for _, portMap := range proxyPortMap {
|
||||||
|
if existingPortMaps[portMap.String()] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
existingPortMaps[portMap.String()] = true
|
||||||
|
unique = append(unique, portMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
return unique
|
||||||
|
}
|
||||||
+42
-182
@@ -1,18 +1,16 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
"github.com/dokku/dokku/plugins/config"
|
"github.com/dokku/dokku/plugins/config"
|
||||||
"github.com/ryanuber/columnize"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RunInSerial is the default value for whether to run a command in parallel or not
|
||||||
|
// and defaults to -1 (false)
|
||||||
|
const RunInSerial = 0
|
||||||
|
|
||||||
// PortMap is a struct that contains a scheme:host-port:container-port mapping
|
// PortMap is a struct that contains a scheme:host-port:container-port mapping
|
||||||
type PortMap struct {
|
type PortMap struct {
|
||||||
ContainerPort int
|
ContainerPort int
|
||||||
@@ -29,8 +27,44 @@ func (p PortMap) AllowsPersistence() bool {
|
|||||||
return p.Scheme == "__internal__"
|
return p.Scheme == "__internal__"
|
||||||
}
|
}
|
||||||
|
|
||||||
func inRange(value int, min int, max int) bool {
|
// BuildConfig rebuilds the proxy config for the specified app
|
||||||
return min < value && value < max
|
func BuildConfig(appName string) error {
|
||||||
|
return common.PlugnTrigger("proxy-build-config", []string{appName}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable disables proxy implementations for the specified app
|
||||||
|
func Disable(appName string) error {
|
||||||
|
if !IsAppProxyEnabled(appName) {
|
||||||
|
common.LogInfo1("Proxy is already disable for app")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
common.LogInfo1("Disabling proxy for app")
|
||||||
|
entries := map[string]string{
|
||||||
|
"DOKKU_DISABLE_PROXY": "1",
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := config.SetMany(appName, entries, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return common.PlugnTrigger("proxy-disable", []string{appName}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable enables proxy implementations for the specified app
|
||||||
|
func Enable(appName string) error {
|
||||||
|
if IsAppProxyEnabled(appName) {
|
||||||
|
common.LogInfo1("Proxy is already enabled for app")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
common.LogInfo1("Enabling proxy for app")
|
||||||
|
keys := []string{"DOKKU_DISABLE_PROXY"}
|
||||||
|
if err := config.UnsetMany(appName, keys, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return common.PlugnTrigger("proxy-enable", []string{appName}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAppProxyEnabled returns true if proxy is enabled; otherwise return false
|
// IsAppProxyEnabled returns true if proxy is enabled; otherwise return false
|
||||||
@@ -42,177 +76,3 @@ func IsAppProxyEnabled(appName string) bool {
|
|||||||
}
|
}
|
||||||
return proxyEnabled
|
return proxyEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func addProxyPorts(appName string, proxyPortMap []PortMap) error {
|
|
||||||
allPortMaps := getProxyPortMap(appName)
|
|
||||||
allPortMaps = append(allPortMaps, proxyPortMap...)
|
|
||||||
|
|
||||||
return setProxyPorts(appName, allPortMaps)
|
|
||||||
}
|
|
||||||
|
|
||||||
func filterAppProxyPorts(appName string, scheme string, hostPort int) []PortMap {
|
|
||||||
var filteredProxyMaps []PortMap
|
|
||||||
for _, portMap := range getProxyPortMap(appName) {
|
|
||||||
if portMap.Scheme == scheme && portMap.HostPort == hostPort {
|
|
||||||
filteredProxyMaps = append(filteredProxyMaps, portMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filteredProxyMaps
|
|
||||||
}
|
|
||||||
|
|
||||||
func getAppProxyType(appName string) string {
|
|
||||||
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "nginx")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getProxyPortMap(appName string) []PortMap {
|
|
||||||
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
|
|
||||||
portMaps, _ := parseProxyPortMapString(value)
|
|
||||||
return portMaps
|
|
||||||
}
|
|
||||||
|
|
||||||
func listAppProxyPorts(appName string) error {
|
|
||||||
proxyPortMap := getProxyPortMap(appName)
|
|
||||||
|
|
||||||
if len(proxyPortMap) == 0 {
|
|
||||||
return errors.New("No port mappings configured for app")
|
|
||||||
}
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
|
|
||||||
lines = append(lines, "-----> scheme:host port:container port")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, portMap := range proxyPortMap {
|
|
||||||
lines = append(lines, portMap.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(lines)
|
|
||||||
common.LogInfo1Quiet(fmt.Sprintf("Port mappings for %s", appName))
|
|
||||||
config := columnize.DefaultConfig()
|
|
||||||
config.Delim = ":"
|
|
||||||
config.Prefix = " "
|
|
||||||
config.Empty = ""
|
|
||||||
fmt.Println(columnize.Format(lines, config))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setProxyPorts(appName string, proxyPortMap []PortMap) error {
|
|
||||||
var value []string
|
|
||||||
for _, portMap := range uniqueProxyPortMap(proxyPortMap) {
|
|
||||||
if portMap.AllowsPersistence() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
value = append(value, portMap.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(value)
|
|
||||||
entries := map[string]string{
|
|
||||||
"DOKKU_PROXY_PORT_MAP": strings.Join(value, " "),
|
|
||||||
}
|
|
||||||
return config.SetMany(appName, entries, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeProxyPorts(appName string, proxyPortMap []PortMap) error {
|
|
||||||
toRemove := map[string]bool{}
|
|
||||||
toRemoveByPort := map[int]bool{}
|
|
||||||
|
|
||||||
for _, portMap := range proxyPortMap {
|
|
||||||
if portMap.AllowsPersistence() {
|
|
||||||
toRemoveByPort[portMap.HostPort] = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
toRemove[portMap.String()] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var toSet []PortMap
|
|
||||||
for _, portMap := range getProxyPortMap(appName) {
|
|
||||||
if toRemove[portMap.String()] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if toRemoveByPort[portMap.HostPort] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
toSet = append(toSet, portMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(toSet) == 0 {
|
|
||||||
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
|
||||||
return config.UnsetMany(appName, keys, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return setProxyPorts(appName, toSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseProxyPortMapString(stringPortMap string) ([]PortMap, error) {
|
|
||||||
var proxyPortMap []PortMap
|
|
||||||
|
|
||||||
for _, v := range strings.Split(strings.TrimSpace(stringPortMap), " ") {
|
|
||||||
parts := strings.SplitN(v, ":", 3)
|
|
||||||
if len(parts) == 1 {
|
|
||||||
hostPort, err := strconv.Atoi(v)
|
|
||||||
if err != nil {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !inRange(hostPort, 0, 65536) {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyPortMap = append(proxyPortMap, PortMap{
|
|
||||||
HostPort: hostPort,
|
|
||||||
Scheme: "__internal__",
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(parts) != 3 {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [len=%d]", v, len(parts))
|
|
||||||
}
|
|
||||||
|
|
||||||
hostPort, err := strconv.Atoi(parts[1])
|
|
||||||
if err != nil {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
containerPort, err := strconv.Atoi(parts[2])
|
|
||||||
if err != nil {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !inRange(hostPort, 0, 65536) {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !inRange(containerPort, 0, 65536) {
|
|
||||||
return proxyPortMap, fmt.Errorf("Invalid port map %s [containerPort=%d]", v, containerPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyPortMap = append(proxyPortMap, PortMap{
|
|
||||||
ContainerPort: containerPort,
|
|
||||||
HostPort: hostPort,
|
|
||||||
Scheme: parts[0],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return uniqueProxyPortMap(proxyPortMap), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func uniqueProxyPortMap(proxyPortMap []PortMap) []PortMap {
|
|
||||||
var unique []PortMap
|
|
||||||
existingPortMaps := map[string]bool{}
|
|
||||||
|
|
||||||
for _, portMap := range proxyPortMap {
|
|
||||||
if existingPortMaps[portMap.String()] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
existingPortMaps[portMap.String()] = true
|
|
||||||
unique = append(unique, portMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
return unique
|
|
||||||
}
|
|
||||||
@@ -20,19 +20,25 @@ func main() {
|
|||||||
switch subcommand {
|
switch subcommand {
|
||||||
case "build-config":
|
case "build-config":
|
||||||
args := flag.NewFlagSet("proxy:build-config", flag.ExitOnError)
|
args := flag.NewFlagSet("proxy:build-config", flag.ExitOnError)
|
||||||
|
allApps := args.Bool("all", false, "--all: build-config for all apps")
|
||||||
|
parallelCount := args.Int("parallel", proxy.RunInSerial, "--parallel: number of apps to build-config for in parallel, -1 to match cpu count")
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
appName := args.Arg(0)
|
appName := args.Arg(0)
|
||||||
err = proxy.CommandBuildConfig(appName)
|
err = proxy.CommandBuildConfig(appName, *allApps, *parallelCount)
|
||||||
case "disable":
|
case "disable":
|
||||||
args := flag.NewFlagSet("proxy:disable", flag.ExitOnError)
|
args := flag.NewFlagSet("proxy:disable", flag.ExitOnError)
|
||||||
|
allApps := args.Bool("all", false, "--all: disable proxy for all apps")
|
||||||
|
parallelCount := args.Int("parallel", proxy.RunInSerial, "--parallel: number of apps to disable proxy for in parallel, -1 to match cpu count")
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
appName := args.Arg(0)
|
appName := args.Arg(0)
|
||||||
err = proxy.CommandDisable(appName)
|
err = proxy.CommandDisable(appName, *allApps, *parallelCount)
|
||||||
case "enable":
|
case "enable":
|
||||||
args := flag.NewFlagSet("proxy:enable", flag.ExitOnError)
|
args := flag.NewFlagSet("proxy:enable", flag.ExitOnError)
|
||||||
|
allApps := args.Bool("all", false, "--all: enable proxy for all apps")
|
||||||
|
parallelCount := args.Int("parallel", proxy.RunInSerial, "--parallel: number of apps to enable proxy for in parallel, -1 to match cpu count")
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
appName := args.Arg(0)
|
appName := args.Arg(0)
|
||||||
err = proxy.CommandEnable(appName)
|
err = proxy.CommandEnable(appName, *allApps, *parallelCount)
|
||||||
case "ports":
|
case "ports":
|
||||||
args := flag.NewFlagSet("proxy:ports", flag.ExitOnError)
|
args := flag.NewFlagSet("proxy:ports", flag.ExitOnError)
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
|
|||||||
@@ -9,55 +9,42 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CommandBuildConfig rebuilds config for a given app
|
// CommandBuildConfig rebuilds config for a given app
|
||||||
func CommandBuildConfig(appName string) error {
|
func CommandBuildConfig(appName string, allApps bool, parallelCount int) error {
|
||||||
|
if allApps {
|
||||||
|
return common.RunCommandAgainstAllApps(BuildConfig, "build-config", parallelCount)
|
||||||
|
}
|
||||||
|
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.PlugnTrigger("proxy-build-config", []string{appName}...)
|
return BuildConfig(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandDisable disables the proxy for app via command line
|
// CommandDisable disables the proxy for app via command line
|
||||||
func CommandDisable(appName string) error {
|
func CommandDisable(appName string, allApps bool, parallelCount int) error {
|
||||||
|
if allApps {
|
||||||
|
return common.RunCommandAgainstAllApps(Disable, "disable", parallelCount)
|
||||||
|
}
|
||||||
|
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsAppProxyEnabled(appName) {
|
return Disable(appName)
|
||||||
common.LogInfo1("Proxy is already disable for app")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
common.LogInfo1("Disabling proxy for app")
|
|
||||||
entries := map[string]string{
|
|
||||||
"DOKKU_DISABLE_PROXY": "1",
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := config.SetMany(appName, entries, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return common.PlugnTrigger("proxy-disable", []string{appName}...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandEnable enables the proxy for app via command line
|
// CommandEnable enables the proxy for app via command line
|
||||||
func CommandEnable(appName string) error {
|
func CommandEnable(appName string, allApps bool, parallelCount int) error {
|
||||||
|
if allApps {
|
||||||
|
return common.RunCommandAgainstAllApps(Enable, "enable", parallelCount)
|
||||||
|
}
|
||||||
|
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if IsAppProxyEnabled(appName) {
|
return Enable(appName)
|
||||||
common.LogInfo1("Proxy is already enabled for app")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
common.LogInfo1("Enabling proxy for app")
|
|
||||||
keys := []string{"DOKKU_DISABLE_PROXY"}
|
|
||||||
if err := config.UnsetMany(appName, keys, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return common.PlugnTrigger("proxy-enable", []string{appName}...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandPorts is a cmd wrapper to list proxy port mappings for an app
|
// CommandPorts is a cmd wrapper to list proxy port mappings for an app
|
||||||
|
|||||||
Reference in new issue
Block a user