Skip to content

Commit

Permalink
Rewrite framework to run as standalone binary instead of testing modu…
Browse files Browse the repository at this point in the history
…le (#68)
  • Loading branch information
nkubala authored Mar 19, 2018
1 parent 48b8991 commit 2485b8b
Show file tree
Hide file tree
Showing 57 changed files with 1,804 additions and 1,269 deletions.
46 changes: 19 additions & 27 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_prefix", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_prefix")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")

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

go_library(
name = "go_default_library",
srcs = ["types.go"],
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
deps = [
"//drivers:go_default_library",
"//types/v1:go_default_library",
"//types/v2:go_default_library",
],
)

go_binary(
name = "structure_tests",
embed = [":go_default_library"],
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
)

go_test(
name = "go_default_test",
testonly = True,
srcs = ["structure_test.go"],
embed = [":go_default_library"],
name = "structure_test",
srcs = ["main.go"],
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
pure = "on",
deps = [
"//drivers:go_default_library",
"//utils:go_default_library",
"//cmd:go_default_library",
"//pkg/drivers:go_default_library",
"//pkg/utils:go_default_library",
"//vendor/github.com/fsouza/go-dockerclient:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
],
)

container_image(
name = "structure_test_image",
testonly = True,
base = "@distroless_base//image",
entrypoint = ["/go_default_test"],
files = [":go_default_test"],
entrypoint = ["/structure_test"],
files = [":structure_test"],
)

go_prefix("github.com/GoogleCloudPlatform/container-structure-test")
Expand All @@ -66,3 +48,13 @@ go_binary(
embed = [":go_default_library"],
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
)

go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/GoogleCloudPlatform/container-structure-test",
deps = [
"//cmd:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)
30 changes: 6 additions & 24 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

[[constraint]]
name = "github.com/GoogleCloudPlatform/container-diff"
revision = "9ba9d88a7caac4d74d4ca39700b5c62331005785"
revision = "d2b317ec63b9e9db4ad6a4065399d74c9b7ebd78"

[[constraint]]
name = "github.com/fsouza/go-dockerclient"
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
# limitations under the License.

# Bump these on release
VERSION_MAJOR ?= 0
VERSION_MINOR ?= 3
VERSION_MAJOR ?= 1
VERSION_MINOR ?= 0
VERSION_BUILD ?= 0

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

GOOS ?= $(shell go env GOOS)
GOARCH = amd64
PROJECT := structure-test
PROJECT := container-structure-test
RELEASE_BUCKET ?= gcp-container-tools/structure-test

LD_FLAGS := -X github.com/GoogleCloudPlatform/container-structure-test/pkg/version.version=$(VERSION)

SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH)

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

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

%.sha256: %
shasum -a 256 $< &> $@
Expand Down
24 changes: 24 additions & 0 deletions cmd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"root.go",
"test.go",
"version.go",
],
importpath = "github.com/GoogleCloudPlatform/container-structure-test/cmd",
visibility = ["//visibility:public"],
deps = [
"//pkg/drivers:go_default_library",
"//pkg/output:go_default_library",
"//pkg/types:go_default_library",
"//pkg/types/unversioned:go_default_library",
"//pkg/utils:go_default_library",
"//pkg/version:go_default_library",
"//vendor/github.com/fsouza/go-dockerclient:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
],
)
50 changes: 50 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.

package cmd

import (
"fmt"
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var logLevel string
var imagePath, driver, metadata string
var save, pull, force, quiet, verbose bool

var configFiles []string

var RootCmd = &cobra.Command{
Use: "container-structure-test",
Short: "container-structure-test provides a framework to test the structure of a container image",
Long: `container-structure-test provides a powerful framework to validate
the structure of a container image.
These tests can be used to check the output of commands in an image,
as well as verify metadata and contents of the filesystem.`,
PersistentPreRun: func(c *cobra.Command, s []string) {
ll, err := logrus.ParseLevel(logLevel)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
logrus.SetLevel(ll)
},
}

func init() {
RootCmd.PersistentFlags().StringVar(&logLevel, "logLevel", "warning", "This flag controls the verbosity of container-structure-test.")
}
Loading

0 comments on commit 2485b8b

Please sign in to comment.