Skip to content

Commit 2485b8b

Browse files
authored
Rewrite framework to run as standalone binary instead of testing module (#68)
1 parent 48b8991 commit 2485b8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1804
-1269
lines changed

BUILD.bazel

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_prefix", "go_test")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_prefix")
22
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
33

44
licenses(["notice"])
@@ -19,44 +19,26 @@ sh_binary(
1919
srcs = ["ext_run.sh"],
2020
)
2121

22-
go_library(
23-
name = "go_default_library",
24-
srcs = ["types.go"],
25-
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
26-
deps = [
27-
"//drivers:go_default_library",
28-
"//types/v1:go_default_library",
29-
"//types/v2:go_default_library",
30-
],
31-
)
32-
3322
go_binary(
34-
name = "structure_tests",
35-
embed = [":go_default_library"],
36-
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
37-
)
38-
39-
go_test(
40-
name = "go_default_test",
41-
testonly = True,
42-
srcs = ["structure_test.go"],
43-
embed = [":go_default_library"],
23+
name = "structure_test",
24+
srcs = ["main.go"],
4425
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
4526
pure = "on",
4627
deps = [
47-
"//drivers:go_default_library",
48-
"//utils:go_default_library",
28+
"//cmd:go_default_library",
29+
"//pkg/drivers:go_default_library",
30+
"//pkg/utils:go_default_library",
4931
"//vendor/github.com/fsouza/go-dockerclient:go_default_library",
32+
"//vendor/github.com/sirupsen/logrus:go_default_library",
5033
"//vendor/gopkg.in/yaml.v2:go_default_library",
5134
],
5235
)
5336

5437
container_image(
5538
name = "structure_test_image",
56-
testonly = True,
5739
base = "@distroless_base//image",
58-
entrypoint = ["/go_default_test"],
59-
files = [":go_default_test"],
40+
entrypoint = ["/structure_test"],
41+
files = [":structure_test"],
6042
)
6143

6244
go_prefix("github.com/GoogleCloudPlatform/container-structure-test")
@@ -66,3 +48,13 @@ go_binary(
6648
embed = [":go_default_library"],
6749
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
6850
)
51+
52+
go_library(
53+
name = "go_default_library",
54+
srcs = ["main.go"],
55+
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
56+
deps = [
57+
"//cmd:go_default_library",
58+
"//vendor/github.com/sirupsen/logrus:go_default_library",
59+
],
60+
)

Gopkg.lock

Lines changed: 6 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
[[constraint]]
2525
name = "github.com/GoogleCloudPlatform/container-diff"
26-
revision = "9ba9d88a7caac4d74d4ca39700b5c62331005785"
26+
revision = "d2b317ec63b9e9db4ad6a4065399d74c9b7ebd78"
2727

2828
[[constraint]]
2929
name = "github.com/fsouza/go-dockerclient"

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
# limitations under the License.
1414

1515
# Bump these on release
16-
VERSION_MAJOR ?= 0
17-
VERSION_MINOR ?= 3
16+
VERSION_MAJOR ?= 1
17+
VERSION_MINOR ?= 0
1818
VERSION_BUILD ?= 0
1919

2020
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
2121

2222
GOOS ?= $(shell go env GOOS)
2323
GOARCH = amd64
24-
PROJECT := structure-test
24+
PROJECT := container-structure-test
2525
RELEASE_BUCKET ?= gcp-container-tools/structure-test
2626

27+
LD_FLAGS := -X github.com/GoogleCloudPlatform/container-structure-test/pkg/version.version=$(VERSION)
28+
2729
SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH)
2830

2931
BUILD_DIR ?= ./out
@@ -34,7 +36,7 @@ $(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
3436
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@
3537

3638
$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
37-
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go test -c . -o $@
39+
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="$(LD_FLAGS)" -o $@ .
3840

3941
%.sha256: %
4042
shasum -a 256 $< &> $@

cmd/BUILD.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"root.go",
7+
"test.go",
8+
"version.go",
9+
],
10+
importpath = "github.com/GoogleCloudPlatform/container-structure-test/cmd",
11+
visibility = ["//visibility:public"],
12+
deps = [
13+
"//pkg/drivers:go_default_library",
14+
"//pkg/output:go_default_library",
15+
"//pkg/types:go_default_library",
16+
"//pkg/types/unversioned:go_default_library",
17+
"//pkg/utils:go_default_library",
18+
"//pkg/version:go_default_library",
19+
"//vendor/github.com/fsouza/go-dockerclient:go_default_library",
20+
"//vendor/github.com/sirupsen/logrus:go_default_library",
21+
"//vendor/github.com/spf13/cobra:go_default_library",
22+
"//vendor/gopkg.in/yaml.v2:go_default_library",
23+
],
24+
)

cmd/root.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2018 Google Inc. All rights reserved.
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
"github.com/sirupsen/logrus"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
var logLevel string
26+
var imagePath, driver, metadata string
27+
var save, pull, force, quiet, verbose bool
28+
29+
var configFiles []string
30+
31+
var RootCmd = &cobra.Command{
32+
Use: "container-structure-test",
33+
Short: "container-structure-test provides a framework to test the structure of a container image",
34+
Long: `container-structure-test provides a powerful framework to validate
35+
the structure of a container image.
36+
These tests can be used to check the output of commands in an image,
37+
as well as verify metadata and contents of the filesystem.`,
38+
PersistentPreRun: func(c *cobra.Command, s []string) {
39+
ll, err := logrus.ParseLevel(logLevel)
40+
if err != nil {
41+
fmt.Println(err)
42+
os.Exit(1)
43+
}
44+
logrus.SetLevel(ll)
45+
},
46+
}
47+
48+
func init() {
49+
RootCmd.PersistentFlags().StringVar(&logLevel, "logLevel", "warning", "This flag controls the verbosity of container-structure-test.")
50+
}

0 commit comments

Comments
 (0)