Unpack tar from GCS bucket

This commit is contained in:
Priya Wadhwa
2018-03-26 13:59:56 -07:00
parent d9c31044b9
commit 85bbb6edff
6 changed files with 186 additions and 20 deletions
@@ -0,0 +1,2 @@
FROM gcr.io/distroless/base:latest
COPY baz /tmp/baz
@@ -0,0 +1,12 @@
[
{
"Image1": "gcr.io/kbuild-test/docker-test-bucket-buildcontext:latest",
"Image2": "gcr.io/kbuild-test/kbuild-test-bucket-buildcontext:latest",
"DiffType": "File",
"Diff": {
"Adds": null,
"Dels": null,
"Mods": null
}
}
]
+50 -20
View File
@@ -22,41 +22,69 @@ import (
"gopkg.in/yaml.v2"
)
const (
executorImage = "executor-image"
executorCommand = "/kbuild/executor"
dockerImage = "gcr.io/cloud-builders/docker"
ubuntuImage = "ubuntu"
testRepo = "gcr.io/kbuild-test/"
dockerPrefix = "docker-"
kbuildPrefix = "kbuild-"
daemonPrefix = "daemon://"
containerDiffOutputFile = "container-diff.json"
kbuildTestBucket = "kbuild-test-bucket"
buildcontextPath = "/workspace/integration_tests"
dockerfilesPath = "/workspace/integration_tests/dockerfiles"
)
var fileTests = []struct {
description string
dockerfilePath string
configPath string
context string
dockerContext string
kbuildContext string
repo string
}{
{
description: "test extract filesystem",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_extract_fs",
configPath: "/workspace/integration_tests/dockerfiles/config_test_extract_fs.json",
context: "integration_tests/dockerfiles/",
dockerContext: dockerfilesPath,
kbuildContext: dockerfilesPath,
repo: "extract-filesystem",
},
{
description: "test run",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_run",
configPath: "/workspace/integration_tests/dockerfiles/config_test_run.json",
context: "integration_tests/dockerfiles/",
dockerContext: dockerfilesPath,
kbuildContext: dockerfilesPath,
repo: "test-run",
},
{
description: "test run no files changed",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_run_2",
configPath: "/workspace/integration_tests/dockerfiles/config_test_run_2.json",
context: "integration_tests/dockerfiles/",
dockerContext: dockerfilesPath,
kbuildContext: dockerfilesPath,
repo: "test-run-2",
},
{
description: "test copy",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_copy",
configPath: "/workspace/integration_tests/dockerfiles/config_test_copy.json",
context: "/workspace/integration_tests/",
dockerContext: buildcontextPath,
kbuildContext: buildcontextPath,
repo: "test-copy",
},
{
description: "test bucket build context",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_copy",
configPath: "/workspace/integration_tests/dockerfiles/config_test_bucket_buildcontext.json",
dockerContext: buildcontextPath,
kbuildContext: kbuildTestBucket,
repo: "test-bucket-buildcontext",
},
}
var structureTests = []struct {
@@ -64,13 +92,15 @@ var structureTests = []struct {
dockerfilePath string
structureTestYamlPath string
dockerBuildContext string
kbuildContext string
repo string
}{
{
description: "test env",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_env",
repo: "test-env",
dockerBuildContext: "/workspace/integration_tests/dockerfiles/",
dockerBuildContext: dockerfilesPath,
kbuildContext: dockerfilesPath,
structureTestYamlPath: "/workspace/integration_tests/dockerfiles/test_env.yaml",
},
}
@@ -85,16 +115,6 @@ type testyaml struct {
Steps []step
}
var executorImage = "executor-image"
var executorCommand = "/kbuild/executor"
var dockerImage = "gcr.io/cloud-builders/docker"
var ubuntuImage = "ubuntu"
var testRepo = "gcr.io/kbuild-test/"
var dockerPrefix = "docker-"
var kbuildPrefix = "kbuild-"
var daemonPrefix = "daemon://"
var containerDiffOutputFile = "container-diff.json"
func main() {
// First, copy container-diff in
@@ -114,27 +134,37 @@ func main() {
Name: ubuntuImage,
Args: []string{"chmod", "+x", "container-structure-test"},
}
GCSBucketTarBuildContext := step{
Name: ubuntuImage,
Args: []string{"tar", "-C", "/workspace/integration_tests/", "-cf", "/workspace/kbuild.tar", "."},
}
uploadTarBuildContext := step{
Name: "gcr.io/cloud-builders/gsutil",
Args: []string{"cp", "/workspace/kbuild.tar", "gs://kbuild-test-bucket/"},
}
// Build executor image
buildExecutorImage := step{
Name: dockerImage,
Args: []string{"build", "-t", executorImage, "-f", "deploy/Dockerfile", "."},
}
y := testyaml{
Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, buildExecutorImage},
Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, GCSBucketTarBuildContext, uploadTarBuildContext, buildExecutorImage},
}
for _, test := range fileTests {
// First, build the image with docker
dockerImageTag := testRepo + dockerPrefix + test.repo
dockerBuild := step{
Name: dockerImage,
Args: []string{"build", "-t", dockerImageTag, "-f", test.dockerfilePath, test.context},
Args: []string{"build", "-t", dockerImageTag, "-f", test.dockerfilePath, test.dockerContext},
}
// Then, buld the image with kbuild
kbuildImage := testRepo + kbuildPrefix + test.repo
kbuild := step{
Name: executorImage,
Args: []string{executorCommand, "--destination", kbuildImage, "--dockerfile", test.dockerfilePath, "--context", test.context},
Args: []string{executorCommand, "--destination", kbuildImage, "--dockerfile", test.dockerfilePath, "--context", test.kbuildContext},
}
// Pull the kbuild image
@@ -178,7 +208,7 @@ func main() {
kbuildImage := testRepo + kbuildPrefix + test.repo
kbuild := step{
Name: executorImage,
Args: []string{executorCommand, "--destination", kbuildImage, "--dockerfile", test.dockerfilePath},
Args: []string{executorCommand, "--destination", kbuildImage, "--dockerfile", test.dockerfilePath, "--context", test.kbuildContext},
}
// Pull the kbuild image
pullKbuildImage := step{