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

chore: install pulumictl in makefile #157

Merged
merged 3 commits into from
Aug 20, 2024
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
56 changes: 36 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,34 @@ NODE_MODULE_NAME := @${ORG}/${NODE_PACK}
TF_NAME := ${PACK}
PROVIDER_PATH := provider
VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version

TFGEN := pulumi-tfgen-${PACK}
PROVIDER := pulumi-resource-${PACK}
VERSION := $(shell pulumictl get version)
JAVA_GEN := pulumi-java-gen
JAVA_GROUP_ID := com.${ORG}.pulumi
JAVA_ARTIFACT_ID := ${PACK}
TESTPARALLELISM := 4

WORKING_DIR := $(shell pwd)
WORKING_DIR := $(shell pwd)
BIN_DIR := $(WORKING_DIR)/.pulumi/bin
PULUMICTL_BIN := $(BIN_DIR)/pulumictl

OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH=amd64
endif

OS := $(shell uname)
EMPTY_TO_AVOID_SED := ""

PULUMICTL_VERSION := v0.0.46

# estimated target version of the plugin that is currently being generated
VERSION = $(shell $(PULUMICTL_BIN) get version)
PACKAGE_VERSION = $(shell $(PULUMICTL_BIN) get version --language generic)
NODEJS_VERSION = $(shell $(PULUMICTL_BIN) get version --language javascript)
PYPI_VERSION = $(shell $(PULUMICTL_BIN) get version --language python)
DOTNET_VERSION = $(shell $(PULUMICTL_BIN) get version--language dotnet)
ocobles marked this conversation as resolved.
Show resolved Hide resolved

development: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment

# Required for the codegen action that runs in pulumi/pulumi and pulumi/pulumi-terraform-bridge
Expand All @@ -37,24 +51,24 @@ tfgen: only_tfgen generate_examples
generate_examples: examples

# Build the tfgen binary and generate the schema
build_schema: $(PULUMICTL_BIN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the dependencies too!

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

bin/pulumi-java-gen: .pulumi-java-gen.version
pulumictl download-binary -n pulumi-language-java -v v$(shell cat .pulumi-java-gen.version) -r pulumi/pulumi-java
bin/pulumi-java-gen: .pulumi-java-gen.version $(PULUMICTL_BIN)
$(PULUMICTL_BIN) download-binary -n pulumi-language-java -v v$(shell cat .pulumi-java-gen.version) -r pulumi/pulumi-java

provider: tfgen install_plugins # build the provider binary
provider: only_provider

only_provider:
only_provider: $(PULUMICTL_BIN)
(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION} -X github.com/equinix/terraform-provider-equinix/version.ProviderVersion=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER})

build_sdks: clean build_nodejs build_python build_go build_dotnet build_java # build all the sdks

build_nodejs: VERSION := $(shell pulumictl get version --language javascript)
build_nodejs: upstream
build_nodejs: upstream $(PULUMICTL_BIN)
$(WORKING_DIR)/bin/$(TFGEN) nodejs --overlays provider/overlays/nodejs --out sdk/nodejs/
echo "patch_nodejs: find and replace wrong imports in examples" && \
find ./sdk/nodejs/ -type f -name "*.ts" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -print -exec sed -i.bak 's/import \* as ${PACK} from "@pulumi\/${PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g; s/import \* as ${NODE_PACK_ALIAS} from "@${ORG}\/${NODE_PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g' {} \;
Expand All @@ -67,10 +81,9 @@ build_nodejs: upstream
yarn install && \
yarn run tsc && \
cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \
sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json
sed -i.bak -e "s/\$${VERSION}/$(NODEJS_VERSION)/g" ./bin/package.json

build_python: PYPI_VERSION := $(shell pulumictl get version --language python)
build_python: upstream
build_python: upstream $(PULUMICTL_BIN)
rm -rf sdk/python/
$(WORKING_DIR)/bin/$(TFGEN) python --overlays provider/overlays/python --out sdk/python/
cd sdk/python/ && \
Expand All @@ -82,9 +95,7 @@ build_python: upstream
rm ./bin/setup.py.bak && \
cd ./bin && python3 setup.py build sdist

build_dotnet: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
build_dotnet: upstream
pulumictl get version --language dotnet
build_dotnet: upstream $(PULUMICTL_BIN)
$(WORKING_DIR)/bin/$(TFGEN) dotnet --overlays provider/overlays/dotnet --out sdk/dotnet/
cd sdk/dotnet/ && \
printf "module fake_dotnet_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
Expand All @@ -96,8 +107,7 @@ build_go:: upstream
go install golang.org/x/tools/cmd/goimports@latest
cd sdk && goimports -w . && go list "$$(grep -e "^module" go.mod | cut -d ' ' -f 2)/go/..." | xargs go build

build_java: PACKAGE_VERSION := $(shell pulumictl get version --language generic)
build_java: bin/pulumi-java-gen patch_java_schema upstream
build_java: bin/pulumi-java-gen patch_java_schema upstream $(PULUMICTL_BIN)
$(WORKING_DIR)/bin/$(JAVA_GEN) generate --schema provider/cmd/$(PROVIDER)/schema-java.json --out sdk/java --build gradle-nexus
rm -f ./provider/cmd/$(PROVIDER)/schema-java.json
echo "patch_java: find and replace invocations of pulumi:fabric/metal/networkedge" && \
Expand Down Expand Up @@ -156,8 +166,8 @@ help:
clean:
rm -rf sdk/{dotnet,nodejs,go,python,java}

install_equinix_plugin: only_provider uninstall_equinix_plugin .pulumi/bin/pulumi
.pulumi/bin/pulumi plugin install resource equinix $(shell pulumictl get version --language generic) --file $(WORKING_DIR)/bin/$(PROVIDER)
install_equinix_plugin: only_provider uninstall_equinix_plugin .pulumi/bin/pulumi $(PULUMICTL_BIN)
.pulumi/bin/pulumi plugin install resource equinix $(VERSION) --file $(WORKING_DIR)/bin/$(PROVIDER)

uninstall_equinix_plugin: .pulumi/bin/pulumi
.pulumi/bin/pulumi plugin rm resource equinix -a -y
Expand Down Expand Up @@ -206,7 +216,13 @@ upstream.rebase:
.pulumi/bin/pulumi: .pulumi/version
curl -fsSL https://get.pulumi.com | HOME=$(WORKING_DIR) sh -s -- --version $(cat .pulumi/version)

examples: install_equinix_plugin
$(PULUMICTL_BIN):
@mkdir -p $(BIN_DIR)
curl -L https://github.com/pulumi/pulumictl/releases/download/$(PULUMICTL_VERSION)/pulumictl-$(PULUMICTL_VERSION)-$(OS)-$(ARCH).tar.gz -o $(BIN_DIR)/pulumictl.tar.gz
tar -xzf .pulumi/bin/pulumictl.tar.gz -C $(BIN_DIR)
rm -f $(BIN_DIR)/pulumictl.tar.gz

examples: install_equinix_plugin $(PULUMICTL_BIN)
scripts/generate_examples.sh
ocobles marked this conversation as resolved.
Show resolved Hide resolved

# Compute the version of Pulumi to use by inspecting the Go dependencies of the provider.
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EXAMPLES_DIR="${SCRIPT_DIR}/../examples/"
# Docs directory
OUTPUT_DIR="${SCRIPT_DIR}/../docs/resource"
# Pulumi Equinix plugin version installed
VERSION=$(pulumictl get version --language generic)
VERSION=$(.pulumi/bin/pulumictl get version --language generic)

get_patch() {
local version="$1"
Expand Down
Loading