-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
150 lines (112 loc) · 5.13 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
VERSION := 0.0.1
PACK := xyz
PROJECT := github.com/pulumi/pulumi-${PACK}
PROVIDER := pulumi-resource-${PACK}
VERSION_PATH := provider/pkg/version.Version
WORKING_DIR := $(shell pwd)
SCHEMA_PATH := ${WORKING_DIR}/schema.json
SRC := provider/cmd/pulumi-resource-${PACK}
# The pulumi binary to use during generation
PULUMI := .pulumi/bin/pulumi
export PULUMI_IGNORE_AMBIENT_PLUGINS = true
generate:: gen_go_sdk gen_dotnet_sdk gen_nodejs_sdk gen_python_sdk
gen_sdk_prerequisites: $(PULUMI)
build:: build_provider build_dotnet_sdk build_nodejs_sdk build_python_sdk
install:: install_dotnet_sdk install_nodejs_sdk
# Provider
PROVIDER_FILES = bin/PulumiPlugin.yaml bin/requirements.txt bin/run-provider.py
PROVIDER_FILES += bin/pulumi-resource-${PACK}.cmd bin/pulumi-resource-${PACK}
build_provider:: bin/venv bin/${PACK}_provider ${PROVIDER_FILES}
bin/venv: ${SRC}/requirements.txt
rm -rf $@
python3 -m venv $@
./bin/venv/bin/python -m pip install -r $<
bin/${PACK}_provider: ${SRC}/ ${SRC}/${PACK}_provider/VERSION
rm -rf $@
cp ${WORKING_DIR}/schema.json ${SRC}/${PACK}_provider/schema.json
./bin/venv/bin/python -m pip install --no-deps provider/cmd/pulumi-resource-${PACK}/ -t bin/
bin/PulumiPlugin.yaml: ${SRC}/PulumiPlugin.yaml
bin/requirements.txt: ${SRC}/requirements.txt
bin/pulumi-resource-${PACK}.cmd: ${SRC}/pulumi-resource-${PACK}.cmd
bin/pulumi-resource-${PACK}: ${SRC}/pulumi-resource-${PACK}
bin/run-provider.py: ${SRC}/run-provider.py
bin/%:
cp -f $< $@
${SRC}/${PACK}_provider/VERSION:
echo "${VERSION}" > ${SRC}/${PACK}_provider/VERSION
# Go SDK
gen_go_sdk: gen_sdk_prerequisites
rm -rf sdk/go
$(PULUMI) package gen-sdk ${SCHEMA_PATH} --language go
# .NET SDK
gen_dotnet_sdk: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
gen_dotnet_sdk: gen_sdk_prerequisites
rm -rf sdk/dotnet
$(PULUMI) package gen-sdk ${SCHEMA_PATH} --language dotnet
build_dotnet_sdk:: DOTNET_VERSION := ${VERSION}
build_dotnet_sdk:: gen_dotnet_sdk
cd sdk/dotnet/ && \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}
install_dotnet_sdk:: build_dotnet_sdk
rm -rf ${WORKING_DIR}/nuget
mkdir -p ${WORKING_DIR}/nuget
find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;
# Node.js SDK
gen_nodejs_sdk: VERSION := $(shell pulumictl get version --language javascript)
gen_nodejs_sdk: gen_sdk_prerequisites
rm -rf sdk/nodejs
$(PULUMI) package gen-sdk ${SCHEMA_PATH} --language nodejs
build_nodejs_sdk:: gen_nodejs_sdk
cd sdk/nodejs/ && \
yarn install && \
yarn run tsc --version && \
yarn run tsc && \
cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \
sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json && \
rm ./bin/package.json.bak
install_nodejs_sdk:: build_nodejs_sdk
yarn link --cwd ${WORKING_DIR}/sdk/nodejs/bin
# Python SDK
gen_python_sdk: PYPI_VERSION := $(shell pulumictl get version --language python)
gen_python_sdk: gen_sdk_prerequisites
rm -rf sdk/python
$(PULUMI) package gen-sdk ${SCHEMA_PATH} --language python
cp ${WORKING_DIR}/README.md sdk/python
cp ${WORKING_DIR}/misc/pyproject.toml sdk/python
build_python_sdk:: PYPI_VERSION := $(shell pulumictl get version --language python)
build_python_sdk:: gen_python_sdk
cd sdk/python/ && \
printf "module fake_python_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
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 && rm ./bin/go.mod && \
python3 -m venv venv && \
./venv/bin/python -m pip install build && \
cd ./bin && \
../venv/bin/python -m build .
# Output tarballs for plugin distribution. Example use:
#
# pulumi plugin install resource xyz 0.0.1 --file pulumi-resource-xyz-v0.0.1-linux-amd64.tar.gz
dist:: build_provider
rm -rf dist
mkdir -p dist
(cd bin && tar --gzip --exclude venv --exclude pulumi-resource-${PACK}.cmd -cf ../dist/pulumi-resource-${PACK}-v${VERSION}-linux-amd64.tar.gz .)
cp dist/pulumi-resource-${PACK}-v${VERSION}-linux-amd64.tar.gz dist/pulumi-resource-${PACK}-v${VERSION}-darwin-amd64.tar.gz
cp dist/pulumi-resource-${PACK}-v${VERSION}-linux-amd64.tar.gz dist/pulumi-resource-${PACK}-v${VERSION}-darwin-arm64.tar.gz
(cd bin && tar --gzip --exclude venv --exclude pulumi-resource-${PACK} -cf ../dist/pulumi-resource-${PACK}-v${VERSION}-windows-amd64.tar.gz .)
# Keep the version of the pulumi binary used for code generation in sync with the version
# of the dependency used by this provider.
$(PULUMI): HOME := $(WORKING_DIR)
$(PULUMI): provider/go.mod
@ PULUMI_VERSION="$$(cd provider && go list -m github.com/pulumi/pulumi/pkg/v3 | awk '{print $$2}')"; \
if [ -x $(PULUMI) ]; then \
CURRENT_VERSION="$$($(PULUMI) version)"; \
if [ "$${CURRENT_VERSION}" != "$${PULUMI_VERSION}" ]; then \
echo "Upgrading $(PULUMI) from $${CURRENT_VERSION} to $${PULUMI_VERSION}"; \
rm $(PULUMI); \
fi; \
fi; \
if ! [ -x $(PULUMI) ]; then \
curl -fsSL https://get.pulumi.com | sh -s -- --version "$${PULUMI_VERSION#v}"; \
fi