1
- # Google Cloud Eventarc Python Samples
1
+ # Eventarc Python Samples
2
2
3
- [ ![ Open in Cloud Shell] [ shell_img ]] [ shell_link ]
4
-
5
- [ shell_img ] : http://gstatic.com/cloudssh/images/open-btn.png
6
- [ shell_link ] : https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=blog/README.md
7
-
8
- This directory contains samples for Google Cloud Eventarc.
3
+ This directory contains python samples for Eventarc.
9
4
10
5
## Samples
11
6
12
- | Sample | Description | Deploy |
13
- | ------------------------------- | ------------------------ | ------------- |
14
- | [ Events – Pub/Sub] [ events_pubsub ] | Event-driven service with Events for Cloud Run for Pub/Sub | - |
15
- | [ Anthos Events – Pub/Sub] [ anthos_events_pubsub ] | Event-driven service with Events for Cloud Run on Anthos for Pub/Sub | - |
16
- | [ Events – GCS] [ events_storage ] | Event-driven service with Events for Cloud Run for GCS | - |
17
- | [ Anthos Events – GCS] [ anthos_events_storage ] | Event-driven service with Events for Cloud Run on Anthos for GCS | - |
18
-
19
- For more Cloud Run samples beyond Python, see the main list in the [ Cloud Run Samples repository] ( https://github.com/GoogleCloudPlatform/cloud-run-samples ) .
7
+ - [ Pub/Sub] [ events_pubsub ]
8
+ - [ Audit Logs – Cloud Storage] [ events_audit_storage ]
9
+ - [ Generic] [ events_generic ]
20
10
21
11
## Setup
22
12
23
13
1 . [ Set up for Cloud Run development] ( https://cloud.google.com/run/docs/setup )
24
14
25
- 2 . Clone this repository:
26
-
27
- ```
28
- git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
29
- ```
15
+ 1 . Install [ ` pip ` ] [ pip ] and [ ` virtualenv ` ] [ virtualenv ] if you do not already have them.
30
16
31
- Note: Some samples in the list above are hosted in other repositories. They are noted with the symbol "➥".
32
-
33
- ## How to run a sample locally
34
-
35
- Install [`pip`][pip] and [`virtualenv`][virtualenv] if you do not already have them.
36
-
37
- You may want to refer to the [`Python Development Environment Setup Guide`][setup] for Google Cloud Platform for instructions.
17
+ - You may want to refer to the [ ` Python Development Environment Setup Guide ` ] [ setup ] for Google Cloud Platform for instructions.
38
18
39
19
1 . Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
40
20
@@ -55,87 +35,9 @@ You may want to refer to the [`Python Development Environment Setup Guide`][setu
55
35
python main.py
56
36
` ` `
57
37
58
- ## How to run a sample in a container
59
-
60
- 1. [Install docker locally](https://docs.docker.com/install/)
61
-
62
- 2. [Build the sample container](https://cloud.google.com/run/docs/building/containers#building_locally_and_pushing_using_docker):
63
-
64
- ```
65
- export SAMPLE=<SAMPLE_NAME>
66
- cd $SAMPLE
67
- docker build --tag $SAMPLE .
68
- ```
69
-
70
- 3. [Run containers locally](https://cloud.google.com/run/docs/testing/local)
71
-
72
- With the built container:
73
-
74
- ```
75
- PORT=8080 && docker run --rm -p 8080:${PORT} -e PORT=${PORT} $SAMPLE
76
- ```
77
-
78
- Overriding the built container with local code:
79
-
80
- ```
81
- PORT=8080 && docker run --rm \
82
- -p 8080:${PORT} -e PORT=${PORT} \
83
- -v $PWD:/app $SAMPLE
84
- ```
85
-
86
- Injecting your service account key for access to GCP services:
87
-
88
- ```
89
- # Set the name of the service account key within the container
90
- export SA_KEY_NAME=my-key-name-123
91
-
92
- PORT=8080 && docker run --rm \
93
- -p 8080:${PORT} \
94
- -e PORT=${PORT} \
95
- -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/${SA_KEY_NAME}.json \
96
- -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/${SA_KEY_NAME}.json:ro \
97
- -v $PWD:/app $SAMPLE
98
- ```
99
-
100
- * Use the --volume (-v) flag to inject the credential file into the container
101
- (assumes you have already set your `GOOGLE_APPLICATION_CREDENTIALS`
102
- environment variable on your machine)
103
-
104
- * Use the --environment (-e) flag to set the `GOOGLE_APPLICATION_CREDENTIALS`
105
- variable inside the container
106
-
107
- Learn more about [testing your container image locally.][testing]
108
-
109
- ## Deploying a Cloud Run service
110
-
111
- 1. Set an environment variable with your GCP Project ID
112
- ```
113
- export GOOGLE_CLOUD_PROJECT=<PROJECT_ID>
114
- ```
115
-
116
- 1. Submit a build using Google Cloud Build
117
- ```
118
- gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
119
- ```
120
-
121
- 1. Deploy to Cloud Run
122
- ```
123
- gcloud run deploy $SAMPLE --image gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
124
- ```
125
-
126
- Choose a particular sample for information about triggering the service with an event.
127
-
128
- See [Building containers][run_build] and [Deploying container images][run_deploy]
129
- for more information.
130
-
131
- [run_docs]: https://cloud.google.com/run/docs/
132
- [run_build]: https://cloud.google.com/run/docs/building/containers
133
- [run_deploy]: https://cloud.google.com/run/docs/deploying
134
- [events_pubsub]: pubsub/README.md
135
- [anthos_events_pubsub]: pubsub/anthos.md
136
- [events_storage]: audit-storage/README.md
137
- [anthos_events_storage]: audit-storage/anthos.md
138
- [testing]: https://cloud.google.com/run/docs/testing/local#running_locally_using_docker_with_access_to_services
38
+ [events_pubsub]: pubsub/
39
+ [events_audit_storage]: audit-storage/
40
+ [events_generic]: generic/
139
41
[setup]: https://cloud.google.com/python/setup
140
42
[pip]: https://pip.pypa.io/
141
43
[virtualenv]: https://virtualenv.pypa.io/
0 commit comments