2018-02-05 16:05:59 -05:00
|
|
|
package image // import "github.com/docker/docker/integration/image"
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-18 11:26:44 -04:00
|
|
|
"strings"
|
2017-11-22 16:31:26 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-05-04 17:15:00 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-03-02 14:02:50 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/skip"
|
2017-11-22 16:31:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommitInheritsEnv(t *testing.T) {
|
2018-05-04 17:15:00 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.36"), "broken in earlier versions")
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
|
2017-11-22 16:31:26 -05:00
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2017-11-22 16:31:26 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:00:37 -04:00
|
|
|
cID1 := container.Create(ctx, t, client)
|
2020-05-18 11:26:44 -04:00
|
|
|
imgName := strings.ToLower(t.Name())
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
2017-11-22 16:31:26 -05:00
|
|
|
Changes: []string{"ENV PATH=/bin"},
|
2020-05-18 11:26:44 -04:00
|
|
|
Reference: imgName,
|
2017-11-22 16:31:26 -05:00
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
image1, _, err := client.ImageInspectWithRaw(ctx, commitResp1.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
expectedEnv1 := []string{"PATH=/bin"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(expectedEnv1, image1.Config.Env))
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2019-06-06 07:00:37 -04:00
|
|
|
cID2 := container.Create(ctx, t, client, container.WithImage(image1.ID))
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
2017-11-22 16:31:26 -05:00
|
|
|
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
|
2020-05-18 11:26:44 -04:00
|
|
|
Reference: imgName,
|
2017-11-22 16:31:26 -05:00
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
image2, _, err := client.ImageInspectWithRaw(ctx, commitResp2.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
expectedEnv2 := []string{"PATH=/usr/bin:/bin"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(expectedEnv2, image2.Config.Env))
|
2017-11-22 16:31:26 -05:00
|
|
|
}
|