From 8afae3ad58fd47ba3fc2ac5c2e1f6f950a967011 Mon Sep 17 00:00:00 2001 From: IaroslavTitov Date: Fri, 10 Jan 2025 16:06:33 -0700 Subject: [PATCH] Fix passing in version on provider build --- .github/workflows/build_sdk.yml | 1 + Makefile | 16 ++++------ .../cmd/pulumi-resource-pulumiservice/main.go | 18 +++++++++-- provider/pkg/provider/provider.go | 2 +- provider/pkg/provider/serve.go | 32 ------------------- provider/pkg/version/version.go | 18 ----------- sdk/java/build.gradle | 2 +- 7 files changed, 25 insertions(+), 64 deletions(-) delete mode 100644 provider/pkg/provider/serve.go delete mode 100644 provider/pkg/version/version.go diff --git a/.github/workflows/build_sdk.yml b/.github/workflows/build_sdk.yml index 33156068..af9e370a 100644 --- a/.github/workflows/build_sdk.yml +++ b/.github/workflows/build_sdk.yml @@ -75,6 +75,7 @@ jobs: sdk/go/**/pulumiUtilities.go sdk/nodejs/package.json sdk/python/pyproject.toml + sdk/java/build.gradle - name: Upload SDK uses: ./.github/actions/upload-sdk with: diff --git a/Makefile b/Makefile index 01ed129c..f053fd37 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ PROVIDER := pulumi-resource-${PACK} PROVIDER_VERSION ?= 1.0.0-alpha.0+dev # Use this normalised version everywhere rather than the raw input to ensure consistency. VERSION_GENERIC = $(shell pulumictl convert-version --language generic --version "$(PROVIDER_VERSION)") -PROVIDER_PATH := provider -VERSION_PATH := provider/pkg/version.Version +LDFLAGS := "-X main.Version=$(VERSION_GENERIC)" +BUILD_PATH := $(PROJECT)/provider/cmd/$(PROVIDER) SCHEMA_FILE := provider/cmd/pulumi-resource-pulumiservice/schema.json GOPATH := $(shell go env GOPATH) @@ -28,18 +28,16 @@ ensure:: go mod tidy cd sdk && go mod tidy -gen:: - build_sdks: dotnet_sdk go_sdk nodejs_sdk python_sdk java_sdk gen_sdk_prerequisites: $(PULUMI) provider:: (cd provider && VERSION=${VERSION_GENERIC} go generate cmd/${PROVIDER}/main.go) - (cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION_GENERIC}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER)) + (cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags $(LDFLAGS) $(BUILD_PATH)) provider_debug:: - (cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -gcflags="all=-N -l" -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION_GENERIC}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER)) + (cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -gcflags="all=-N -l" -ldflags $(LDFLAGS) $(BUILD_PATH)) test_provider:: cd provider/pkg && go test -short -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM} ./... @@ -82,13 +80,13 @@ python_sdk: gen_sdk_prerequisites java_sdk: export PULUMI_IGNORE_AMBIENT_PLUGINS = true java_sdk: gen_sdk_prerequisites rm -rf sdk/java - $(PULUMI) package gen-sdk $(SCHEMA_FILE) --language java + $(PULUMI) package gen-sdk $(SCHEMA_FILE) --language java --version $(VERSION_GENERIC) cd sdk/java && \ echo "module fake_java_module // Exclude this directory from Go tools\n\ngo 1.17" > go.mod && \ gradle --console=plain build .PHONY: build -build:: gen provider dotnet_sdk go_sdk nodejs_sdk python_sdk java_sdk +build:: provider dotnet_sdk go_sdk nodejs_sdk python_sdk java_sdk # Required for the codegen action that runs in pulumi/pulumi only_build:: build @@ -169,7 +167,7 @@ bin/%/$(PROVIDER) bin/%/$(PROVIDER).exe: export GOOS=$$(echo "$(TARGET)" | cut -d "-" -f 1) && \ export GOARCH=$$(echo "$(TARGET)" | cut -d "-" -f 2) && \ export CGO_ENABLED=0 && \ - go build -o "${WORKING_DIR}/$@" $(PULUMI_PROVIDER_BUILD_PARALLELISM) -ldflags "$(LDFLAGS)" "$(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER)" + go build -o "${WORKING_DIR}/$@" $(PULUMI_PROVIDER_BUILD_PARALLELISM) -ldflags $(LDFLAGS) $(BUILD_PATH) bin/$(PROVIDER)-v$(VERSION_GENERIC)-linux-amd64.tar.gz: bin/linux-amd64/$(PROVIDER) bin/$(PROVIDER)-v$(VERSION_GENERIC)-linux-arm64.tar.gz: bin/linux-arm64/$(PROVIDER) diff --git a/provider/cmd/pulumi-resource-pulumiservice/main.go b/provider/cmd/pulumi-resource-pulumiservice/main.go index c7723458..cefc52af 100644 --- a/provider/cmd/pulumi-resource-pulumiservice/main.go +++ b/provider/cmd/pulumi-resource-pulumiservice/main.go @@ -17,17 +17,29 @@ package main import ( _ "embed" - "github.com/pulumi/pulumi-pulumiservice/provider/pkg/provider" - "github.com/pulumi/pulumi-pulumiservice/provider/pkg/version" + psp "github.com/pulumi/pulumi-pulumiservice/provider/pkg/provider" + "github.com/pulumi/pulumi/pkg/v3/resource/provider" + "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil" + rpc "github.com/pulumi/pulumi/sdk/v3/proto/go" ) var providerName = "pulumiservice" // embed schema.json directly into resource binary so that we can properly serve the schema // directly from the resource provider +// //go:embed schema.json var schema string +// The version needs to be replaced using LDFLAGS on build +var Version string = "REPLACE_ON_BUILD" + func main() { - provider.Serve(providerName, version.Version, schema) + // Start gRPC service for the pulumiservice provider + err := provider.Main(providerName, func(host *provider.HostClient) (rpc.ResourceProviderServer, error) { + return psp.MakeProvider(host, providerName, Version, schema) + }) + if err != nil { + cmdutil.ExitError(err.Error()) + } } diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 880d31f9..fe687e0f 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -58,7 +58,7 @@ type pulumiserviceProvider struct { AccessToken string } -func makeProvider(host *provider.HostClient, name, version, schema string) (pulumirpc.ResourceProviderServer, error) { +func MakeProvider(host *provider.HostClient, name, version, schema string) (pulumirpc.ResourceProviderServer, error) { // inject version into schema versionedSchema := mustSetSchemaVersion(schema, version) // Return the new provider diff --git a/provider/pkg/provider/serve.go b/provider/pkg/provider/serve.go deleted file mode 100644 index 6d48b779..00000000 --- a/provider/pkg/provider/serve.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016-2020, Pulumi Corporation. -// -// 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 provider - -import ( - "github.com/pulumi/pulumi/pkg/v3/resource/provider" - "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil" - rpc "github.com/pulumi/pulumi/sdk/v3/proto/go" -) - -// Serve launches the gRPC server for the resource provider. -func Serve(providerName, version string, schema string) { - // Start gRPC service. - err := provider.Main(providerName, func(host *provider.HostClient) (rpc.ResourceProviderServer, error) { - return makeProvider(host, providerName, version, schema) - }) - if err != nil { - cmdutil.ExitError(err.Error()) - } -} diff --git a/provider/pkg/version/version.go b/provider/pkg/version/version.go deleted file mode 100644 index c9094d63..00000000 --- a/provider/pkg/version/version.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016-2020, Pulumi Corporation. -// -// 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 version - -// Version is initialized by the Go linker to contain the semver of this build. -var Version string = "0.0.1" diff --git a/sdk/java/build.gradle b/sdk/java/build.gradle index 80c28d73..a808147c 100644 --- a/sdk/java/build.gradle +++ b/sdk/java/build.gradle @@ -12,7 +12,7 @@ group = "com.pulumi" def resolvedVersion = System.getenv("PACKAGE_VERSION") ?: (project.version == "unspecified" - ? "0.0.1" + ? "1.0.0-alpha.0+dev" : project.version) def signingKey = System.getenv("SIGNING_KEY")