mirror of
https://github.com/docker/compose.git
synced 2025-07-26 23:24:05 +02:00
Support environment variables defined in compose file:
* KEY=VALUE * KEY (no =VALUE) will fetch the process environment variable envFile list is already parsed by compose-go and resolved to Environment key values no need to do anything for this.
This commit is contained in:
parent
2e867f40d7
commit
0c27fd6236
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -280,7 +281,8 @@ func (s serviceConfigAciHelper) getAciContainer(volumesCache map[string]bool) (c
|
|||||||
return containerinstance.Container{
|
return containerinstance.Container{
|
||||||
Name: to.StringPtr(s.Name),
|
Name: to.StringPtr(s.Name),
|
||||||
ContainerProperties: &containerinstance.ContainerProperties{
|
ContainerProperties: &containerinstance.ContainerProperties{
|
||||||
Image: to.StringPtr(s.Image),
|
Image: to.StringPtr(s.Image),
|
||||||
|
EnvironmentVariables: getEnvVariables(s.Environment),
|
||||||
Resources: &containerinstance.ResourceRequirements{
|
Resources: &containerinstance.ResourceRequirements{
|
||||||
Limits: &containerinstance.ResourceLimits{
|
Limits: &containerinstance.ResourceLimits{
|
||||||
MemoryInGB: to.Float64Ptr(memLimit),
|
MemoryInGB: to.Float64Ptr(memLimit),
|
||||||
@ -294,7 +296,23 @@ func (s serviceConfigAciHelper) getAciContainer(volumesCache map[string]bool) (c
|
|||||||
VolumeMounts: volumes,
|
VolumeMounts: volumes,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvVariables(composeEnv types.MappingWithEquals) *[]containerinstance.EnvironmentVariable {
|
||||||
|
result := []containerinstance.EnvironmentVariable{}
|
||||||
|
for key, value := range composeEnv {
|
||||||
|
var strValue string
|
||||||
|
if value == nil {
|
||||||
|
strValue = os.Getenv(key)
|
||||||
|
} else {
|
||||||
|
strValue = *value
|
||||||
|
}
|
||||||
|
result = append(result, containerinstance.EnvironmentVariable{
|
||||||
|
Name: to.StringPtr(key),
|
||||||
|
Value: to.StringPtr(strValue),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &result
|
||||||
}
|
}
|
||||||
|
|
||||||
func bytesToGb(b types.UnitBytes) float64 {
|
func bytesToGb(b types.UnitBytes) float64 {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
||||||
@ -260,6 +261,31 @@ func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerResourceLimit
|
|||||||
Expect(*limits.MemoryInGB).To(Equal(float64(1)))
|
Expect(*limits.MemoryInGB).To(Equal(float64(1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerenvVar() {
|
||||||
|
os.Setenv("key2", "value2")
|
||||||
|
project := types.Project{
|
||||||
|
Services: []types.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "service1",
|
||||||
|
Image: "image1",
|
||||||
|
Environment: types.MappingWithEquals{
|
||||||
|
"key1": to.StringPtr("value1"),
|
||||||
|
"key2": nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
group, err := ToContainerGroup(suite.ctx, project)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
container1 := (*group.Containers)[0]
|
||||||
|
envVars := *container1.EnvironmentVariables
|
||||||
|
Expect(len(envVars)).To(Equal(2))
|
||||||
|
Expect(envVars).To(ContainElement(containerinstance.EnvironmentVariable{Name: to.StringPtr("key1"), Value: to.StringPtr("value1")}))
|
||||||
|
Expect(envVars).To(ContainElement(containerinstance.EnvironmentVariable{Name: to.StringPtr("key2"), Value: to.StringPtr("value2")}))
|
||||||
|
}
|
||||||
|
|
||||||
func TestConvertTestSuite(t *testing.T) {
|
func TestConvertTestSuite(t *testing.T) {
|
||||||
RegisterTestingT(t)
|
RegisterTestingT(t)
|
||||||
suite.Run(t, new(ConvertTestSuite))
|
suite.Run(t, new(ConvertTestSuite))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user