Merge pull request #10750 from tianon/cirros-tar

Update cirros.tar.gz handling to be more agnostic of running within the image
This commit is contained in:
Jessie Frazelle 2015-02-19 12:32:09 -08:00
commit eefe6c2831
3 changed files with 34 additions and 26 deletions

View File

@ -110,9 +110,6 @@ RUN gem install --no-rdoc --no-ri fpm --version 1.3.2
# Get the "busybox" image source so we can build locally instead of pulling # Get the "busybox" image source so we can build locally instead of pulling
RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox
# Get the "cirros" image source so we can import it instead of fetching it during tests
RUN curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz
# Install registry # Install registry
ENV REGISTRY_COMMIT c448e0416925a9876d5576e412703c9b8b865e19 ENV REGISTRY_COMMIT c448e0416925a9876d5576e412703c9b8b865e19
RUN set -x \ RUN set -x \

View File

@ -206,18 +206,18 @@ func TestEventsImagePull(t *testing.T) {
func TestEventsImageImport(t *testing.T) { func TestEventsImageImport(t *testing.T) {
since := time.Now().Unix() since := time.Now().Unix()
defer deleteImages("cirros") runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
server, err := fileServer(map[string]string{
"/cirros.tar.gz": "/cirros.tar.gz",
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal("failed to create a container", out, err)
} }
defer server.Close() cleanedContainerID := stripTrailingCharacters(out)
fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL) defer deleteContainer(cleanedContainerID)
importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros")
out, _, err := runCommandWithOutput(importCmd) out, _, err = runCommandPipelineWithOutput(
exec.Command(dockerBinary, "export", cleanedContainerID),
exec.Command(dockerBinary, "import", "-"),
)
if err != nil { if err != nil {
t.Errorf("import failed with errors: %v, output: %q", err, out) t.Errorf("import failed with errors: %v, output: %q", err, out)
} }

View File

@ -1,32 +1,43 @@
package main package main
import ( import (
"fmt"
"os/exec" "os/exec"
"strings" "strings"
"testing" "testing"
) )
func TestImportDisplay(t *testing.T) { func TestImportDisplay(t *testing.T) {
server, err := fileServer(map[string]string{ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
"/cirros.tar.gz": "/cirros.tar.gz", out, _, err := runCommandWithOutput(runCmd)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal("failed to create a container", out, err)
} }
defer server.Close() cleanedContainerID := stripTrailingCharacters(out)
fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL) defer deleteContainer(cleanedContainerID)
importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros")
out, _, err := runCommandWithOutput(importCmd) out, _, err = runCommandPipelineWithOutput(
exec.Command(dockerBinary, "export", cleanedContainerID),
exec.Command(dockerBinary, "import", "-"),
)
if err != nil { if err != nil {
t.Errorf("import failed with errors: %v, output: %q", err, out) t.Errorf("import failed with errors: %v, output: %q", err, out)
} }
if n := strings.Count(out, "\n"); n != 2 { if n := strings.Count(out, "\n"); n != 1 {
t.Fatalf("display is messed up: %d '\\n' instead of 2", n) t.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
}
image := strings.TrimSpace(out)
defer deleteImages(image)
runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
t.Fatal("failed to create a container", out, err)
} }
deleteImages("cirros") if out != "" {
t.Fatalf("command output should've been nothing, was %q", out)
}
logDone("import - cirros was imported and display is fine") logDone("import - display is fine, imported image runs")
} }