diff --git a/Dockerfile.apiserver b/Dockerfile.apiserver index 4c02dcc954..205425fb36 100644 --- a/Dockerfile.apiserver +++ b/Dockerfile.apiserver @@ -25,13 +25,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ ARG VERSION ARG BUILD_TIMESTAMP ARG COMMIT_HASH +ARG BUILD_OPTS ENV CGO_ENABLED=1 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=bind,source=.,target=/build,ro \ - xx-go build -ldflags="-s -w -extldflags -static \ + xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \ -X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \ -X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \ diff --git a/Dockerfile.cli b/Dockerfile.cli index 3aed7d9b62..8453b6fdf5 100644 --- a/Dockerfile.cli +++ b/Dockerfile.cli @@ -26,13 +26,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ ARG VERSION ARG BUILD_TIMESTAMP ARG COMMIT_HASH +ARG BUILD_OPTS -ENV CGO_ENABLED=0 +ENV CGO_ENABLED=1 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=bind,source=.,target=/build,ro \ - xx-go build -ldflags="-s -w -extldflags -static \ + xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \ -X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \ -X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \ diff --git a/Dockerfile.cr-discovery-server b/Dockerfile.cr-discovery-server index 721004bb40..e2095dba30 100644 --- a/Dockerfile.cr-discovery-server +++ b/Dockerfile.cr-discovery-server @@ -25,13 +25,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ ARG VERSION ARG BUILD_TIMESTAMP ARG COMMIT_HASH +ARG BUILD_OPTS -ENV CGO_ENABLED=0 +ENV CGO_ENABLED=1 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=bind,source=.,target=/build,ro \ - xx-go build -ldflags="-s -w -extldflags -static \ + xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \ -X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \ -X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \ diff --git a/Dockerfile.orchestrator b/Dockerfile.orchestrator index 1dfce85915..1b47628c7b 100644 --- a/Dockerfile.orchestrator +++ b/Dockerfile.orchestrator @@ -25,13 +25,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ ARG VERSION ARG BUILD_TIMESTAMP ARG COMMIT_HASH +ARG BUILD_OPTS ENV CGO_ENABLED=1 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=bind,source=.,target=/build,ro \ - xx-go build -ldflags="-s -w -extldflags -static \ + xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \ -X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \ -X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \ diff --git a/Dockerfile.uibackend b/Dockerfile.uibackend index f2fa9a9679..c15a58f73b 100644 --- a/Dockerfile.uibackend +++ b/Dockerfile.uibackend @@ -25,13 +25,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \ ARG VERSION ARG BUILD_TIMESTAMP ARG COMMIT_HASH +ARG BUILD_OPTS -ENV CGO_ENABLED=0 +ENV CGO_ENABLED=1 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=bind,source=.,target=/build,ro \ - xx-go build -ldflags="-s -w -extldflags -static \ + xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \ -X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \ -X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \ diff --git a/Makefile b/Makefile index 4acb65be85..c805ab2f3d 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ DOCKER_REGISTRY ?= ghcr.io/openclarity DOCKER_TAG ?= $(VERSION) VMCLARITY_TOOLS_BASE ?= GO_VERSION ?= $(shell cat $(ROOT_DIR)/.go-version) +GO_BUILD_TAGS ?= #### ## Runtime variables @@ -56,25 +57,30 @@ build: ui build-all-go ## Build all components .PHONY: build-all-go build-all-go: bin/vmclarity-apiserver bin/vmclarity-cli bin/vmclarity-orchestrator bin/vmclarity-ui-backend bin/vmclarity-cr-discovery-server ## Build all go components +BUILD_OPTS = -race +ifneq ($(GO_BUILD_TAGS),) +BUILD_OPTS += -tags $(GO_BUILD_TAGS) +endif + LDFLAGS = -s -w LDFLAGS += -X 'github.com/openclarity/vmclarity/core/version.Version=$(VERSION)' LDFLAGS += -X 'github.com/openclarity/vmclarity/core/version.CommitHash=$(COMMIT_HASH)' LDFLAGS += -X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=$(BUILD_TIMESTAMP)' bin/vmclarity-orchestrator: $(shell find api provider orchestrator utils core) | $(BIN_DIR) - cd orchestrator && go build -race -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go + cd orchestrator && go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go bin/vmclarity-apiserver: $(shell find api api/server) | $(BIN_DIR) - cd api/server && go build -race -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go + cd api/server && go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go bin/vmclarity-cli: $(shell find api cli utils core) | $(BIN_DIR) - cd cli && go build -race -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go + cd cli && go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go bin/vmclarity-ui-backend: $(shell find api uibackend/server) | $(BIN_DIR) - cd uibackend/server && go build -race -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go + cd uibackend/server && go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go bin/vmclarity-cr-discovery-server: $(shell find api containerruntimediscovery/server utils core) | $(BIN_DIR) - cd containerruntimediscovery/server && go build -race -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go + cd containerruntimediscovery/server && go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" -o $(ROOT_DIR)/$@ cmd/main.go .PHONY: clean clean: clean-ui clean-go ## Clean all build artifacts @@ -215,6 +221,7 @@ BAKE_ENV += DOCKER_TAG=$(DOCKER_TAG) BAKE_ENV += VERSION=$(VERSION) BAKE_ENV += BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) BAKE_ENV += COMMIT_HASH=$(COMMIT_HASH) +BAKE_ENV += BUILD_OPTS="$(BUILD_OPTS)" BAKE_OPTS = ifneq ($(strip $(VMCLARITY_TOOLS_BASE)),) diff --git a/docker-bake.hcl b/docker-bake.hcl index 70da4723d2..141f3c29c1 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -10,6 +10,7 @@ variable "VERSION" {default = null} variable "BUILD_TIMESTAMP" {default = null} variable "COMMIT_HASH" {default = null} variable "VMCLARITY_TOOLS_BASE" {default = null} +variable "BUILD_OPTS" {default = null} function "get_tag" { params = [name] @@ -40,6 +41,7 @@ target "_common_args_for_go" { VERSION = "${VERSION}" BUILD_TIMESTAMP = "${BUILD_TIMESTAMP}" COMMIT_HASH = "${COMMIT_HASH}" + BUILD_OPTS = "${BUILD_OPTS}" } } diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index 8f60a63429..f330fb2552 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -23,7 +23,6 @@ import ( "github.com/Portshift/go-utils/healthz" apiclient "github.com/openclarity/vmclarity/api/client" - apitypes "github.com/openclarity/vmclarity/api/types" "github.com/openclarity/vmclarity/core/log" discovery "github.com/openclarity/vmclarity/orchestrator/discoverer" assetscanprocessor "github.com/openclarity/vmclarity/orchestrator/processor/assetscan" @@ -33,12 +32,6 @@ import ( scanconfigwatcher "github.com/openclarity/vmclarity/orchestrator/watcher/scanconfig" scanestimationwatcher "github.com/openclarity/vmclarity/orchestrator/watcher/scanestimation" "github.com/openclarity/vmclarity/provider" - "github.com/openclarity/vmclarity/provider/aws" - "github.com/openclarity/vmclarity/provider/azure" - "github.com/openclarity/vmclarity/provider/docker" - "github.com/openclarity/vmclarity/provider/external" - "github.com/openclarity/vmclarity/provider/gcp" - "github.com/openclarity/vmclarity/provider/kubernetes" ) type Orchestrator struct { @@ -126,24 +119,3 @@ func (o *Orchestrator) Stop(ctx context.Context) { o.cancelFunc() } } - -// nolint:wrapcheck -// NewProvider returns an initialized provider.Provider based on the kind apitypes.CloudProvider. -func NewProvider(ctx context.Context, kind apitypes.CloudProvider) (provider.Provider, error) { - switch kind { - case apitypes.Azure: - return azure.New(ctx) - case apitypes.Docker: - return docker.New(ctx) - case apitypes.AWS: - return aws.New(ctx) - case apitypes.GCP: - return gcp.New(ctx) - case apitypes.External: - return external.New(ctx) - case apitypes.Kubernetes: - return kubernetes.New(ctx) - default: - return nil, fmt.Errorf("unsupported provider: %s", kind) - } -} diff --git a/orchestrator/provider.go b/orchestrator/provider.go new file mode 100644 index 0000000000..fd2e91cb75 --- /dev/null +++ b/orchestrator/provider.go @@ -0,0 +1,53 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// 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. + +//go:build !providerv2 + +package orchestrator + +import ( + "context" + "fmt" + + apitypes "github.com/openclarity/vmclarity/api/types" + "github.com/openclarity/vmclarity/provider" + "github.com/openclarity/vmclarity/provider/aws" + "github.com/openclarity/vmclarity/provider/azure" + "github.com/openclarity/vmclarity/provider/docker" + "github.com/openclarity/vmclarity/provider/external" + "github.com/openclarity/vmclarity/provider/gcp" + "github.com/openclarity/vmclarity/provider/kubernetes" +) + +// nolint:wrapcheck +// NewProvider returns an initialized provider.Provider based on the kind apitypes.CloudProvider. +func NewProvider(ctx context.Context, kind apitypes.CloudProvider) (provider.Provider, error) { + switch kind { + case apitypes.Azure: + return azure.New(ctx) + case apitypes.Docker: + return docker.New(ctx) + case apitypes.AWS: + return aws.New(ctx) + case apitypes.GCP: + return gcp.New(ctx) + case apitypes.External: + return external.New(ctx) + case apitypes.Kubernetes: + return kubernetes.New(ctx) + default: + return nil, fmt.Errorf("unsupported provider: %s", kind) + } +} diff --git a/orchestrator/providerv2.go b/orchestrator/providerv2.go new file mode 100644 index 0000000000..b12ce10094 --- /dev/null +++ b/orchestrator/providerv2.go @@ -0,0 +1,53 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// 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. + +//go:build providerv2 + +package orchestrator + +import ( + "context" + "fmt" + + apitypes "github.com/openclarity/vmclarity/api/types" + provider2 "github.com/openclarity/vmclarity/provider" + "github.com/openclarity/vmclarity/provider/docker" + "github.com/openclarity/vmclarity/provider/external" + "github.com/openclarity/vmclarity/provider/kubernetes" + "github.com/openclarity/vmclarity/provider/v2/aws" + "github.com/openclarity/vmclarity/provider/v2/azure" + "github.com/openclarity/vmclarity/provider/v2/gcp" +) + +// nolint:wrapcheck +// NewProvider returns an initialized provider.Provider based on the kind apitypes.CloudProvider. +func NewProvider(ctx context.Context, kind apitypes.CloudProvider) (provider2.Provider, error) { + switch kind { + case apitypes.Azure: + return azure.New(ctx) + case apitypes.Docker: + return docker.New(ctx) + case apitypes.AWS: + return aws.New(ctx) + case apitypes.GCP: + return gcp.New(ctx) + case apitypes.External: + return external.New(ctx) + case apitypes.Kubernetes: + return kubernetes.New(ctx) + default: + return nil, fmt.Errorf("unsupported provider: %s", kind) + } +}