Add env
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Adam Štrauch 2023-10-14 01:10:14 +02:00
parent 37ca4ece39
commit 00beda8137
Signed by: cx
GPG Key ID: 7262DAFE292BCE20
5 changed files with 18 additions and 3 deletions

View File

@ -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
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
Setup struct {
SSHKeys string `json:"ssh_keys"`

View File

@ -307,7 +307,7 @@ func (d *Driver) pullImage(image string) error {
// cmd - string slice of command and its arguments
// volumePath - host's directory to mount into the container
// 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)
cli, err := d.getClient()
if err != nil {
@ -343,11 +343,16 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
OOMKillDisable = true
}
envList := []string{}
for key, value := range env {
envList = append(envList, key+"="+value)
}
createdContainer, err := cli.ContainerCreate(
context.Background(),
&container.Config{
Hostname: name,
Env: []string{},
Env: envList,
Image: image,
Cmd: cmd,
ExposedPorts: nat.PortSet{

View File

@ -25,7 +25,10 @@ func TestGetProcesses(t *testing.T) {
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)
err = driver.Start("test")

View File

@ -159,6 +159,7 @@ func (c *Container) Create() error {
c.App.CPU,
c.App.Memory,
[]string{},
c.App.Env,
)
return err

View File

@ -202,6 +202,10 @@ func (p *Processor) Get(noUpdate bool) (apps.App, error) {
// Create creates a single app in the system
func (p *Processor) Create(appTemplate apps.App) error {
if appTemplate.Env == nil {
appTemplate.Env = make(map[string]string)
}
err := p.Register(appTemplate)
if err != nil {
return err