Skip to content

Commit

Permalink
✨ add a new version
Browse files Browse the repository at this point in the history
- Upgrade to new version of pulumi-provider-go
- Allow read files
  • Loading branch information
spigell committed Sep 24, 2023
1 parent 472428d commit 02cfa2a
Show file tree
Hide file tree
Showing 91 changed files with 15,377 additions and 3,063 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,25 @@ Pulumi.*.yaml
yarn.lock
ci-scripts
/nuget/
ci-scripts
/nuget/
sdk/dotnet/version.txt
.DS_Store
/provider/cmd/pulumi-resource-command/schema-embed.json
dist/

rsa*
password.txt
password2.txt
private_ip.txt
out.txt
examples/**/venv/
examples/**/__pycache__/

sdk/java/build
sdk/java/.gradle
sdk/java/gradle
sdk/java/gradlew
sdk/java/gradlew.bat

sdk/python/venv
7 changes: 1 addition & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ run:
tests: true
build-tags:
- bench
- !bench
skip-dirs:
- cmd

Expand All @@ -26,8 +25,7 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- unused
- dogsled
- dupl
- durationcheck
Expand All @@ -48,7 +46,6 @@ linters:
- gosec
- gosimple
- govet
- ifshort
- ineffassign
- misspell
- nestif
Expand All @@ -59,13 +56,11 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- revive
- whitespace

1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ release:
disable: false
snapshot:
name_template: '{{ .Tag }}-SNAPSHOT'

1 change: 1 addition & 0 deletions .pulumi.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.81.0
119 changes: 93 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
PROJECT_NAME := Pulumi file Resource Provider
PROJECT_NAME := Pulumi File Resource Provider

PACK := file
PACKDIR := sdk
PROJECT := github.com/spigell/pulumi-${PACK}
NODE_MODULE_NAME := @spigell/pulumi-${PACK}
PROJECT := github.com/spigell/pulumi-file
NODE_MODULE_NAME := @spigell/command
NUGET_PKG_NAME := Pulumi.Command

PROVIDER := pulumi-resource-${PACK}
CODEGEN := pulumi-gen-${PACK}
Expand All @@ -12,81 +13,147 @@ PROVIDER_PATH := provider
VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version

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

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

ensure::
cd provider && go mod tidy
# Need to pick up locally pinned pulumi-langage-* plugins.
export PULUMI_IGNORE_AMBIENT_PLUGINS = true

ensure:: tidy

tidy: tidy_provider
cd sdk && go mod tidy
cd tests && go mod tidy

gen::
tidy_examples:
cd examples && go mod tidy

tidy_provider:
cd provider && go mod tidy

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

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

provider_debug::
(cd provider && go build -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} ./...
test_provider: tidy_provider
cd provider/tests && go test -short -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM} ./...

dotnet_sdk:: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
dotnet_sdk:: .pulumi/bin/pulumi
rm -rf sdk/dotnet
.pulumi/bin/pulumi package gen-sdk --language dotnet $(SCHEMA_FILE)
# Copy the logo to the dotnet directory before building so it can be included in the nuget package archive.
# https://github.com/pulumi/pulumi-command/issues/243
cd ${PACKDIR}/dotnet/&& \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}

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

nodejs_sdk::
nodejs_sdk:: VERSION := $(shell pulumictl get version --language javascript)
nodejs_sdk:: .pulumi/bin/pulumi
rm -rf sdk/nodejs
$(WORKING_DIR)/bin/$(CODEGEN) -version=${VERSION} nodejs $(SCHEMA_FILE) $(CURDIR)
.pulumi/bin/pulumi package gen-sdk --language nodejs $(SCHEMA_FILE)
cd ${PACKDIR}/nodejs/ && \
yarn install && \
yarn run tsc
cp README.md LICENSE ${PACKDIR}/nodejs/package.json ${PACKDIR}/nodejs/yarn.lock ${PACKDIR}/nodejs/bin/
cp -r ${PACKDIR}/nodejs/scripts ${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:: .pulumi/bin/pulumi
rm -rf sdk/python
.pulumi/bin/pulumi package gen-sdk --language python $(SCHEMA_FILE)
cp README.md ${PACKDIR}/python/
cd ${PACKDIR}/python/ && \
rm -rf ./bin/ ../python.bin/ && cp -R . ../python.bin && mv ../python.bin ./bin && \
sed -i.bak -e 's/^ version = .*/ version = "$(PYPI_VERSION)"/g' ./bin/pyproject.toml && \
rm ./bin/pyproject.toml.bak && \
python3 -m venv venv && \
./venv/bin/python -m pip install build && \
cd ./bin && \
../venv/bin/python -m build .

bin/pulumi-java-gen::
echo pulumi-java-gen is no longer necessary

java_sdk:: PACKAGE_VERSION := $(shell pulumictl get version --language generic)
java_sdk:: .pulumi/bin/pulumi
rm -rf sdk/java
.pulumi/bin/pulumi package gen-sdk --language java $(SCHEMA_FILE)
cd sdk/java/ && \
gradle --console=plain build

.PHONY: build
build:: gen provider go_sdk nodejs_sdk
build:: provider build_sdks

.PHONY: build_sdks
build_sdks: codegen dotnet_sdk go_sdk nodejs_sdk python_sdk java_sdk

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

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


install:: install_nodejs_sdk
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}
GO_TEST := go test -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM}

