Skip to content

Commit

Permalink
feat: code parity with other native providers
Browse files Browse the repository at this point in the history
Fixes pulumi#9 and #3

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Aug 13, 2021
1 parent 41d69d6 commit 8173048
Show file tree
Hide file tree
Showing 26 changed files with 1,268 additions and 601 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/vendor/
**/bin/
**/obj/
**/node_modules/
**/.vs
**/.idea
**/.ionide
.pulumi
Pulumi.*.yaml
yarn.lock
yarn.lock
ci-scripts
/nuget/
112 changes: 112 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
PROJECT_NAME := Pulumi Xyz Resource Provider

PACK := xyz
PACKDIR := sdk
PROJECT := github.com/pulumi/pulumi-xyz
NODE_MODULE_NAME := @pulumi/xyz
NUGET_PKG_NAME := Pulumi.Xyz

PROVIDER := pulumi-resource-${PACK}
CODEGEN := pulumi-gen-${PACK}
VERSION ?= $(shell pulumictl get version)
PROVIDER_PATH := provider
VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version

SCHEMA_FILE := provider/cmd/pulumi-resource-xyz/schema.json
GOPATH := $(shell go env GOPATH)

WORKING_DIR := $(shell pwd)
TESTPARALLELISM := 4

ensure::
cd provider && go mod tidy
cd sdk && go mod tidy
cd tests && go mod tidy

gen::
(cd provider && go build -a -o $(WORKING_DIR)/bin/${CODEGEN} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/$(CODEGEN))

provider::
(cd provider && VERSION=${VERSION} go generate cmd/${PROVIDER}/main.go)
(cd provider && go build -a -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER))

provider_debug::
(cd provider && go build -a -o $(WORKING_DIR)/bin/${PROVIDER} -gcflags="all=-N -l" -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER))

test_provider::
cd provider/pkg && go test -short -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM} ./...

dotnet_sdk:: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
dotnet_sdk::
$(WORKING_DIR)/bin/$(CODEGEN) -version=${DOTNET_VERSION} dotnet $(SCHEMA_FILE) $(CURDIR)
rm -rf sdk/dotnet
cd ${PACKDIR}/dotnet/&& \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}

go_sdk::
rm -rf sdk/go
$(WORKING_DIR)/bin/$(CODEGEN) -version=${VERSION} go $(SCHEMA_FILE) $(CURDIR)

nodejs_sdk:: VERSION := $(shell pulumictl get version --language javascript)
nodejs_sdk::
rm -rf sdk/nodejs
$(WORKING_DIR)/bin/$(CODEGEN) -version=${VERSION} nodejs $(SCHEMA_FILE) $(CURDIR)
cd ${PACKDIR}/nodejs/ && \
yarn install && \
yarn run tsc
cp README.md LICENSE ${PACKDIR}/nodejs/package.json ${PACKDIR}/nodejs/yarn.lock ${PACKDIR}/nodejs/bin/
sed -i.bak 's/$${VERSION}/$(VERSION)/g' ${PACKDIR}/nodejs/bin/package.json

python_sdk:: PYPI_VERSION := $(shell pulumictl get version --language python)
python_sdk::
# Delete only files and folders that are generated.
rm -r sdk/python/pulumi_kubernetes/*/ sdk/python/pulumi_kubernetes/__init__.py
$(WORKING_DIR)/bin/$(CODEGEN) -version=${VERSION} python $(SCHEMA_FILE) $(CURDIR)
cp README.md ${PACKDIR}/python/
cd ${PACKDIR}/python/ && \
python3 setup.py clean --all 2>/dev/null && \
rm -rf ./bin/ ../python.bin/ && cp -R . ../python.bin && mv ../python.bin ./bin && \
sed -i.bak -e 's/^VERSION = .*/VERSION = "$(PYPI_VERSION)"/g' -e 's/^PLUGIN_VERSION = .*/PLUGIN_VERSION = "$(VERSION)"/g' ./bin/setup.py && \
rm ./bin/setup.py.bak && \
cd ./bin && python3 setup.py build sdist

.PHONY: build
build:: gen provider dotnet_sdk go_sdk nodejs_sdk python_sdk

# Required for the codegen action that runs in pulumi/pulumi
only_build:: build

lint::
for DIR in "provider" "sdk" "tests" ; do \
pushd $$DIR && golangci-lint run -c ../.golangci.yml --timeout 10m && popd ; \
done


install:: install_nodejs_sdk install_dotnet_sdk
cp $(WORKING_DIR)/bin/${PROVIDER} ${GOPATH}/bin


GO_TEST := go test -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM}

test_all::
cd provider/pkg && $(GO_TEST) ./...
cd tests/sdk/nodejs && $(GO_TEST) ./...
cd tests/sdk/python && $(GO_TEST) ./...
cd tests/sdk/dotnet && $(GO_TEST) ./...
cd tests/sdk/go && $(GO_TEST) ./...

install_dotnet_sdk::
rm -rf $(WORKING_DIR)/nuget/$(NUGET_PKG_NAME).*.nupkg
mkdir -p $(WORKING_DIR)/nuget
find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;

install_python_sdk::
#target intentionally blank

install_go_sdk::
#target intentionally blank

install_nodejs_sdk::
-yarn unlink --cwd $(WORKING_DIR)/sdk/nodejs/bin
yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ Most of the code for the provider implementation is in `pkg/provider/provider.go

An example of using the single resource defined in this example is in `examples/simple`.

A code generator is available which generates SDKs in TypeScript, Python, Go and .NET which are also checked in to the `sdk` folder. The SDKs are generated from a schema in `schema.json`. This file shoudl be kept aligned with the resources, functions and types supported by the provider implementation.
A code generator is available which generates SDKs in TypeScript, Python, Go and .NET which are also checked in to the `sdk` folder. The SDKs are generated from a schema in `provider/cmd/pulumi-resource-xyz/schema.json`. This file should be kept aligned with the resources, functions and types supported by the provider implementation.

Note that the generated provider plugin (`pulumi-resource-xyz`) must be on your `PATH` to be used by Pulumi deployments. If creating a provider for distribution to other users, you should ensure they install this plugin to their `PATH`.

## Pre-requisites

## Build and Test
Install the `pulumictl` cli from the [releases](https://github.com/pulumi/pulumictl/releases) page or follow the [install instructions](https://github.com/pulumi/pulumictl#installation)

```bash
# build the resource provider plugin
$ go install ./cmd/pulumi-resource-xyz
> NB: Usage of `pulumictl` is optional. If not using it, hard code the version in the [Makefile](Makefile) of when building explicitly pass version as `VERSION=0.0.1 make build`
# build the SDK generator
$ go install ./cmd/pulumi-sdkgen-xyz
## Build and Test

# regenerate the SDK
$ rm -rf ./sdk
$ pulumi-sdkgen-xyz ./schema.json ./sdk
```bash
# build and install the resource provider plugin
$ make build install

# test
$ cd examples/simple
Expand Down
116 changes: 0 additions & 116 deletions cmd/pulumi-sdkgen-xyz/main.go

This file was deleted.

10 changes: 0 additions & 10 deletions go.mod

This file was deleted.

Loading

0 comments on commit 8173048

Please sign in to comment.