| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package docker
- 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 {
- logger.Info("Loading MC container")
- confPath := filepath.Join(config.BasePath, "settings", "mc.json")
- _, err := os.Open(confPath)
- if err != nil {
- // create a default if it doesn't exist
- err = config.CreateDefaultMcConf()
- if err != nil {
- // error if we can't create it
- errmsg := fmt.Sprintf("Unable to create MC config! %v", err)
- logger.Error(errmsg)
- }
- }
- logger.Info("Running MC")
- info, err := StartContainer("mc", "miniomc")
- if err != nil {
- logger.Error(fmt.Sprintf("Error starting MC: %v", err))
- return err
- }
- config.UpdateContainerState("mc", info)
- return nil
- }
- // iterate through each ship and create a minio
- // version stuff is offloaded to version server struct
- func LoadMinIOs() error {
- logger.Info("Loading MinIO containers")
- conf := config.Conf()
- for _, pier := range conf.Piers {
- // uConf := config.UrbitConf(pier)
- label := "minio_" + pier
- info, err := StartContainer(label, "minio")
- if err != nil {
- logger.Error(fmt.Sprintf("Error starting %s Minio: %v", pier, err))
- return err
- }
- config.UpdateContainerState(label, info)
- }
- 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,
- }
- // always on wg nw
- hostConfig = container.HostConfig{
- NetworkMode: "container:wireguard",
- Mounts: mounts,
- }
- return containerConfig, hostConfig, nil
- }
- // miniomc container config builder
- func mcContainerConf() (container.Config, container.HostConfig, error) {
- var containerConfig container.Config
- var hostConfig container.HostConfig
- // construct the container metadata from version server info
- containerInfo, err := GetLatestContainerInfo("miniomc")
- if err != nil {
- return containerConfig, hostConfig, 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,
- Entrypoint: []string{"/bin/bash"},
- Tty: true,
- OpenStdin: true,
- }
- // always on wg nw
- hostConfig = container.HostConfig{
- NetworkMode: "container:wireguard",
- }
- return containerConfig, hostConfig, nil
- }
|