mirror of
https://github.com/containers/podman.git
synced 2025-12-05 12:52:12 +08:00
Merge pull request #20657 from nalind/commit-config
RHEL-14922: accept a config blob alongside the "changes" slice when committing
This commit is contained in:
30
test/apiv2/14-commit.at
Normal file
30
test/apiv2/14-commit.at
Normal file
@@ -0,0 +1,30 @@
|
||||
# Create a container for testing the container initializing later
|
||||
podman create -t -i --name myctr $IMAGE ls
|
||||
|
||||
config=$(mktemp -t config.XXXXXXXXXX.json)
|
||||
cat > "$config" <<- EOF
|
||||
{
|
||||
"Entrypoint": ["/bin/crash"],
|
||||
"Cmd": ["and", "burn"],
|
||||
"Labels": {"for": "ever", "and": "ever"}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create a new image based on the container
|
||||
t POST 'libpod/commit?container=myctr&repo=nativeimage&tag=1' $config 200
|
||||
|
||||
# Check some things
|
||||
t GET libpod/images/nativeimage:1/json 200 ".Config.Cmd=$(jq .Cmd $config)" ".Config.Entrypoint=$(jq .Entrypoint $config)"
|
||||
|
||||
# Create a new image based on the container
|
||||
t POST 'commit?container=myctr&repo=compatimage&tag=1' $config 201
|
||||
|
||||
# Check some things
|
||||
t GET images/compatimage:1/json 200 ".Config.Cmd=$(jq .Cmd $config)" ".Config.Entrypoint=$(jq .Entrypoint $config)"
|
||||
|
||||
# Clean up
|
||||
t DELETE containers/myctr 204
|
||||
t DELETE images/nativeimage:1 200
|
||||
t DELETE images/compatimage:1 200
|
||||
rm -f "$config"
|
||||
unset config
|
||||
@@ -21,7 +21,7 @@ var _ = Describe("Podman commit", func() {
|
||||
session := podmanTest.Podman([]string{"commit", "test1", "--change", "BOGUS=foo", "foobar.com/test1-image:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(125))
|
||||
Expect(session.ErrorToString()).To(Equal("Error: invalid change \"BOGUS=foo\" - invalid instruction BOGUS"))
|
||||
Expect(session.ErrorToString()).To(HaveSuffix(`applying changes: processing change "BOGUS foo": did not understand change instruction "BOGUS foo"`))
|
||||
|
||||
session = podmanTest.Podman([]string{"commit", "test1", "foobar.com/test1-image:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
@@ -127,6 +127,45 @@ var _ = Describe("Podman commit", func() {
|
||||
Expect(inspectResults[0].Labels).To(HaveKeyWithValue("image", "blue"))
|
||||
})
|
||||
|
||||
It("podman commit container with --config flag", func() {
|
||||
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
||||
test.WaitWithDefaultTimeout()
|
||||
Expect(test).Should(ExitCleanly())
|
||||
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||
|
||||
configFile, err := os.CreateTemp(podmanTest.TempDir, "")
|
||||
Expect(err).Should(Succeed())
|
||||
_, err = configFile.WriteString(`{"Labels":{"image":"green"}}`)
|
||||
Expect(err).Should(Succeed())
|
||||
configFile.Close()
|
||||
|
||||
session := podmanTest.Podman([]string{"commit", "-q", "--config", configFile.Name(), "test1", "foobar.com/test1-image:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
||||
check.WaitWithDefaultTimeout()
|
||||
inspectResults := check.InspectImageJSON()
|
||||
Expect(inspectResults[0].Labels).To(HaveKeyWithValue("image", "green"))
|
||||
})
|
||||
|
||||
It("podman commit container with --config pointing to trash", func() {
|
||||
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
||||
test.WaitWithDefaultTimeout()
|
||||
Expect(test).Should(ExitCleanly())
|
||||
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||
|
||||
configFile, err := os.CreateTemp(podmanTest.TempDir, "")
|
||||
Expect(err).Should(Succeed())
|
||||
_, err = configFile.WriteString("this is not valid JSON\n")
|
||||
Expect(err).Should(Succeed())
|
||||
configFile.Close()
|
||||
|
||||
session := podmanTest.Podman([]string{"commit", "-q", "--config", configFile.Name(), "test1", "foobar.com/test1-image:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Not(ExitCleanly()))
|
||||
})
|
||||
|
||||
It("podman commit container with --squash", func() {
|
||||
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
||||
test.WaitWithDefaultTimeout()
|
||||
|
||||
Reference in New Issue
Block a user