This commit is contained in:
parent
37ca4ece39
commit
00beda8137
@ -102,6 +102,8 @@ type App struct {
|
|||||||
// This is not store in the database but used in create request when the app suppose to be created from an existing snapshot
|
// This is not store in the database but used in create request when the app suppose to be created from an existing snapshot
|
||||||
Snapshot string `json:"snapshot" gorm:"-"`
|
Snapshot string `json:"snapshot" gorm:"-"`
|
||||||
|
|
||||||
|
Env map[string]string `json:"env"`
|
||||||
|
|
||||||
// Fields to setup during creating of the app, this is not stored in the database
|
// Fields to setup during creating of the app, this is not stored in the database
|
||||||
Setup struct {
|
Setup struct {
|
||||||
SSHKeys string `json:"ssh_keys"`
|
SSHKeys string `json:"ssh_keys"`
|
||||||
|
@ -307,7 +307,7 @@ func (d *Driver) pullImage(image string) error {
|
|||||||
// cmd - string slice of command and its arguments
|
// cmd - string slice of command and its arguments
|
||||||
// volumePath - host's directory to mount into the container
|
// volumePath - host's directory to mount into the container
|
||||||
// returns container ID
|
// returns container ID
|
||||||
func (d *Driver) Create(name string, image string, volumePath string, HTTPPort int, SSHPort int, CPU int, memory int, cmd []string) (string, error) {
|
func (d *Driver) Create(name string, image string, volumePath string, HTTPPort int, SSHPort int, CPU int, memory int, cmd []string, env map[string]string) (string, error) {
|
||||||
log.Println("Creating container " + name)
|
log.Println("Creating container " + name)
|
||||||
cli, err := d.getClient()
|
cli, err := d.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -343,11 +343,16 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
|
|||||||
OOMKillDisable = true
|
OOMKillDisable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envList := []string{}
|
||||||
|
for key, value := range env {
|
||||||
|
envList = append(envList, key+"="+value)
|
||||||
|
}
|
||||||
|
|
||||||
createdContainer, err := cli.ContainerCreate(
|
createdContainer, err := cli.ContainerCreate(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Hostname: name,
|
Hostname: name,
|
||||||
Env: []string{},
|
Env: envList,
|
||||||
Image: image,
|
Image: image,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
ExposedPorts: nat.PortSet{
|
ExposedPorts: nat.PortSet{
|
||||||
|
@ -25,7 +25,10 @@ func TestGetProcesses(t *testing.T) {
|
|||||||
|
|
||||||
driver.Remove("test")
|
driver.Remove("test")
|
||||||
|
|
||||||
_, err := driver.Create("test", "docker.io/library/busybox", "/tmp", 8990, 8922, 1, 128, []string{"sleep", "3600"})
|
env := make(map[string]string)
|
||||||
|
env["TEST"] = "test"
|
||||||
|
|
||||||
|
_, err := driver.Create("test", "docker.io/library/busybox", "/tmp", 8990, 8922, 1, 128, []string{"sleep", "3600"}, env)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
err = driver.Start("test")
|
err = driver.Start("test")
|
||||||
|
@ -159,6 +159,7 @@ func (c *Container) Create() error {
|
|||||||
c.App.CPU,
|
c.App.CPU,
|
||||||
c.App.Memory,
|
c.App.Memory,
|
||||||
[]string{},
|
[]string{},
|
||||||
|
c.App.Env,
|
||||||
)
|
)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -202,6 +202,10 @@ func (p *Processor) Get(noUpdate bool) (apps.App, error) {
|
|||||||
|
|
||||||
// Create creates a single app in the system
|
// Create creates a single app in the system
|
||||||
func (p *Processor) Create(appTemplate apps.App) error {
|
func (p *Processor) Create(appTemplate apps.App) error {
|
||||||
|
if appTemplate.Env == nil {
|
||||||
|
appTemplate.Env = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
err := p.Register(appTemplate)
|
err := p.Register(appTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user