mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move envconfig generation to lxc driver
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
222605b5fb
commit
4994b0fe54
3 changed files with 20 additions and 44 deletions
|
@ -168,19 +168,6 @@ func (container *Container) WriteHostConfig() (err error) {
|
||||||
return ioutil.WriteFile(container.hostConfigPath(), data, 0666)
|
return ioutil.WriteFile(container.hostConfigPath(), data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) generateEnvConfig(env []string) error {
|
|
||||||
data, err := json.Marshal(env)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p, err := container.EnvConfigPath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ioutil.WriteFile(p, data, 0600)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, stdout io.Writer, stderr io.Writer) chan error {
|
func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, stdout io.Writer, stderr io.Writer) chan error {
|
||||||
var cStdout, cStderr io.ReadCloser
|
var cStdout, cStderr io.ReadCloser
|
||||||
|
|
||||||
|
@ -422,15 +409,10 @@ func (container *Container) Start() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
env := container.createDaemonEnvironment(linkedEnv)
|
|
||||||
// TODO: This is only needed for lxc so we should look for a way to
|
|
||||||
// remove this dep
|
|
||||||
if err := container.generateEnvConfig(env); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := container.setupWorkingDirectory(); err != nil {
|
if err := container.setupWorkingDirectory(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
env := container.createDaemonEnvironment(linkedEnv)
|
||||||
if err := populateCommand(container, env); err != nil {
|
if err := populateCommand(container, env); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -851,22 +833,6 @@ func (container *Container) jsonPath() string {
|
||||||
return path.Join(container.root, "config.json")
|
return path.Join(container.root, "config.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) EnvConfigPath() (string, error) {
|
|
||||||
p := path.Join(container.root, "config.env")
|
|
||||||
if _, err := os.Stat(p); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
f, err := os.Create(p)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
f.Close()
|
|
||||||
} else {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method must be exported to be used from the lxc template
|
// This method must be exported to be used from the lxc template
|
||||||
// This directory is only usable when the container is running
|
// This directory is only usable when the container is running
|
||||||
func (container *Container) RootfsPath() string {
|
func (container *Container) RootfsPath() string {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package lxc
|
package lxc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -85,6 +86,9 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
|
||||||
if err := execdriver.SetTerminal(c, pipes); err != nil {
|
if err := execdriver.SetTerminal(c, pipes); err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
if err := d.generateEnvConfig(c); err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
configPath, err := d.generateLXCConfig(c)
|
configPath, err := d.generateLXCConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
|
@ -416,3 +420,14 @@ func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) {
|
||||||
}
|
}
|
||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *driver) generateEnvConfig(c *execdriver.Command) error {
|
||||||
|
data, err := json.Marshal(c.Env)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p := path.Join(d.root, "containers", c.ID, "config.env")
|
||||||
|
c.Mounts = append(c.Mounts, execdriver.Mount{p, "/.dockerenv", false, true})
|
||||||
|
|
||||||
|
return ioutil.WriteFile(p, data, 0600)
|
||||||
|
}
|
||||||
|
|
|
@ -2,14 +2,15 @@ package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/archive"
|
|
||||||
"github.com/dotcloud/docker/daemon/execdriver"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/archive"
|
||||||
|
"github.com/dotcloud/docker/daemon/execdriver"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BindMap struct {
|
type BindMap struct {
|
||||||
|
@ -34,14 +35,8 @@ func prepareVolumesForContainer(container *Container) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupMountsForContainer(container *Container) error {
|
func setupMountsForContainer(container *Container) error {
|
||||||
envPath, err := container.EnvConfigPath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mounts := []execdriver.Mount{
|
mounts := []execdriver.Mount{
|
||||||
{container.daemon.sysInitPath, "/.dockerinit", false, true},
|
{container.daemon.sysInitPath, "/.dockerinit", false, true},
|
||||||
{envPath, "/.dockerenv", false, true},
|
|
||||||
{container.ResolvConfPath, "/etc/resolv.conf", false, true},
|
{container.ResolvConfPath, "/etc/resolv.conf", false, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue