|
@@ -1,13 +1,9 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "bufio"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"net/http"
|
|
|
- "os"
|
|
|
- "os/exec"
|
|
|
- "strings"
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
"github.com/docker/docker/api/types/container"
|
|
@@ -15,35 +11,9 @@ import (
|
|
|
"imuslab.com/zoraxy/mod/utils"
|
|
|
)
|
|
|
|
|
|
-// IsDockerized checks if the program is running in a Docker container.
|
|
|
-func IsDockerized() bool {
|
|
|
- // Check for the /proc/1/cgroup file
|
|
|
- file, err := os.Open("/proc/1/cgroup")
|
|
|
- if err != nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- defer file.Close()
|
|
|
-
|
|
|
- scanner := bufio.NewScanner(file)
|
|
|
- for scanner.Scan() {
|
|
|
- if strings.Contains(scanner.Text(), "docker") {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-// IsDockerInstalled checks if Docker is installed on the host.
|
|
|
-func IsDockerInstalled() bool {
|
|
|
- _, err := exec.LookPath("docker")
|
|
|
- return err == nil
|
|
|
-}
|
|
|
-
|
|
|
// HandleDockerAvaible check if teh docker related functions should be avaible in front-end
|
|
|
func HandleDockerAvailable(w http.ResponseWriter, r *http.Request) {
|
|
|
- dockerAvailable := IsDockerized()
|
|
|
- js, _ := json.Marshal(dockerAvailable)
|
|
|
+ js, _ := json.Marshal(*runningInDocker)
|
|
|
utils.SendJSONResponse(w, string(js))
|
|
|
}
|
|
|
|