mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat(env): support env vars for services (both run command and compose)
This commit is contained in:
@@ -47,6 +47,11 @@ func assertContainerMatchesSpec(t *testing.T, ctr api.ServiceContainer, spec api
|
||||
assert.EqualValues(t, spec.Container.Entrypoint, ctr.Config.Entrypoint)
|
||||
}
|
||||
|
||||
expectedEnvs := spec.Container.Env.ToSlice()
|
||||
for _, env := range expectedEnvs {
|
||||
assert.Contains(t, ctr.Config.Env, env)
|
||||
}
|
||||
|
||||
assert.Equal(t, spec.Container.Image, ctr.Config.Image)
|
||||
assert.Equal(t, spec.Container.Init, ctr.HostConfig.Init)
|
||||
assert.ElementsMatch(t, spec.Container.Volumes, ctr.HostConfig.Binds)
|
||||
|
||||
@@ -3,12 +3,13 @@ package e2e
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/ucind"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
"github.com/psviderski/uncloud/pkg/client/compose"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestComposeDeployment(t *testing.T) {
|
||||
@@ -52,6 +53,11 @@ func TestComposeDeployment(t *testing.T) {
|
||||
Name: name,
|
||||
Mode: api.ServiceModeReplicated,
|
||||
Container: api.ContainerSpec{
|
||||
Env: map[string]string{
|
||||
"VAR": "value",
|
||||
"BOOL": "true",
|
||||
"EMPTY": "",
|
||||
},
|
||||
// TODO: resolve image digest and substitute the image with the image@digest.
|
||||
Image: "portainer/pause:3.9",
|
||||
},
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
services:
|
||||
basic:
|
||||
environment:
|
||||
VAR: "value"
|
||||
BOOL: "true"
|
||||
EMPTY: ""
|
||||
image: portainer/pause:3.9
|
||||
x-ports:
|
||||
- basic.example.com:80/https
|
||||
|
||||
@@ -659,6 +659,8 @@ func TestServiceLifecycle(t *testing.T) {
|
||||
// Verify default settings.
|
||||
assert.Empty(t, ctr.Config.Cmd)
|
||||
assert.EqualValues(t, []string{"/pause"}, ctr.Config.Entrypoint) // Populated by the image.
|
||||
assert.Equal(t, []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, ctr.Config.Env)
|
||||
|
||||
assert.Nil(t, ctr.HostConfig.Init)
|
||||
assert.Empty(t, ctr.HostConfig.Binds)
|
||||
assert.Empty(t, ctr.HostConfig.PortBindings)
|
||||
@@ -691,9 +693,15 @@ func TestServiceLifecycle(t *testing.T) {
|
||||
Command: []string{"sleep", "infinity"},
|
||||
// Extra slashes is not a typo, it changes the spec but Linux ignores them and uses the default /pause.
|
||||
Entrypoint: []string{"///pause"},
|
||||
Image: "portainer/pause:latest",
|
||||
Init: &init,
|
||||
Volumes: []string{"/host/path:/container/path:ro"},
|
||||
Env: map[string]string{
|
||||
"VAR": "value",
|
||||
"EMTPY": "",
|
||||
"BOOL": "true",
|
||||
"": "ignored",
|
||||
},
|
||||
Image: "portainer/pause:latest",
|
||||
Init: &init,
|
||||
Volumes: []string{"/host/path:/container/path:ro"},
|
||||
},
|
||||
Ports: []api.PortSpec{
|
||||
{
|
||||
@@ -733,6 +741,15 @@ func TestServiceLifecycle(t *testing.T) {
|
||||
|
||||
assert.EqualValues(t, spec.Container.Command, ctr.Config.Cmd)
|
||||
assert.EqualValues(t, spec.Container.Entrypoint, ctr.Config.Entrypoint)
|
||||
|
||||
expectedEnv := []string{
|
||||
"BOOL=true",
|
||||
"EMTPY=",
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
"VAR=value",
|
||||
}
|
||||
assert.ElementsMatch(t, expectedEnv, ctr.Config.Env)
|
||||
|
||||
assert.True(t, *ctr.HostConfig.Init)
|
||||
assert.Len(t, ctr.HostConfig.Binds, 1)
|
||||
assert.Contains(t, ctr.HostConfig.Binds, spec.Container.Volumes[0])
|
||||
|
||||
Reference in New Issue
Block a user