|
|
@@ -4,7 +4,10 @@ import (
|
|
|
"fmt"
|
|
|
"goseg/config"
|
|
|
"os"
|
|
|
+ "strings"
|
|
|
"path/filepath"
|
|
|
+ "github.com/docker/docker/api/types/container"
|
|
|
+ "github.com/docker/docker/api/types/mount"
|
|
|
)
|
|
|
|
|
|
func LoadMC() error {
|
|
|
@@ -47,3 +50,65 @@ func LoadMinIOs() error {
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+// minio container config builder
|
|
|
+func minioContainerConf(containerName string) (container.Config, container.HostConfig, error) {
|
|
|
+ var containerConfig container.Config
|
|
|
+ var hostConfig container.HostConfig
|
|
|
+ shipName := strings.Split(containerName,"_")[1]
|
|
|
+ err := config.LoadUrbitConfig(shipName)
|
|
|
+ if err != nil {
|
|
|
+ errmsg := fmt.Errorf("Error loading %s config: %v", shipName, err)
|
|
|
+ return containerConfig, hostConfig, errmsg
|
|
|
+ }
|
|
|
+ shipConf := config.UrbitConf(shipName)
|
|
|
+ // construct the container metadata from version server info
|
|
|
+ containerInfo, err := GetLatestContainerInfo("minio")
|
|
|
+ if err != nil {
|
|
|
+ return containerConfig, hostConfig, err
|
|
|
+ }
|
|
|
+ desiredImage := fmt.Sprintf("%s:%s@sha256:%s", containerInfo["repo"], containerInfo["tag"], containerInfo["hash"])
|
|
|
+ command := fmt.Sprintf("server /data --console-address :%s --address :%s", string(shipConf.WgConsolePort), string(shipConf.WgS3Port))
|
|
|
+ environment := []string{
|
|
|
+ fmt.Sprintf("MINIO_ROOT_USER=%s", shipName),
|
|
|
+ fmt.Sprintf("MINIO_ROOT_PASSWORD=%s", shipConf.MinioPassword),
|
|
|
+ fmt.Sprintf("MINIO_DOMAIN=s3.%s", shipConf.WgURL),
|
|
|
+ fmt.Sprintf("MINIO_SERVER_URL=https://s3.%s", shipConf.WgURL),
|
|
|
+ }
|
|
|
+ mounts := []mount.Mount{
|
|
|
+ {
|
|
|
+ Type: mount.TypeBind,
|
|
|
+ Source: shipName,
|
|
|
+ Target: "/data",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ containerConfig = container.Config{
|
|
|
+ Image: desiredImage,
|
|
|
+ Cmd: []string{command},
|
|
|
+ Env: environment,
|
|
|
+ }
|
|
|
+ hostConfig = container.HostConfig{
|
|
|
+ NetworkMode: "container:wireguard",
|
|
|
+ Mounts: mounts,
|
|
|
+ }
|
|
|
+ return containerConfig, hostConfig, nil
|
|
|
+}
|
|
|
+
|
|
|
+// miniomc container config builder
|
|
|
+func mcContainerConf() (container.Config, error) {
|
|
|
+ var containerConfig container.Config
|
|
|
+ // construct the container metadata from version server info
|
|
|
+ containerInfo, err := GetLatestContainerInfo("miniomc")
|
|
|
+ if err != nil {
|
|
|
+ return containerConfig, err
|
|
|
+ }
|
|
|
+ desiredTag := containerInfo["tag"]
|
|
|
+ desiredHash := containerInfo["hash"]
|
|
|
+ desiredRepo := containerInfo["repo"]
|
|
|
+ desiredImage := fmt.Sprintf("%s:%s@sha256:%s", desiredRepo, desiredTag, desiredHash)
|
|
|
+ // construct the container config struct
|
|
|
+ containerConfig = container.Config{
|
|
|
+ Image: desiredImage,
|
|
|
+ }
|
|
|
+ return containerConfig, nil
|
|
|
+}
|