Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing in version on provider build #486

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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} ./...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions provider/cmd/pulumi-resource-pulumiservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
2 changes: 1 addition & 1 deletion provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions provider/pkg/provider/serve.go

This file was deleted.

18 changes: 0 additions & 18 deletions provider/pkg/version/version.go

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/java/build.gradle

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

Loading