Merge branch 'master' of github.com:GoogleCloudPlatform/k8s-container-builder into snapshot
This commit is contained in:
commit
7456e9de9a
|
|
@ -0,0 +1 @@
|
||||||
|
vendor/
|
||||||
|
|
@ -292,6 +292,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "c5933c09ead2842baa85dcb4321cef9623f4ab6ec4f6c84b6579071aa1baf3e4"
|
inputs-digest = "6e9d101389852c13c0a3dc486d69b0438b6518c42d9031e3bf0c41d7d1943438"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
||||||
12
Makefile
12
Makefile
|
|
@ -23,20 +23,28 @@ GOOS ?= $(shell go env GOOS)
|
||||||
GOARCH = amd64
|
GOARCH = amd64
|
||||||
ORG := github.com/GoogleCloudPlatform
|
ORG := github.com/GoogleCloudPlatform
|
||||||
PROJECT := k8s-container-builder
|
PROJECT := k8s-container-builder
|
||||||
|
REGISTRY?=gcr.io/kbuild-project
|
||||||
|
|
||||||
REPOPATH ?= $(ORG)/$(PROJECT)
|
REPOPATH ?= $(ORG)/$(PROJECT)
|
||||||
|
|
||||||
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
||||||
|
GO_LDFLAGS := '-extldflags "-static"'
|
||||||
|
GO_BUILD_TAGS := "containers_image_ostree_stub containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs"
|
||||||
|
|
||||||
EXECUTOR_PACKAGE = $(REPOPATH)/executor
|
EXECUTOR_PACKAGE = $(REPOPATH)/executor
|
||||||
KBUILD_PACKAGE = $(REPOPATH)/kbuild
|
KBUILD_PACKAGE = $(REPOPATH)/kbuild
|
||||||
|
|
||||||
out/executor: $(GO_FILES)
|
out/executor: $(GO_FILES)
|
||||||
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -o $@ $(EXECUTOR_PACKAGE)
|
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(EXECUTOR_PACKAGE)
|
||||||
|
|
||||||
|
|
||||||
out/kbuild: $(GO_FILES)
|
out/kbuild: $(GO_FILES)
|
||||||
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -o $@ $(KBUILD_PACKAGE)
|
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(KBUILD_PACKAGE)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: out/executor out/kbuild
|
test: out/executor out/kbuild
|
||||||
@ ./test.sh
|
@ ./test.sh
|
||||||
|
|
||||||
|
.PHONY: integration-test
|
||||||
|
integration-test: out/executor out/kbuild
|
||||||
|
@ ./integration-test.sh
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Copyright 2018 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Running integration tests..."
|
||||||
|
go run integration_tests/integration_test_yaml.go | gcloud container builds submit --config /dev/fd/0 .
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Copyright 2018 Google, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
FROM gcr.io/google-appengine/debian9:latest
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Image1": "gcr.io/kbuild-test/docker-extract-filesystem:latest",
|
||||||
|
"Image2": "gcr.io/kbuild-test/kbuild-extract-filesystem:latest",
|
||||||
|
"DiffType": "File",
|
||||||
|
"Diff": {
|
||||||
|
"Adds": [
|
||||||
|
{
|
||||||
|
"Name": "/workspace",
|
||||||
|
"Size": 16271436
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/workspace/Dockerfile",
|
||||||
|
"Size": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/workspace/executor",
|
||||||
|
"Size": 16271436
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Dels": [
|
||||||
|
{
|
||||||
|
"Name": "/dev",
|
||||||
|
"Size": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/etc/hosts",
|
||||||
|
"Size": 109
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/etc/resolv.conf",
|
||||||
|
"Size": 38
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/proc",
|
||||||
|
"Size": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "/sys",
|
||||||
|
"Size": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Mods": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Copyright 2018 Google, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# Builds the static Go image to execute in a Kubernetes job
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
ADD out/executor /workspace/executor
|
||||||
|
ADD files/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 Google LLC
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tests = []struct {
|
||||||
|
description string
|
||||||
|
dockerfilePath string
|
||||||
|
configPath string
|
||||||
|
context 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/",
|
||||||
|
repo: "extract-filesystem",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type step struct {
|
||||||
|
Name string
|
||||||
|
Args []string
|
||||||
|
Env []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type testyaml struct {
|
||||||
|
Steps []step
|
||||||
|
}
|
||||||
|
|
||||||
|
var executorImage = "executor-image"
|
||||||
|
var executorCommand = "/workspace/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
|
||||||
|
containerDiffStep := step{
|
||||||
|
Name: "gcr.io/cloud-builders/gsutil",
|
||||||
|
Args: []string{"cp", "gs://container-diff/latest/container-diff-linux-amd64", "."},
|
||||||
|
}
|
||||||
|
containerDiffPermissions := step{
|
||||||
|
Name: ubuntuImage,
|
||||||
|
Args: []string{"chmod", "+x", "container-diff-linux-amd64"},
|
||||||
|
}
|
||||||
|
// Build executor image
|
||||||
|
buildExecutorImage := step{
|
||||||
|
Name: dockerImage,
|
||||||
|
Args: []string{"build", "-t", executorImage, "-f", "integration_tests/executor/Dockerfile", "."},
|
||||||
|
}
|
||||||
|
|
||||||
|
y := testyaml{
|
||||||
|
Steps: []step{containerDiffStep, containerDiffPermissions, buildExecutorImage},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
// First, build the image with docker
|
||||||
|
dockerBuild := step{
|
||||||
|
Name: dockerImage,
|
||||||
|
Args: []string{"build", "-t", testRepo + dockerPrefix + test.repo, "-f", test.dockerfilePath, test.context},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then, buld the image with kbuild and commit it
|
||||||
|
var commitID = "test"
|
||||||
|
kbuild := step{
|
||||||
|
Name: dockerImage,
|
||||||
|
Args: []string{"run", "-v", test.dockerfilePath + ":/workspace/Dockerfile", "--name", commitID, executorImage, executorCommand},
|
||||||
|
}
|
||||||
|
|
||||||
|
commit := step{
|
||||||
|
Name: dockerImage,
|
||||||
|
Args: []string{"commit", commitID, testRepo + kbuildPrefix + test.repo},
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerImage := daemonPrefix + testRepo + dockerPrefix + test.repo
|
||||||
|
kbuildImage := daemonPrefix + testRepo + kbuildPrefix + test.repo
|
||||||
|
// Run container diff on the images
|
||||||
|
args := "container-diff-linux-amd64 diff " + dockerImage + " " + kbuildImage + " --type=file -j > " + containerDiffOutputFile
|
||||||
|
containerDiff := step{
|
||||||
|
Name: ubuntuImage,
|
||||||
|
Args: []string{"sh", "-c", args},
|
||||||
|
Env: []string{"PATH=/workspace:/bin"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare output files
|
||||||
|
compareOutputs := step{
|
||||||
|
Name: ubuntuImage,
|
||||||
|
Args: []string{"cmp", test.configPath, containerDiffOutputFile},
|
||||||
|
}
|
||||||
|
|
||||||
|
y.Steps = append(y.Steps, dockerBuild, kbuild, commit, containerDiff, compareOutputs)
|
||||||
|
}
|
||||||
|
|
||||||
|
d, _ := yaml.Marshal(&y)
|
||||||
|
fmt.Println(string(d))
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue