Skip to content

Commit

Permalink
Update Cloud Run Helloworld project to use Python buildpacks (#10493)
Browse files Browse the repository at this point in the history
* Delete Dockerfile

Removing Docker file because GCP Buildpacks now provide a reasonable entrypoint if none is provided https://cloud.google.com/docs/buildpacks/release-notes#July_19_2023

* updated helloworld README to run without Dockerfile

* fixed tests for run/helloworld

* debug 27 tests

* debug

---------

Co-authored-by: jscma <[email protected]>
Co-authored-by: Averi Kitsch <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent 39b165d commit 291e314
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 87 deletions.
41 changes: 0 additions & 41 deletions run/helloworld/Dockerfile

This file was deleted.

20 changes: 12 additions & 8 deletions run/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ This sample shows how to deploy a Hello World application to Cloud Run.

## Build

* Set an environment variable with your GCP Project ID:

```
docker build --tag helloworld:python .
export GOOGLE_CLOUD_PROJECT=<PROJECT_ID>
```

## Run Locally
* Use a [Buildpack](https://github.com/GoogleCloudPlatform/buildpacks) to build the container:

```sh
gcloud builds submit --pack image=gcr.io/${GOOGLE_CLOUD_PROJECT}/helloworld
```
docker run --rm -p 9090:8080 -e PORT=8080 helloworld:python

## Run Locally

```sh
docker run --rm gcr.io/${GOOGLE_CLOUD_PROJECT}/helloworld
```

## Test
Expand All @@ -33,12 +41,8 @@ _Note: you may need to install `pytest` using `pip install pytest`._
# Set an environment variable with your GCP Project ID
export GOOGLE_CLOUD_PROJECT=<PROJECT_ID>

# Submit a build using Google Cloud Build
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/helloworld

# Deploy to Cloud Run
gcloud run deploy helloworld \
--image gcr.io/${GOOGLE_CLOUD_PROJECT}/helloworld
gcloud run deploy helloworld --source .
```


Expand Down
39 changes: 3 additions & 36 deletions run/helloworld/e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,7 @@


@pytest.fixture
def container_image():
# Build container image for Cloud Run deployment
subprocess.check_call(
[
"gcloud",
"builds",
"submit",
"--tag",
IMAGE_NAME,
"--project",
PROJECT,
"--quiet",
]
)

yield IMAGE_NAME

# Delete container image
subprocess.check_call(
[
"gcloud",
"container",
"images",
"delete",
IMAGE_NAME,
"--quiet",
"--project",
PROJECT,
]
)


@pytest.fixture
def deployed_service(container_image):
def deployed_service():
# Deploy image to Cloud Run
service_name = f"helloworld-{SUFFIX}"
subprocess.check_call(
Expand All @@ -72,8 +39,8 @@ def deployed_service(container_image):
"run",
"deploy",
service_name,
"--image",
container_image,
"--source",
".",
"--project",
PROJECT,
"--region=us-central1",
Expand Down
10 changes: 8 additions & 2 deletions run/helloworld/noxfile_config.py → run/noxfile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@

TEST_CONFIG_OVERRIDE = {
# You can opt out from the test for specific Python versions.
# We only run the cloud run tests in py38 session.
"ignored_versions": ["2.7", "3.6", "3.7", "3.8"],
"ignored_versions": ["2.7", "3.7", "3.9", "3.10"],
# Old samples are opted out of enforcing Python type hints
# All new samples should feature them
"enforce_type_hints": False,
# An envvar key for determining the project id to use. Change it
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
# build specific Cloud project. You can also use your own string
# to use your own Cloud project.
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
# If you need to use a specific version of pip,
# change pip_version_override to the string representation
# of the version number, for example, "20.2.4"
"pip_version_override": None,
# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
"envs": {},
Expand Down

0 comments on commit 291e314

Please sign in to comment.