-
Notifications
You must be signed in to change notification settings - Fork 4
TEC-88-add-python-311-support-to-gcloud-requests #29
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
Open
umar-leadpages
wants to merge
20
commits into
master
Choose a base branch
from
gcloud_requests_migrations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
de6720e
Code migrations for python 3.11 compatibility
umar-leadpages 69f74c1
Add support for python 3.9
umar-leadpages 399007a
added cloudbuild pipeline
adith-rai-97 e300cd4
small update for runtests and makefile for robustness
adith-rai-97 32269d8
added linting step
adith-rai-97 55d3722
added subs var
adith-rai-97 33ddf71
Get all tests to work with datastore, get old libs like grcpio to wor…
adith-rai-97 8aba357
clean up
adith-rai-97 cd23c28
syntax fix
adith-rai-97 c4f769c
add logs bucket
adith-rai-97 bb1ebd8
permit test to urlmatch both oauth url as well as metadata server url…
adith-rai-97 7555b6e
dev ver
adith-rai-97 3291e75
revert
adith-rai-97 ee4a480
add powerful machine for cloudbuild
adith-rai-97 0c14b43
revert
adith-rai-97 e161fbf
update readme
adith-rai-97 c0c4a49
apply cosmetic fixes
adith-rai-97 71a56b8
update dev ver
adith-rai-97 cf64f20
Merge pull request #30 from LeadPages/cloudbuild
adith-rai-97 8dff75a
Update __init__.py - fix version name
adith-rai-97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,9 @@ __pycache__ | |
| /dist | ||
| /gcloud_requests.egg-info | ||
| /htmlcov | ||
| cloudbuild_pypirc | ||
| netrc | ||
| pip.conf | ||
| gcloud | ||
| build | ||
| dist | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| DOCKER ?= docker | ||
| MKDIR ?= mkdir | ||
| RM ?= rm | ||
|
|
||
| PROJECT=gcloud-requests | ||
|
|
||
| LATEST_SUPPORTED_PY_VERSION=3.11 | ||
|
|
||
| SUPPORTED_PY_VERSIONS=2.7 3.6 3.7 3.8 3.9 $(LATEST_SUPPORTED_PY_VERSION) | ||
|
|
||
| # Determine platform flag (only needed for python 2.7) | ||
| # grpcio HAS NO PRE_BUILT WHEELS FOR ARM64 FOR PYTHON 2, SO FORCE PLATFORM TO linuc/amd64 | ||
| # For grpcio We also need to rebuild from source with the alpine image, so for python 2.7, we dont use the full debian | ||
| define PLATFORM_ARG | ||
| $(if $(filter 2.7,$(PY_VERSION)),--platform=linux/amd64,) | ||
| endef | ||
| PY_IMAGE = python:$(PY_VERSION)-alpine | ||
| ifeq ($(PY_VERSION),2.7) | ||
| PY_IMAGE = python:2.7 | ||
| endif | ||
| # Addtionally, the python 2.7 debian image will need bash to work with runtests.sh and buildwheel.sh | ||
| SHELL_CMD = sh | ||
| ifeq ($(PY_VERSION),2.7) | ||
| SHELL_CMD = /bin/bash | ||
| endif | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # NOT FULLY Mocked, setting project ID as lp-infra-lab | ||
| GOOGLE_CLOUD_PROJECT ?= lp-infra-lab | ||
| DATASTORE_PROJECT_ID ?= $(GOOGLE_CLOUD_PROJECT) | ||
| DATASTORE_DATASET ?= $(GOOGLE_CLOUD_PROJECT) | ||
| GCLOUD_PROJECT ?= $(GOOGLE_CLOUD_PROJECT) | ||
|
|
||
| .PHONY: test ci-tests | ||
|
|
||
| netrc: | ||
| cp ${HOME}/.netrc netrc | ||
|
|
||
| pip.conf: | ||
| cp ${HOME}/.pip/pip.conf pip.conf | ||
|
|
||
| cloudbuild_pypirc: | ||
| cp ${HOME}/.pypirc cloudbuild_pypirc | ||
|
|
||
| ${HOME}/.config/gcloud/application_default_credentials.json: | ||
| gcloud auth application-default login | ||
|
|
||
| run: netrc pip.conf cloudbuild_pypirc ${HOME}/.config/gcloud/application_default_credentials.json | ||
| $(DOCKER) run $(PLATFORM_ARG) -it --rm=true --name=$(PROJECT)_python$(PY_VERSION) \ | ||
| -v $(CURDIR):/workspace \ | ||
| -v ${HOME}/.config/gcloud:/root/.config/gcloud:ro \ | ||
| -e GOOGLE_APPLICATION_CREDENTIALS=/root/.config/gcloud/application_default_credentials.json \ | ||
| -e DATASTORE_PROJECT_ID=$(DATASTORE_PROJECT_ID) \ | ||
| -e DATASTORE_DATASET=$(DATASTORE_DATASET) \ | ||
| -e GOOGLE_CLOUD_PROJECT=$(GOOGLE_CLOUD_PROJECT) \ | ||
| -e GCLOUD_PROJECT=$(GCLOUD_PROJECT) \ | ||
| $(PY_IMAGE) \ | ||
| $(SHELL_CMD) -c "/workspace/ci/runtests.sh onlysetup; exec /bin/sh" | ||
|
|
||
| lint: | ||
| $(DOCKER) run --rm \ | ||
| -v $(CURDIR):/workspace \ | ||
| python:3.11-alpine sh -c "pip install flake8 && flake8 /workspace/gcloud_requests /workspace/tests" | ||
|
|
||
| test: netrc pip.conf cloudbuild_pypirc ${HOME}/.config/gcloud/application_default_credentials.json | ||
| $(DOCKER) run $(PLATFORM_ARG) -it --rm=true --name=$(PROJECT)_$@ \ | ||
| -v $(CURDIR):/workspace \ | ||
| -v ${HOME}/.config/gcloud:/root/.config/gcloud:ro \ | ||
| -e GOOGLE_APPLICATION_CREDENTIALS=/root/.config/gcloud/application_default_credentials.json \ | ||
| -e DATASTORE_PROJECT_ID=$(DATASTORE_PROJECT_ID) \ | ||
| -e DATASTORE_DATASET=$(DATASTORE_DATASET) \ | ||
| -e GOOGLE_CLOUD_PROJECT=$(GOOGLE_CLOUD_PROJECT) \ | ||
| -e GCLOUD_PROJECT=$(GCLOUD_PROJECT) \ | ||
| $(PY_IMAGE) $(SHELL_CMD) /workspace/ci/runtests.sh | ||
|
|
||
| ci-tests: | ||
| $(foreach pyversion, $(SUPPORTED_PY_VERSIONS), $(MAKE) PY_VERSION=$(pyversion) test;) | ||
|
|
||
| bdist_wheel: netrc pip.conf cloudbuild_pypirc ${HOME}/.config/gcloud/application_default_credentials.json | ||
| # THIS WILL PUBLISH THE LIBRARY! HAVE YOU SET THE gcloud_requests/__init__.py versions TO A DEV VERSION??? | ||
| @if [ x"$(BUILD_TYPE)" == x"release" ]; then \ | ||
| if grep __version__ gcloud_requests/__init__.py | grep -q '[0-9]*\.[0-9]*[\.\-]dev'; then \ | ||
| $(DOCKER) run $(PLATFORM_ARG) -it --rm=true --name=$(PROJECT)_$@ \ | ||
| -v $(CURDIR):/workspace \ | ||
| -v ${HOME}/.config/gcloud:/root/.config/gcloud:ro \ | ||
| -e GOOGLE_APPLICATION_CREDENTIALS=/root/.config/gcloud/application_default_credentials.json \ | ||
| --env BUILD_TYPE=$(BUILD_TYPE) \ | ||
| python:$(LATEST_SUPPORTED_PY_VERSION)-alpine /bin/sh /workspace/ci/buildwheel.sh; \ | ||
| else \ | ||
| echo "The __version__ in gcloud_requests/__init__.py does not contain 'dev' designator"; \ | ||
| fi \ | ||
| else \ | ||
| $(DOCKER) run $(PLATFORM_ARG) -it --rm=true --name=$(PROJECT)_$@ \ | ||
| -v $(CURDIR):/workspace \ | ||
| -v ${HOME}/.config/gcloud:/root/.config/gcloud:ro \ | ||
| -e GOOGLE_APPLICATION_CREDENTIALS=/root/.config/gcloud/application_default_credentials.json \ | ||
| --env BUILD_TYPE=local \ | ||
| python:$(LATEST_SUPPORTED_PY_VERSION)-alpine /bin/sh /workspace/ci/buildwheel.sh; \ | ||
| fi | ||
|
|
||
| clean: | ||
| -$(RM) netrc | ||
| -$(RM) pip.conf | ||
| -$(RM) cloudbuild_pypirc | ||
| -$(RM) -rf build | ||
| -$(RM) -rf dist | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/bin/sh | ||
|
|
||
| function setup_root() { | ||
| mkdir /root/.pip && ln -s /workspace/pip.conf /root/.pip/pip.conf | ||
| ln -s /workspace/netrc /root/.netrc | ||
| ln -s /workspace/cloudbuild_pypirc /root/.pypirc | ||
| } | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function setup_app() { | ||
| mkdir /app && cd /app | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # copy, because we wanna be able to toss out __pychache__ and *.pyc files | ||
| cp -ar /workspace/gcloud_requests /app/gcloud_requests | ||
| cp -ar /workspace/tests /app/tests | ||
| # copy, don't link, because we change it with `sed` | ||
| cp -v /workspace/requirements.txt /app/requirements.txt | ||
| ln -s /workspace/requirements-dev.txt /app/requirements-dev.txt | ||
| ln -s /workspace/setup.cfg /app/setup.cfg | ||
| ln -s /workspace/setup.py /app/setup.py | ||
| } | ||
|
|
||
| function build_wheel() { | ||
| cd /app | ||
| export HOME=/root # Damn you cloudbuild, presets to /home/builder/home ... | ||
| sed -i requirements.txt -e "s:^six$:six==1.15:" | ||
| pip install -r requirements.txt | ||
| pip install wheel | ||
|
|
||
| python setup.py bdist_wheel | ||
|
|
||
| ls -la build | ||
| ls -la dist | ||
| ls -la . | ||
| } | ||
|
|
||
| function upload_lib() { | ||
| # twine needs a compiler | ||
| cd /app | ||
| apk update && apk upgrade && apk add build-base libffi-dev | ||
| pip install twine | ||
| # "local" refers to the [local] section in pypirc which specifies the URL | ||
| echo "Uplaod library to Artifactory" | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| twine upload \ | ||
| --repository local \ | ||
| dist/* \ | ||
| --config-file /root/.pypirc | ||
| } | ||
|
|
||
| function main() { | ||
| setup_root | ||
| setup_app | ||
| build_wheel | ||
| # additional safegard against uploading | ||
| if [ x"${BUILD_TYPE}" == x"release" ]; then | ||
| upload_lib | ||
| elif [ x"${BUILD_TYPE}" == x"local" ]; then | ||
| echo " copy into /workspace dir, which is a docker volume mount" | ||
| rm -rf /workspace/{build,dist} | ||
| cp -avr /app/build /app/dist /workspace/ | ||
| else | ||
| echo "Discard builded library!" | ||
| fi | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| main $@ | ||
adith-rai-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| substitutions: | ||
| _LATEST_SUPPORTED_PY_VERSION: "3.11" | ||
| _DATASTORE_PROJECT_ID: lp-infra-lab | ||
| _DATASTORE_DATASET: lp-infra-lab | ||
| _GOOGLE_CLOUD_PROJECT: lp-infra-lab | ||
| _GCLOUD_PROJECT: lp-infra-lab | ||
|
|
||
| steps: | ||
| # Pulls down the netrc and pip conf files we need to access our private npm registry. | ||
| # This file is stored within the context of this build, and becomes accessible to the CI image | ||
| # via a volume mount. | ||
| - name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine | ||
| id: "Prepare: Copy over npm/pip/net config files from bucket" | ||
| entrypoint: "gsutil" | ||
| args: | ||
| - cp | ||
| - gs://center-builds/pypi/netrc | ||
| - gs://center-builds/pypi/pip.conf | ||
| - gs://center-builds/pypi/cloudbuild_pypirc | ||
| - . | ||
|
|
||
| - name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine | ||
| id: "Test the git checkout" | ||
| entrypoint: "bash" | ||
| args: | ||
| - -c | ||
| - | | ||
| ls -la / | ||
| ls -la /workspace | ||
| git log | ||
|
|
||
| - name: python:${_LATEST_SUPPORTED_PY_VERSION}-alpine | ||
| id: "Lint" | ||
| entrypoint: sh | ||
| args: | ||
| - -c | ||
| - | | ||
| # Create pip and auth dirs | ||
| mkdir -p /root/.pip | ||
|
|
||
| # Link workspace configs into expected locations | ||
| ln -sf /workspace/pip.conf /root/.pip/pip.conf | ||
| ln -sf /workspace/netrc /root/.netrc | ||
| ln -sf /workspace/cloudbuild_pypirc /root/.pypirc | ||
|
|
||
| # Install flake8 using the correct pip config | ||
| pip install flake8 | ||
|
|
||
| # Run linting | ||
| flake8 gcloud_requests tests | ||
|
|
||
| # We need to rebuild from source with alpine image, so for python 2.7, we dont use alpine | ||
| - name: python:2.7 | ||
| id: "Test: Inside Python-2.7" | ||
| entrypoint: bash | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:3.6-alpine | ||
| id: "Test: Inside Python-3.6" | ||
| entrypoint: sh | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:3.7-alpine | ||
| id: "Test: Inside Python-3.7" | ||
| entrypoint: sh | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:3.8-alpine | ||
| id: "Test: Inside Python-3.8" | ||
| entrypoint: sh | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:3.9-alpine | ||
| id: "Test: Inside Python-3.9" | ||
| entrypoint: sh | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:${_LATEST_SUPPORTED_PY_VERSION}-alpine | ||
| id: "Test: Inside Python-${_LATEST_SUPPORTED_PY_VERSION}" | ||
| entrypoint: sh | ||
| args: | ||
| - /workspace/ci/runtests.sh | ||
| env: | ||
| - DATASTORE_PROJECT_ID=${_DATASTORE_PROJECT_ID} | ||
| - DATASTORE_DATASET=${_DATASTORE_DATASET} | ||
| - GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT} | ||
| - GCLOUD_PROJECT=${_GCLOUD_PROJECT} | ||
|
|
||
| - name: python:${_LATEST_SUPPORTED_PY_VERSION}-alpine | ||
| id: "Build and Publish: create and upload library" | ||
| entrypoint: sh | ||
| env: | ||
| - 'BUILD_TYPE=$_BUILD_TYPE' # Safe-Guard inside buildwheel.sh | ||
| args: | ||
| - -c | ||
| - | | ||
| if [ x"$_BUILD_TYPE" == x"release" ]; then | ||
| /workspace/ci/buildwheel.sh | ||
| else | ||
| echo "_BUILD_TYPE is <$_BUILD_TYPE> -> DO NOT build a wheel publish." | ||
| fi | ||
|
|
||
| logsBucket: gs://leadpage-dev_cloudbuild/cloudbuild_logs | ||
| options: | ||
| machineType: 'E2_HIGHCPU_8' # We need these extra cores to run these unit tests for python 2, else it takes 20 minutes | ||
| logging: GCS_ONLY |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.