pulumi/sdk/python/Makefile
joeduffy 162157c1a7 Add a Dockerfile for the Pulumi CLI
This introduces a Dockerfile for the Pulumi CLI. This makes it
easier to develop and test the engine in a self-contained environment,
in addition to being suitable for running the actual CLI itself.

For instance,

    $ docker run pulumi/pulumi -e "PULUMI_ACCESS_TOKEN=x" up

will run the Pulumi program mounted under the /app volume. This will
be used in some upcoming CI/CD scenarios.

This uses multi-stage builds, and Debian Stretch as the base, for
relatively fast and lean build times and resulting images. We are
intentional about restoring dep packages independent of the actual
source code so that we don't end up needlessly re-depping, which can
consume quite a bit of time. After fixing
https://github.com/pulumi/pulumi/issues/1986, we should explore an
Alpine base image option.

I made the decision to keep this image scoped to just the Go builds.
Therefore, none of the actual SDK packages themselves are built, just
the engine, CLI, and language plugins for Node.js, Python, and Go.
It's possible to create a mega-container that has all of these full
environments so that we can rebuild them too, but for now I figured
it was better to rely on package management for them.

Another alternative would have been to install released binaries,
rather than building them. To keep the useful flow for development,
however, I decided to go the build route for now. If we build at the
same hashes, the resulting binaries "should" be ~identical anyhow.

I've created a pulumi/pulumi Docker Hub repo that we can publish this
into. For now, there is no CI publishing of the image.

This fixes pulumi/pulumi#1991.
2018-09-29 11:48:21 -07:00

71 lines
2.1 KiB
Makefile

PROJECT_NAME := Pulumi Python SDK
LANGHOST_PKG := github.com/pulumi/pulumi/sdk/python/cmd/pulumi-language-python
VERSION := $(shell ../../scripts/get-py-version)
ifeq ($(PYTHON),)
PYTHON := python
endif
ifeq ($(PIP),)
PIP := pip
endif
ifneq ($(PYTHON_3),)
PIPENV_PYTHON_VERSION := --three
else
PIPENV_PYTHON_VERSION := --two
endif
PIPENV_VERSION := 2018.05.18
PYENV := ./env
PYENVSRC := $(PYENV)/src
GOMETALINTERBIN := gometalinter
GOMETALINTER := ${GOMETALINTERBIN} --config=../../Gometalinter.json
include ../../build/common.mk
ensure::
$(PIP) install pipenv==$(PIPENV_VERSION) --user
pipenv $(PIPENV_PYTHON_VERSION) install --dev
mkdir -p $(PYENVSRC)
build_package::
rm -rf $(PYENVSRC) && cp -R ./lib/. $(PYENVSRC)/
sed -i.bak "s/\$${VERSION}/$(VERSION)/g" $(PYENVSRC)/setup.py && rm $(PYENVSRC)/setup.py.bak
if [ ! -z "$$(command -v pandoc)" ]; then \
pandoc --from=markdown --to=rst --output="$(PYENVSRC)/README.rst" ../../README.md; \
else \
echo "warning: pandoc not found, generating empty README.rst"; \
echo "" > "$(PYENVSRC)/README.rst"; \
fi
cd $(PYENVSRC) && pipenv run python setup.py build bdist_wheel --universal
build_plugin::
go install -ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
build:: build_package build_plugin
lint::
pipenv run pylint -E ./lib/pulumi --ignore-patterns '.*_pb2_.*.py'
$(GOMETALINTER) ./cmd/pulumi-language-python/... | sort ; exit $${PIPESTATUS[0]}
$(GOMETALINTER) ./pkg/... | sort ; exit $${PIPESTATUS[0]}
install_package::
cd $(PYENVSRC) && $(PIP) install --user -e .
cp ./cmd/pulumi-language-python-exec "$(PULUMI_BIN)"
install_plugin::
GOBIN=$(PULUMI_BIN) go install \
-ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
install:: install_package install_plugin
test_fast::
pipenv run pip install ./env/src
pipenv run python -m unittest discover -s lib/test
dist::
go install -ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
cp ./cmd/pulumi-language-python-exec "$$(go env GOPATH)"/bin/