-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added docker conditional compilation
- Moved docker UX optimization into module - Added conditional compilation for Windows build - Added Permission Policy header editor - Fixed docker container list ui error message bug
- Loading branch information
Showing
13 changed files
with
334 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package dockerux | ||
|
||
/* Windows docker optimizer*/ | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/client" | ||
"imuslab.com/zoraxy/mod/utils" | ||
) | ||
|
||
// Windows build not support docker | ||
func (d *UXOptimizer) HandleDockerAvailable(w http.ResponseWriter, r *http.Request) { | ||
js, _ := json.Marshal(d.RunninInDocker) | ||
utils.SendJSONResponse(w, string(js)) | ||
} | ||
|
||
func (d *UXOptimizer) HandleDockerContainersList(w http.ResponseWriter, r *http.Request) { | ||
apiClient, err := client.NewClientWithOpts(client.WithVersion("1.43")) | ||
if err != nil { | ||
d.SystemWideLogger.PrintAndLog("Docker", "Unable to create new docker client", err) | ||
utils.SendErrorResponse(w, "Docker client initiation failed") | ||
return | ||
} | ||
defer apiClient.Close() | ||
|
||
containers, err := apiClient.ContainerList(context.Background(), container.ListOptions{All: true}) | ||
if err != nil { | ||
d.SystemWideLogger.PrintAndLog("Docker", "List docker container failed", err) | ||
utils.SendErrorResponse(w, "List docker container failed") | ||
return | ||
} | ||
|
||
networks, err := apiClient.NetworkList(context.Background(), types.NetworkListOptions{}) | ||
if err != nil { | ||
d.SystemWideLogger.PrintAndLog("Docker", "List docker network failed", err) | ||
utils.SendErrorResponse(w, "List docker network failed") | ||
return | ||
} | ||
|
||
result := map[string]interface{}{ | ||
"network": networks, | ||
"containers": containers, | ||
} | ||
|
||
js, err := json.Marshal(result) | ||
if err != nil { | ||
utils.SendErrorResponse(w, err.Error()) | ||
return | ||
} | ||
|
||
utils.SendJSONResponse(w, string(js)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package dockerux | ||
|
||
/* | ||
Windows docker UX optimizer dummy | ||
This is a dummy module for Windows as docker features | ||
is useless on Windows and create a larger binary size | ||
docker on Windows build are trimmed to reduce binary size | ||
and make it compatibile with Windows 7 | ||
*/ | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"imuslab.com/zoraxy/mod/utils" | ||
) | ||
|
||
// Windows build not support docker | ||
func (d *UXOptimizer) HandleDockerAvailable(w http.ResponseWriter, r *http.Request) { | ||
js, _ := json.Marshal(d.RunninInDocker) | ||
utils.SendJSONResponse(w, string(js)) | ||
} | ||
|
||
func (d *UXOptimizer) HandleDockerContainersList(w http.ResponseWriter, r *http.Request) { | ||
utils.SendErrorResponse(w, "Platform not supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dockerux | ||
|
||
import "imuslab.com/zoraxy/mod/info/logger" | ||
|
||
/* | ||
Docker Optimizer | ||
This script add support for optimizing docker user experience | ||
Note that this module are community contribute only. For bug | ||
report, please directly tag the Pull Request author. | ||
*/ | ||
|
||
type UXOptimizer struct { | ||
RunninInDocker bool | ||
SystemWideLogger *logger.Logger | ||
} | ||
|
||
//Create a new docker optimizer | ||
func NewDockerOptimizer(IsRunningInDocker bool, logger *logger.Logger) *UXOptimizer { | ||
return &UXOptimizer{ | ||
RunninInDocker: IsRunningInDocker, | ||
SystemWideLogger: logger, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.