|
|
@@ -6,10 +6,12 @@ import (
|
|
|
"fmt"
|
|
|
"goseg/config"
|
|
|
"goseg/defaults"
|
|
|
+ "goseg/structs"
|
|
|
"io/ioutil"
|
|
|
"path/filepath"
|
|
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
+ "github.com/docker/docker/api/types/mount"
|
|
|
)
|
|
|
|
|
|
// load existing urbits from config json
|
|
|
@@ -40,23 +42,21 @@ func LoadUrbits() error {
|
|
|
}
|
|
|
|
|
|
// urbit container config builder
|
|
|
-func urbitContainerConf(containerName string) (container.Config, error) {
|
|
|
+func urbitContainerConf(containerName string) (container.Config, container.HostConfig, error) {
|
|
|
var containerConfig container.Config
|
|
|
+ var hostConfig container.HostConfig
|
|
|
var scriptContent string
|
|
|
// construct the container metadata from version server info
|
|
|
containerInfo, err := GetLatestContainerInfo("vere")
|
|
|
if err != nil {
|
|
|
- return containerConfig, err
|
|
|
+ return containerConfig, hostConfig, err
|
|
|
}
|
|
|
- desiredTag := containerInfo["tag"]
|
|
|
- desiredHash := containerInfo["hash"]
|
|
|
- desiredRepo := containerInfo["repo"]
|
|
|
- desiredImage := fmt.Sprintf("%s:%s@sha256:%s", desiredRepo, desiredTag, desiredHash)
|
|
|
+ desiredImage := fmt.Sprintf("%s:%s@sha256:%s", containerInfo["repo"], containerInfo["tag"], containerInfo["hash"])
|
|
|
// reload urbit conf from disk
|
|
|
err = config.LoadUrbitConfig(containerName)
|
|
|
if err != nil {
|
|
|
errmsg := fmt.Errorf("Error loading %s config: %v", containerName, err)
|
|
|
- return containerConfig, errmsg
|
|
|
+ return containerConfig, hostConfig, errmsg
|
|
|
}
|
|
|
// put in memory
|
|
|
shipConf := config.UrbitConf(containerName)
|
|
|
@@ -72,32 +72,65 @@ func urbitContainerConf(containerName string) (container.Config, error) {
|
|
|
scriptContent = defaults.MeldScript
|
|
|
case "prep":
|
|
|
scriptContent = defaults.PrepScript
|
|
|
+ case "noboot":
|
|
|
+ return containerConfig, hostConfig, fmt.Errorf("%s marked noboot!",containerName)
|
|
|
default:
|
|
|
- return containerConfig, fmt.Errorf("Unknown action: %s", act)
|
|
|
+ return containerConfig, hostConfig, fmt.Errorf("Unknown action: %s", act)
|
|
|
+ }
|
|
|
+ // reset ship status to boot for next time
|
|
|
+ if act != "boot" {
|
|
|
+ updateUrbitConf := shipConf
|
|
|
+ updateUrbitConf.BootStatus = "boot"
|
|
|
+ var newConfig map[string]structs.UrbitDocker
|
|
|
+ newConfig[containerName] = updateUrbitConf
|
|
|
+ err = config.UpdateUrbitConfig(newConfig)
|
|
|
+ if err != nil {
|
|
|
+ logger.Warn("Unable to reset %s boot script!", containerName)
|
|
|
+ }
|
|
|
}
|
|
|
// write the script
|
|
|
scriptPath := filepath.Join(config.DockerDir, containerName, "_data", containerName, "start_urbit.sh")
|
|
|
err = ioutil.WriteFile(scriptPath, []byte(scriptContent), 0755) // make the script executable
|
|
|
if err != nil {
|
|
|
- return containerConfig, fmt.Errorf("Failed to write script: %v", err)
|
|
|
+ return containerConfig, hostConfig, fmt.Errorf("Failed to write script: %v", err)
|
|
|
}
|
|
|
// gather boot option values
|
|
|
shipName := shipConf.PierName
|
|
|
loomValue := string(shipConf.LoomSize)
|
|
|
dirnameValue := shipConf.PierName
|
|
|
+ var devMode string
|
|
|
+ if shipConf.DevMode == true {
|
|
|
+ devMode = "True"
|
|
|
+ } else {
|
|
|
+ devMode = "False"
|
|
|
+ }
|
|
|
var httpPort string
|
|
|
var amesPort string
|
|
|
+ var network string
|
|
|
if shipConf.Network == "wireguard" {
|
|
|
httpPort = string(shipConf.WgHTTPPort)
|
|
|
amesPort = string(shipConf.WgAmesPort)
|
|
|
+ network = "container:wireguard"
|
|
|
} else {
|
|
|
httpPort = string(shipConf.HTTPPort)
|
|
|
amesPort = string(shipConf.AmesPort)
|
|
|
+ network = "default"
|
|
|
}
|
|
|
- // finally construct the container config struct
|
|
|
+ // finally construct the container config structs
|
|
|
containerConfig = container.Config{
|
|
|
Image: desiredImage,
|
|
|
- Entrypoint: []string{scriptPath, shipName, "--loom=" + loomValue, "--dirname=" + dirnameValue, "--http-port=" + httpPort, "--ames-port=" + amesPort},
|
|
|
+ Entrypoint: []string{scriptPath, shipName, "--loom=" + loomValue, "--dirname=" + dirnameValue, "--dev-mode="+ devMode, "--http-port=" + httpPort, "--port=" + amesPort},
|
|
|
+ }
|
|
|
+ mounts := []mount.Mount{
|
|
|
+ {
|
|
|
+ Type: mount.TypeBind,
|
|
|
+ Source: shipName,
|
|
|
+ Target: "/data",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ hostConfig = container.HostConfig{
|
|
|
+ NetworkMode: container.NetworkMode(network),
|
|
|
+ Mounts: mounts,
|
|
|
}
|
|
|
- return containerConfig, nil
|
|
|
+ return containerConfig, hostConfig, nil
|
|
|
}
|