test_all::
test_all:: test
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) ./...

test_remote:
test_integration:
docker-compose up openssh-server -d
pulumi -C examples/simple-go stack init dev
cat ./misc/ssh/id_rsa | pulumi -C examples/simple-go config set --secret sshKey
PATH=$(PATH):../../bin pulumi -C examples/simple-go up -fy
PATH=$(PATH):../../bin pulumi -C examples/simple-go destroy -yf
PATH=$(PATH):${GOPATH}/bin pulumi -C examples/simple-go up -fy
PATH=$(PATH):${GOPATH}/bin pulumi -C examples/simple-go destroy -yf
pulumi -C examples/simple-go stack rm dev -y

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_java_sdk::
#target intentionally blank

install_nodejs_sdk::
-yarn unlink --cwd $(WORKING_DIR)/sdk/nodejs/bin
yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin

test:: tidy_examples test_provider
cd examples && go test -v -tags=all -timeout 2h

# --------- File-based targets --------- #

.pulumi/bin/pulumi: PULUMI_VERSION := $(shell cat .pulumi.version)
.pulumi/bin/pulumi: HOME := $(WORKING_DIR)
.pulumi/bin/pulumi: .pulumi.version
curl -fsSL https://get.pulumi.com | sh -s -- --version "$(PULUMI_VERSION)"

23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

This is a very simple pulumi native provider.

Hugely based on [pulumi-go-provider](https://github.com/pulumi/pulumi-go-provider) and [pulumi-command-provider](https://github.com/pulumi/pulumi-command). Several pieces of code were from there.

Resources:
* Node: It manages a content of file on linux machines. It supports only remote file now.
* Remote.File: It manages the content of files on Linux machines. It supports only remote files for now.

There is typescript and golang examples of using the single resource defined in `examples directory`.
There are typescript and golang examples of using the single resource defined in `examples directory`.

``Read`` call is not implemented so commands like `pulumi refresh` or `pulumi import` are not working right now.
``Read`` call is implemented so commands like `pulumi refresh` works now.
But `pulumi import` is not implemented now.

## Installing
There are golang and typescript sdk. Another are generated but not uploaded to packages repositories.

This package is available only for JS/TS or Golang.
## Installing

Grab plugin if pulumi didn't make it automaticaly:
Grab the plugin if pulumi didn't make it automatically:

```
pulumi plugin install resource file v0.0.2 --server https://github.com/spigell/pulumi-file/releases/download/v0.0.2
pulumi plugin install resource file v0.0.3 --server https://github.com/spigell/pulumi-file/releases/download/v0.0.3
```

### Node.js (JavaScript/TypeScript)
Expand All @@ -39,14 +42,14 @@ To use from Go, use `go get` to grab the latest version of the library

### Dependencies

- Go 1.15
- NodeJS 10.X.X or later
- Go 1.21
- NodeJS 16.X.X or later

### Local Build and Test

Most of the code for the provider implementation is in `provider/pkg` directory.

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 should 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 `schema.json`.

Note that the generated provider plugin (`pulumi-resource-file`) must be on your `PATH` to be used by Pulumi deployments.

Expand Down
1 change: 0 additions & 1 deletion examples/simple-go/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
name: file_local
runtime: go
description: A minimal Go Pulumi program

Loading

0 comments on commit 02cfa2a

Please sign in to comment.