Pārlūkot izejas kodu

add urbit container config constructor

reid 2 gadi atpakaļ
vecāks
revīzija
1079f06e8a
5 mainītis faili ar 476 papildinājumiem un 16 dzēšanām
  1. 1 0
      config/config.go
  2. 376 0
      defaults/scripts.go
  3. 18 8
      docker/docker.go
  4. 68 0
      docker/urbit.go
  5. 13 8
      structs/structs.go

+ 1 - 0
config/config.go

@@ -32,6 +32,7 @@ var (
 	Ready     = false
 	// representation of desired/actual container states
 	GSContainers = make(map[string]structs.ContainerState)
+	DockerDir    = "/var/lib/docker/volumes/"
 	// version server check
 	checkInterval = 5 * time.Minute
 	confMutex     sync.Mutex

+ 376 - 0
defaults/scripts.go

@@ -0,0 +1,376 @@
+package defaults
+
+var (
+	PrepScript = `#!/bin/bash
+	set -eu
+	# set defaults
+	#amesPort="34343"
+	#httpPort="80"
+	loom="31"
+	devMode="False"
+	
+	# Find the first directory and start urbit with the ship therein
+	dirnames="*/"
+	dirs=( $dirnames )
+	dirname=''${dirnames[0]}
+	
+	# Patp checker
+	check_patp() {
+		patp="$1"
+		pre="dozmarbinwansamlitsighidfidlissogdirwacsabwissibrigsoldopmodfoglidhopdardorlorhodfolrintogsilmirholpaslacrovlivdalsatlibtabhanticpidtorbolfosdotlosdilforpilramtirwintadbicdifrocwidbisdasmidloprilnardapmolsanlocnovsitnidtipsicropwitnatpanminritpodmottamtolsavposnapnopsomfinfonbanmorworsipronnorbotwicsocwatdolmagpicdavbidbaltimtasmalligsivtagpadsaldivdactansidfabtarmonranniswolmispallasdismaprabtobrollatlonnodnavfignomnibpagsopralbilhaddocridmocpacravripfaltodtiltinhapmicfanpattaclabmogsimsonpinlomrictapfirhasbosbatpochactidhavsaplindibhosdabbitbarracparloddosbortochilmactomdigfilfasmithobharmighinradmashalraglagfadtopmophabnilnosmilfopfamdatnoldinhatnacrisfotribhocnimlarfitwalrapsarnalmoslandondanladdovrivbacpollaptalpitnambonrostonfodponsovnocsorlavmatmipfip"
+		suf="zodnecbudwessevpersutletfulpensytdurwepserwylsunrypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnexlunmeplutseppesdelsulpedtemledtulmetwenbynhexfebpyldulhetmevruttylwydtepbesdexsefwycburderneppurrysrebdennutsubpetrulsynregtydsupsemwynrecmegnetsecmulnymtevwebsummutnyxrextebfushepbenmuswyxsymselrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpelsyptermebsetdutdegtexsurfeltudnuxruxrenwytnubmedlytdusnebrumtynseglyxpunresredfunrevrefmectedrusbexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermertenlusnussyltecmexpubrymtucfyllepdebbermughuttunbylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmylwedducfurfexnulluclennerlexrupnedlecrydlydfenwelnydhusrelrudneshesfetdesretdunlernyrsebhulrylludremlysfynwerrycsugnysnyllyndyndemluxfedsedbecmunlyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes"
+		[[ "${patp:0:1}" == "~" ]] && patp="${patp:1}"
+		patp_arr=(${patp//-/ })
+	
+		[[ "${patp:0:3}" == "doz" ]] && return
+	
+		if [[ ${#patp} -eq 3 ]]; then
+			[[ $suf == *"$patp"* ]] && echo "$patp" && return
+		else
+			for p in "${patp_arr[@]}"; do
+				[[ ${#p} -eq 6 && $pre == *"${p:0:3}"* && $suf == *"${p:3:3}"* ]] || return
+			done
+			echo "$patp"
+		fi
+	}
+	
+	# Find a directory with a valid patp
+	for patp in *; do
+		if [[ -d $patp ]]; then
+			result=$(echo $(check_patp "$patp"))
+			if [[ -n $result ]]; then
+			  dirname=$result
+			  break
+			fi
+		fi
+	done
+	
+	# check args
+	for i in "$@"
+	do
+	case $i in
+	   --loom=*)
+		  loom="${i#*=}"
+		  shift
+		  ;;
+	   --dirname=*)
+		  dirname="${i#*=}"
+		  shift
+	esac
+	done
+	
+	# If the container is not started with the -i flag
+	# then STDIN will be closed and we need to start
+	# Urbit/vere with the -t flag.
+	ttyflag=""
+	if [ ! -t 0 ]; then
+	echo "Running with no STDIN"
+	ttyflag="-t"
+	fi
+	
+	file="${dirname}/.vere.lock"
+	if [ -e "$file" ]; then
+		content=$(cat "$file")
+		if [ "$content" == "1" ]; then
+			rm "$file"
+			echo "File .vere.lock containing PID 1 has been deleted."
+		fi
+	fi
+	
+	urbit prep --loom $loom $dirname`
+
+	StartScript = `#!/bin/bash
+
+	set -eu
+	# set defaults
+	amesPort="34343"
+	httpPort="80"
+	loom="31"
+	devMode="False"
+	
+	# Find the first directory and start urbit with the ship therein
+	dirnames="*/"
+	dirs=( $dirnames )
+	dirname=''${dirnames[0]}
+	
+	# Patp checker
+	check_patp() {
+		patp="$1"
+		pre="dozmarbinwansamlitsighidfidlissogdirwacsabwissibrigsoldopmodfoglidhopdardorlorhodfolrintogsilmirholpaslacrovlivdalsatlibtabhanticpidtorbolfosdotlosdilforpilramtirwintadbicdifrocwidbisdasmidloprilnardapmolsanlocnovsitnidtipsicropwitnatpanminritpodmottamtolsavposnapnopsomfinfonbanmorworsipronnorbotwicsocwatdolmagpicdavbidbaltimtasmalligsivtagpadsaldivdactansidfabtarmonranniswolmispallasdismaprabtobrollatlonnodnavfignomnibpagsopralbilhaddocridmocpacravripfaltodtiltinhapmicfanpattaclabmogsimsonpinlomrictapfirhasbosbatpochactidhavsaplindibhosdabbitbarracparloddosbortochilmactomdigfilfasmithobharmighinradmashalraglagfadtopmophabnilnosmilfopfamdatnoldinhatnacrisfotribhocnimlarfitwalrapsarnalmoslandondanladdovrivbacpollaptalpitnambonrostonfodponsovnocsorlavmatmipfip"
+		suf="zodnecbudwessevpersutletfulpensytdurwepserwylsunrypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnexlunmeplutseppesdelsulpedtemledtulmetwenbynhexfebpyldulhetmevruttylwydtepbesdexsefwycburderneppurrysrebdennutsubpetrulsynregtydsupsemwynrecmegnetsecmulnymtevwebsummutnyxrextebfushepbenmuswyxsymselrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpelsyptermebsetdutdegtexsurfeltudnuxruxrenwytnubmedlytdusnebrumtynseglyxpunresredfunrevrefmectedrusbexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermertenlusnussyltecmexpubrymtucfyllepdebbermughuttunbylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmylwedducfurfexnulluclennerlexrupnedlecrydlydfenwelnydhusrelrudneshesfetdesretdunlernyrsebhulrylludremlysfynwerrycsugnysnyllyndyndemluxfedsedbecmunlyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes"
+		[[ "${patp:0:1}" == "~" ]] && patp="${patp:1}"
+		patp_arr=(${patp//-/ })
+	
+		[[ "${patp:0:3}" == "doz" ]] && return
+	
+		if [[ ${#patp} -eq 3 ]]; then
+			[[ $suf == *"$patp"* ]] && echo "$patp" && return
+		else
+			for p in "${patp_arr[@]}"; do
+				[[ ${#p} -eq 6 && $pre == *"${p:0:3}"* && $suf == *"${p:3:3}"* ]] || return
+			done
+			echo "$patp"
+		fi
+	}
+	
+	# Find a directory with a valid patp
+	for patp in *; do
+		if [[ -d $patp ]]; then
+			result=$(echo $(check_patp "$patp"))
+			if [[ -n $result ]]; then
+			  dirname=$result
+			  break
+			fi
+		fi
+	done
+	
+	# check args
+	for i in "$@"
+	do
+	case $i in
+	  -p=*|--port=*)
+		  amesPort="${i#*=}"
+		  shift
+		  ;;
+	   --http-port=*)
+		  httpPort="${i#*=}"
+		  shift
+		  ;;
+	   --loom=*)
+		  loom="${i#*=}"
+		  shift
+		  ;;
+	   --dirname=*)
+		  dirname="${i#*=}"
+		  shift
+		  ;;
+	   --devmode=*)
+		  devMode="${i#*=}"
+		  shift
+		  ;;
+	esac
+	done
+	
+	# If the container is not started with the -i flag
+	# then STDIN will be closed and we need to start
+	# Urbit/vere with the -t flag.
+	ttyflag=""
+	if [ ! -t 0 ]; then
+	echo "Running with no STDIN"
+	ttyflag="-t"
+	fi
+	
+	# Check if there is a keyfile, if so boot a ship with its name, and then remove the key
+	if [ -e *.key ]; then
+		# Get the name of the key
+		keynames="*.key"
+		keys=( $keynames )
+		keyname=''${keys[0]}
+		mv $keyname /tmp
+	
+		# Boot urbit with the key, exit when done booting
+		urbit $ttyflag -w $(basename $keyname .key) -k /tmp/$keyname -p $amesPort -x --http-port $httpPort --loom $loom
+	
+		# Remove the keyfile for security
+		rm /tmp/$keyname
+		rm *.key || true
+	fi
+	
+	file="${dirname}/.vere.lock"
+	if [ -e "$file" ]; then
+		content=$(cat "$file")
+		if [ "$content" == "1" ]; then
+			rm "$file"
+			echo "File .vere.lock containing PID 1 has been deleted."
+		fi
+	fi
+	
+	
+	if [ $devMode == "True" ]; then
+		echo "Developer mode: $devMode"
+		echo "No logs will display"
+		# Run urbit inside a tmux pane (no logs)
+		tmux new -d -s urbit "script -q -c 'exec urbit -p $amesPort --http-port $httpPort --loom $loom $dirname' /dev/null"
+		tmux_pid=$(tmux list-panes -t urbit -F "#{pane_pid}")
+		while kill -0 "$tmux_pid" 2> /dev/null; do
+			sleep 3
+		done
+		tmux kill-session -t urbit
+		exit 0
+	else
+		urbit $ttyflag -p $amesPort --http-port $httpPort --loom $loom $dirname
+	fi`
+
+	PackScript = `#!/bin/bash
+	echo "URTH PACK"
+	
+	set -eu
+	# set defaults
+	#amesPort="34343"
+	#httpPort="80"
+	loom="31"
+	devMode="False"
+	
+	# Find the first directory and start urbit with the ship therein
+	dirnames="*/"
+	dirs=( $dirnames )
+	dirname=''${dirnames[0]}
+	
+	# Patp checker
+	check_patp() {
+		patp="$1"
+		pre="dozmarbinwansamlitsighidfidlissogdirwacsabwissibrigsoldopmodfoglidhopdardorlorhodfolrintogsilmirholpaslacrovlivdalsatlibtabhanticpidtorbolfosdotlosdilforpilramtirwintadbicdifrocwidbisdasmidloprilnardapmolsanlocnovsitnidtipsicropwitnatpanminritpodmottamtolsavposnapnopsomfinfonbanmorworsipronnorbotwicsocwatdolmagpicdavbidbaltimtasmalligsivtagpadsaldivdactansidfabtarmonranniswolmispallasdismaprabtobrollatlonnodnavfignomnibpagsopralbilhaddocridmocpacravripfaltodtiltinhapmicfanpattaclabmogsimsonpinlomrictapfirhasbosbatpochactidhavsaplindibhosdabbitbarracparloddosbortochilmactomdigfilfasmithobharmighinradmashalraglagfadtopmophabnilnosmilfopfamdatnoldinhatnacrisfotribhocnimlarfitwalrapsarnalmoslandondanladdovrivbacpollaptalpitnambonrostonfodponsovnocsorlavmatmipfip"
+		suf="zodnecbudwessevpersutletfulpensytdurwepserwylsunrypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnexlunmeplutseppesdelsulpedtemledtulmetwenbynhexfebpyldulhetmevruttylwydtepbesdexsefwycburderneppurrysrebdennutsubpetrulsynregtydsupsemwynrecmegnetsecmulnymtevwebsummutnyxrextebfushepbenmuswyxsymselrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpelsyptermebsetdutdegtexsurfeltudnuxruxrenwytnubmedlytdusnebrumtynseglyxpunresredfunrevrefmectedrusbexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermertenlusnussyltecmexpubrymtucfyllepdebbermughuttunbylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmylwedducfurfexnulluclennerlexrupnedlecrydlydfenwelnydhusrelrudneshesfetdesretdunlernyrsebhulrylludremlysfynwerrycsugnysnyllyndyndemluxfedsedbecmunlyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes"
+		[[ "${patp:0:1}" == "~" ]] && patp="${patp:1}"
+		patp_arr=(${patp//-/ })
+	
+		[[ "${patp:0:3}" == "doz" ]] && return
+	
+		if [[ ${#patp} -eq 3 ]]; then
+			[[ $suf == *"$patp"* ]] && echo "$patp" && return
+		else
+			for p in "${patp_arr[@]}"; do
+				[[ ${#p} -eq 6 && $pre == *"${p:0:3}"* && $suf == *"${p:3:3}"* ]] || return
+			done
+			echo "$patp"
+		fi
+	}
+	
+	# Find a directory with a valid patp
+	for patp in *; do
+		if [[ -d $patp ]]; then
+			result=$(echo $(check_patp "$patp"))
+			if [[ -n $result ]]; then
+			  dirname=$result
+			  break
+			fi
+		fi
+	done
+	
+	# check args
+	for i in "$@"
+	do
+	case $i in
+	#  -p=*|--port=*)
+	#      amesPort="${i#*=}"
+	#      shift
+	#      ;;
+	#   --http-port=*)
+	#      httpPort="${i#*=}"
+	#      shift
+	#      ;;
+	   --loom=*)
+		  loom="${i#*=}"
+		  shift
+		  ;;
+	   --dirname=*)
+		  dirname="${i#*=}"
+		  shift
+	#      ;;
+	#   --devmode=*)
+	#      devMode="${i#*=}"
+	#      shift
+	#      ;;
+	esac
+	done
+	
+	# If the container is not started with the -i flag
+	# then STDIN will be closed and we need to start
+	# Urbit/vere with the -t flag.
+	ttyflag=""
+	if [ ! -t 0 ]; then
+	echo "Running with no STDIN"
+	ttyflag="-t"
+	fi
+	
+	file="${dirname}/.vere.lock"
+	if [ -e "$file" ]; then
+		content=$(cat "$file")
+		if [ "$content" == "1" ]; then
+			rm "$file"
+			echo "File .vere.lock containing PID 1 has been deleted."
+		fi
+	fi
+	
+	urbit pack --loom $loom $dirname`
+
+	MeldScript = `#!/bin/bash
+	echo "URTH MELD"
+	
+	set -eu
+	# set defaults
+	#amesPort="34343"
+	#httpPort="80"
+	loom="31"
+	devMode="False"
+	
+	# Find the first directory and start urbit with the ship therein
+	dirnames="*/"
+	dirs=( $dirnames )
+	dirname=''${dirnames[0]}
+	
+	# Patp checker
+	check_patp() {
+		patp="$1"
+		pre="dozmarbinwansamlitsighidfidlissogdirwacsabwissibrigsoldopmodfoglidhopdardorlorhodfolrintogsilmirholpaslacrovlivdalsatlibtabhanticpidtorbolfosdotlosdilforpilramtirwintadbicdifrocwidbisdasmidloprilnardapmolsanlocnovsitnidtipsicropwitnatpanminritpodmottamtolsavposnapnopsomfinfonbanmorworsipronnorbotwicsocwatdolmagpicdavbidbaltimtasmalligsivtagpadsaldivdactansidfabtarmonranniswolmispallasdismaprabtobrollatlonnodnavfignomnibpagsopralbilhaddocridmocpacravripfaltodtiltinhapmicfanpattaclabmogsimsonpinlomrictapfirhasbosbatpochactidhavsaplindibhosdabbitbarracparloddosbortochilmactomdigfilfasmithobharmighinradmashalraglagfadtopmophabnilnosmilfopfamdatnoldinhatnacrisfotribhocnimlarfitwalrapsarnalmoslandondanladdovrivbacpollaptalpitnambonrostonfodponsovnocsorlavmatmipfip"
+		suf="zodnecbudwessevpersutletfulpensytdurwepserwylsunrypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnexlunmeplutseppesdelsulpedtemledtulmetwenbynhexfebpyldulhetmevruttylwydtepbesdexsefwycburderneppurrysrebdennutsubpetrulsynregtydsupsemwynrecmegnetsecmulnymtevwebsummutnyxrextebfushepbenmuswyxsymselrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpelsyptermebsetdutdegtexsurfeltudnuxruxrenwytnubmedlytdusnebrumtynseglyxpunresredfunrevrefmectedrusbexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermertenlusnussyltecmexpubrymtucfyllepdebbermughuttunbylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmylwedducfurfexnulluclennerlexrupnedlecrydlydfenwelnydhusrelrudneshesfetdesretdunlernyrsebhulrylludremlysfynwerrycsugnysnyllyndyndemluxfedsedbecmunlyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes"
+		[[ "${patp:0:1}" == "~" ]] && patp="${patp:1}"
+		patp_arr=(${patp//-/ })
+	
+		[[ "${patp:0:3}" == "doz" ]] && return
+	
+		if [[ ${#patp} -eq 3 ]]; then
+			[[ $suf == *"$patp"* ]] && echo "$patp" && return
+		else
+			for p in "${patp_arr[@]}"; do
+				[[ ${#p} -eq 6 && $pre == *"${p:0:3}"* && $suf == *"${p:3:3}"* ]] || return
+			done
+			echo "$patp"
+		fi
+	}
+	
+	# Find a directory with a valid patp
+	for patp in *; do
+		if [[ -d $patp ]]; then
+			result=$(echo $(check_patp "$patp"))
+			if [[ -n $result ]]; then
+			  dirname=$result
+			  break
+			fi
+		fi
+	done
+	
+	# check args
+	for i in "$@"
+	do
+	case $i in
+	   --loom=*)
+		  loom="${i#*=}"
+		  shift
+		  ;;
+	   --dirname=*)
+		  dirname="${i#*=}"
+		  shift
+	esac
+	done
+	
+	# If the container is not started with the -i flag
+	# then STDIN will be closed and we need to start
+	# Urbit/vere with the -t flag.
+	ttyflag=""
+	if [ ! -t 0 ]; then
+	echo "Running with no STDIN"
+	ttyflag="-t"
+	fi
+	
+	file="${dirname}/.vere.lock"
+	if [ -e "$file" ]; then
+		content=$(cat "$file")
+		if [ "$content" == "1" ]; then
+			rm "$file"
+			echo "File .vere.lock containing PID 1 has been deleted."
+		fi
+	fi
+	
+	urbit meld --loom $loom $dirname`
+)

+ 18 - 8
docker/docker.go

@@ -110,9 +110,23 @@ func GetContainerStats(containerName string) (structs.ContainerStats, error) {
 }
 
 // start a container by name + type
-// not for booting new ships
+// contructs a container.Config, then runs through whether to boot/restart/etc
+// saves the current container state in memory after completion
 func StartContainer(containerName string, containerType string) (structs.ContainerState, error) {
 	var containerState structs.ContainerState
+	var containerConfig container.Config
+	// switch on containerType to process containerConfig
+	switch containerType { 
+	case "vere":
+		// containerConfig, err := urbitContainerConf(containerName)
+		_, err := urbitContainerConf(containerName)
+		if err != nil {
+			return containerState, err
+		}
+	default:
+		errmsg := fmt.Errorf("Unrecognized container type %s",containerType)
+		return containerState, errmsg
+	}
 	ctx := context.Background()
 	cli, err := client.NewClientWithOpts(client.FromEnv)
 	if err != nil {
@@ -145,10 +159,6 @@ func StartContainer(containerName string, containerType string) (structs.Contain
 	desiredRepo := containerInfo["repo"]
 	desiredImage := fmt.Sprintf("%s:%s@sha256:%s", desiredRepo, desiredTag, desiredHash)
 	desiredStatus := "running"
-	if desiredTag == "" || desiredHash == "" {
-		err = fmt.Errorf("Version info has not been retrieved!")
-		return containerState, err
-	}
 	// check if the desired image is available locally
 	images, err := cli.ImageList(ctx, types.ImageListOptions{})
 	if err != nil {
@@ -174,9 +184,7 @@ func StartContainer(containerName string, containerType string) (structs.Contain
 	switch {
 	case existingContainer == nil:
 		// if the container does not exist, create and start it
-		_, err := cli.ContainerCreate(ctx, &container.Config{
-			Image: desiredImage,
-		}, nil, nil, nil, containerName)
+		_, err := cli.ContainerCreate(ctx, &containerConfig, nil, nil, nil, containerName)
 		if err != nil {
 			return containerState, err
 		}
@@ -226,6 +234,7 @@ func StartContainer(containerName string, containerType string) (structs.Contain
 	if err != nil {
 		return containerState, fmt.Errorf("failed to inspect container %s: %v", containerName, err)
 	}
+	// save the current state of the container in memory for reference
 	containerState = structs.ContainerState{
 		ID:            containerDetails.ID,           // container id hash
 		Name:          containerName,                 // name (eg @p)
@@ -234,6 +243,7 @@ func StartContainer(containerName string, containerType string) (structs.Contain
 		DesiredStatus: desiredStatus,                 // what the user sets
 		ActualStatus:  containerDetails.State.Status, // what the daemon reports
 		CreatedAt:     containerDetails.Created,      // this is a string
+		Config:		   containerConfig,				  // container.Config struct constructed above
 	}
 	return containerState, err
 }

+ 68 - 0
docker/urbit.go

@@ -5,6 +5,11 @@ package docker
 import (
 	"fmt"
 	"goseg/config"
+	"goseg/defaults"
+	"path/filepath"
+	"io/ioutil"
+
+	"github.com/docker/docker/api/types/container"
 )
 
 // load existing urbits from config json
@@ -33,3 +38,66 @@ func LoadUrbits() error {
 	}
 	return nil
 }
+
+// urbit container config builder
+func urbitContainerConf(containerName string) (container.Config, error) {
+	var containerConfig container.Config
+	var scriptContent string
+	// construct the container metadata from version server info
+	containerInfo, err := GetLatestContainerInfo("vere")
+	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)
+	// 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
+	}
+	// put in memory
+	shipConf := config.UrbitConf(containerName)
+	// todo: this BootStatus doesnt actually have anythin to do with pack and meld right now
+	act := shipConf.BootStatus
+	// get the correct startup script based on act
+	switch act {
+	case "boot":
+		scriptContent = defaults.StartScript
+	case "pack":
+		scriptContent = defaults.PackScript
+	case "meld":
+		scriptContent = defaults.MeldScript
+	case "prep":
+		scriptContent = defaults.PrepScript
+	default:
+		return containerConfig, fmt.Errorf("Unknown action: %s", act)
+	}
+	// 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)
+	}
+	// gather boot option values
+	shipName := shipConf.PierName
+	loomValue := string(shipConf.LoomSize)
+	dirnameValue := shipConf.PierName
+	var httpPort string
+	var amesPort string
+	if shipConf.Network == "wireguard" {
+		httpPort = string(shipConf.WgHTTPPort)
+		amesPort = string(shipConf.WgAmesPort)
+	} else {
+		httpPort = string(shipConf.HTTPPort)
+		amesPort = string(shipConf.AmesPort)
+	}
+	// finally construct the container config struct
+	containerConfig = container.Config{
+		Image:      desiredImage,
+		Entrypoint: []string{scriptPath, shipName, "--loom="+loomValue, "--dirname="+dirnameValue, "--http-port="+httpPort, "--ames-port="+amesPort},
+	}
+	return containerConfig, nil
+}

+ 13 - 8
structs/structs.go

@@ -1,5 +1,9 @@
 package structs
 
+import (
+	"github.com/docker/docker/api/types/container"
+)
+
 // incoming websocket payloads
 type WsPayload struct {
 	Type   string `json:"type"`
@@ -14,13 +18,14 @@ type Event struct {
 
 // for keeping track of container desired/actual state
 type ContainerState struct {
-	ID            string
-	Name          string
-	Type          string
-	Image         string
-	ActualStatus  string // on/off
-	DesiredStatus string
-	ActualNetwork string // bridge/wireguard
+	ID             string
+	Name           string
+	Type           string
+	Image          string
+	ActualStatus   string // on/off
+	DesiredStatus  string
+	ActualNetwork  string // bridge/wireguard
 	DesiredNetwork string
-	CreatedAt     string
+	CreatedAt      string
+	Config		   container.Config
 }