์ด ํํ ๋ฆฌ์ผ์์๋ Cloud ๊ฐ์ฌ ๋ก๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ Cloud Storage์์ ์ด๋ฒคํธ๋ฅผ ์์ ํ๋ ์ธ์ฆ๋ Cloud Run ์๋น์ค๋ฅผ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ฌ์ฉํ์ฌ ํ๋ก๋์ ์ํฌ๋ก๋๋ฅผ ๋ฐฐํฌํฉ๋๋ค. Eventarc ํธ๋ฆฌ๊ฑฐ์์ Cloud ๊ฐ์ฌ ๋ก๊ทธ ํญ๋ชฉ์ ๊ธฐ์ค์ผ๋ก ์ด๋ฒคํธ๋ฅผ ํํฐ๋งํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ Cloud ๊ฐ์ฌ ๋ก๊ทธ์ ์ด๋ฒคํธ ํํฐ ํ์ธ์ ์ฐธ์กฐํ์ธ์.
Google Cloud ์ฝ์ ๋๋ Google Cloud CLI๋ฅผ ์ฌ์ฉํ์ฌ ์ด ํํ ๋ฆฌ์ผ์ ์๋ฃํ ์ ์์ต๋๋ค.
๋ชฉํ
์ด ํํ ๋ฆฌ์ผ์์๋ ๋ค์ ๋จ๊ณ๋ฅผ ์งํํฉ๋๋ค.
์ด๋ฒคํธ ์์ค๋ก ์ฌ์ฉํ Cloud Storage ๋ฒํท์ ๋ง๋ญ๋๋ค.
Cloud Run์ ์ด๋ฒคํธ ์์ ์ ์๋น์ค๋ฅผ ๋ฐฐํฌํฉ๋๋ค.
Eventarc ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ญ๋๋ค.
Cloud Storage ๋ฒํท์ ํ์ผ์ ์ ๋ก๋ํ์ฌ ์ด๋ฒคํธ๋ฅผ ์์ฑํ๊ณ Cloud Run ๋ก๊ทธ์์ ํ์ธํฉ๋๋ค.
๋น์ฉ
์ด ๋ฌธ์์์๋ ๋น์ฉ์ด ์ฒญ๊ตฌ๋ ์ ์๋ ๋ค์๊ณผ ๊ฐ์ Google Cloud๊ตฌ์ฑ์์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
ํ๋ก์ ํธ ์ฌ์ฉ๋์ ๊ธฐ์ค์ผ๋ก ์์ ๋น์ฉ์ ์ฐ์ถํ๋ ค๋ฉด ๊ฐ๊ฒฉ ๊ณ์ฐ๊ธฐ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์์ํ๊ธฐ ์ ์
์กฐ์ง์์ ์ ์ํ ๋ณด์ ์ ์ฝ์กฐ๊ฑด์ผ๋ก ์ธํด ๋ค์ ๋จ๊ณ๋ฅผ ์๋ฃํ์ง ๋ชปํ ์ ์์ต๋๋ค. ๋ฌธ์ ํด๊ฒฐ ์ ๋ณด๋ ์ ํ๋ Google Cloud ํ๊ฒฝ์์ ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ฐธ์กฐํ์ธ์.
ํ๋ก์ ํธ ์์ฑ์์๊ฒ๋ ๊ธฐ๋ณธ ์์ ์ ์ญํ (roles/owner
)์ด ๋ถ์ฌ๋ฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Identity and Access Management(IAM) ์ญํ ์๋ ๋๋ถ๋ถ์ Google Cloud ๋ฆฌ์์ค์ ๋ํ ์ ์ฒด ์ก์ธ์ค์ ํ์ํ ๊ถํ์ด ํฌํจ๋๋ฉฐ, ์ด ๋จ๊ณ๋ฅผ ๊ฑด๋๋ธ ์ ์์ต๋๋ค.
ํ๋ก์ ํธ ์์ฑ์๊ฐ ์๋๋ฉด ํ๋ก์ ํธ์์ ์ ํฉํ ์ฃผ ๊ตฌ์ฑ์์ ๋ํด ํ์ ๊ถํ์ ๋ถ์ฌํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด ์ฃผ ๊ตฌ์ฑ์์ Google ๊ณ์ (์ต์ข ์ฌ์ฉ์)์ด๊ฑฐ๋ ์๋น์ค ๊ณ์ (์ ํ๋ฆฌ์ผ์ด์ ๋ฐ ์ปดํจํ ์ํฌ๋ก๋)์ผ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ด๋ฒคํธ ๋์์ ์ญํ ๋ฐ ๊ถํ ํ์ด์ง๋ฅผ ์ฐธ์กฐํ์ธ์.
๊ธฐ๋ณธ์ ์ผ๋ก Cloud Build ๊ถํ์๋ Artifact Registry ์ํฐํฉํธ๋ฅผ ์ ๋ก๋ ๋ฐ ๋ค์ด๋ก๋ํ ์ ์๋ ๊ถํ์ด ํฌํจ๋ฉ๋๋ค.
ํ์ ๊ถํ
ํํ ๋ฆฌ์ผ์ ์๋ฃํ๋ ๋ฐ ํ์ํ ๊ถํ์ ์ป์ผ๋ ค๋ฉด ๊ด๋ฆฌ์์๊ฒ ํ๋ก์ ํธ์ ๋ํ ๋ค์ IAM ์ญํ ์ ๋ถ์ฌํด ๋ฌ๋ผ๊ณ ์์ฒญํ์ธ์.
-
Cloud Build ํธ์ง์(
roles/cloudbuild.builds.editor
) -
Cloud Run ๊ด๋ฆฌ์(
roles/run.admin
) -
Eventarc ๊ด๋ฆฌ์(
roles/eventarc.admin
) -
๋ก๊ทธ ๋ทฐ ์ ๊ทผ์ (
roles/logging.viewAccessor
) -
ํ๋ก์ ํธ IAM ๊ด๋ฆฌ์(
roles/resourcemanager.projectIamAdmin
) -
์๋น์ค ๊ณ์ ๊ด๋ฆฌ์(
roles/iam.serviceAccountAdmin
) -
์๋น์ค ๊ณ์ ์ฌ์ฉ์(
roles/iam.serviceAccountUser
) -
์๋น์ค ์ฌ์ฉ๋ ๊ด๋ฆฌ์(
roles/serviceusage.serviceUsageAdmin
) -
์คํ ๋ฆฌ์ง ๊ด๋ฆฌ์(
roles/storage.admin
)
์ญํ ๋ถ์ฌ์ ๋ํ ์์ธํ ๋ด์ฉ์ ํ๋ก์ ํธ, ํด๋, ์กฐ์ง์ ๋ํ ์ก์ธ์ค ๊ด๋ฆฌ๋ฅผ ์ฐธ์กฐํ์ธ์.
์ปค์คํ ์ญํ ์ด๋ ๋ค๋ฅธ ์ฌ์ ์ ์๋ ์ญํ ์ ํตํด ํ์ํ ๊ถํ์ ์ป์ ์๋ ์์ต๋๋ค.
Google Cloud ์ฝ์ ๋๋ gcloud CLI๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ ๋จ๊ณ๋ฅผ ์๋ฃํฉ๋๋ค.
Console
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Cloud Build, Logging, Pub/Sub, Cloud Run, Cloud Storage, and Eventarc APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Cloud Build, Logging, Pub/Sub, Cloud Run, Cloud Storage, and Eventarc APIs.
- ๊ฐ์ฌ ๋ก๊ทธ์ ๊ธฐ๋ก๋๋ ๋ฐ์ดํฐ ์ก์ธ์ค๋ฅผ ๊ตฌ์ฑํ๋ ค๋ฉด Google Cloud Storage์ ๋ํด ๊ด๋ฆฌ์ ์ฝ๊ธฐ, ๋ฐ์ดํฐ ์ฝ๊ธฐ, ๋ฐ์ดํฐ ์ฐ๊ธฐ ๋ก๊ทธ ์ ํ์ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.
-
Google Cloud ์ฝ์์์ ์๋น์ค ๊ณ์ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์๋น์ค ๊ณ์ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
Google Cloud ์ฝ์์ ํ์ํ ์๋น์ค ๊ณ์ ์ด๋ฆ์ ์ ๋ ฅํฉ๋๋ค.
Google Cloud ์ฝ์์์ ์ด ์ด๋ฆ์ ๊ธฐ๋ฐ์ผ๋ก ์๋น์ค ๊ณ์ ID๊ฐ ์์ฑ๋ฉ๋๋ค. ํ์ํ ๊ฒฝ์ฐ ID๋ฅผ ์์ ํฉ๋๋ค. ๋์ค์ ์ด ID๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
- ์ ํ์ฌํญ: ์๋น์ค ๊ณ์ ์ ๋ํ ์ค๋ช ์ ์ ๋ ฅํฉ๋๋ค.
-
์ง๊ธ ์ก์ธ์ค ์ ์ด๋ฅผ ์ค์ ํ์ง ์์ผ๋ ค๋ฉด ์๋ฃ๋ฅผ ํด๋ฆญํ์ฌ ์๋น์ค ๊ณ์ ๋ง๋ค๊ธฐ๋ฅผ ์๋ฃํฉ๋๋ค.
์ก์ธ์ค ์ ์ด๋ฅผ ์ง๊ธ ์ค์ ํ๋ ค๋ฉด ๋ง๋ค๊ณ ๊ณ์ํ๊ธฐ๋ฅผ ํด๋ฆญํ๊ณ ๋ค์ ๋จ๊ณ๋ก ์งํํฉ๋๋ค.
- ํ๋ก์ ํธ์์ Eventarc ํธ๋ฆฌ๊ฑฐ์ ์ฐ๊ฒฐ๋ ์๋น์ค ๊ณ์ ์ ๋ํด ๋ถ์ฌํ Cloud Run ํธ์ถ์ ๋ฐ Eventarc ์ด๋ฒคํธ ์์ ์ ์ญํ ์ ์ ํํฉ๋๋ค.
์ด๋ ๊ฒ ํ๋ฉด ํ ์คํธ ๋ชฉ์ ์ผ๋ก ํ๋ก์ ํธ์์ ๋ชจ๋ Cloud Run ์๋น์ค ๋ฐ ์์ ์ ๋ํด Cloud Run ํธ์ถ์ ์ญํ ์ด ๋ถ์ฌ๋์ง๋ง, ์ฌ์ฉ์๊ฐ ์๋น์ค์ ์ญํ ์ ๋ถ์ฌํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ Cloud Run ์๋น์ค ๊ถํ ๋ถ์ฌ๋ฅผ ์ฐธ์กฐํ์ธ์.
Cloud Run ํธ์ถ์ ์ญํ ์ ๋ถ์ฌํ์ง ์๊ณ ์ธ์ฆ๋ Cloud Run ์๋น์ค์ ๋ํ ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ค์ด๋ ํธ๋ฆฌ๊ฑฐ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋๋ฉฐ ํ์ฑํ๋ฉ๋๋ค. ํ์ง๋ง ํธ๋ฆฌ๊ฑฐ๊ฐ ์์ํ ๋๋ก ์๋ํ์ง ์๊ณ ๋ค์๊ณผ ๋น์ทํ ๋ฉ์์ง๊ฐ ๋ก๊ทธ์ ํ์๋ฉ๋๋ค.
The request was not authenticated. Either allow unauthenticated invocations or set the proper Authorization header.
- ์ญํ ์ ์ถ๊ฐํ์ผ๋ฉด ๊ณ์ ๋ฐ ์๋ฃ๋ฅผ ํด๋ฆญํ์ฌ ์๋น์ค ๊ณ์ ๋ง๋ค๊ธฐ๋ฅผ ๋ง์นฉ๋๋ค.
gcloud
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Cloud Build, Logging, Pub/Sub, Cloud Run, Cloud Storage, and Eventarc APIs:
gcloud services enable artifactregistry.googleapis.com
cloudbuild.googleapis.com logging.googleapis.com pubsub.googleapis.com run.googleapis.com storage.googleapis.com and eventarc.googleapis.com -
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Cloud Build, Logging, Pub/Sub, Cloud Run, Cloud Storage, and Eventarc APIs:
gcloud services enable artifactregistry.googleapis.com
cloudbuild.googleapis.com logging.googleapis.com pubsub.googleapis.com run.googleapis.com storage.googleapis.com and eventarc.googleapis.com gcloud
๊ตฌ์ฑ์์๋ฅผ ์ ๋ฐ์ดํธํฉ๋๋ค.gcloud components update
- ๊ณ์ ์ ์ฌ์ฉํ์ฌ ๋ก๊ทธ์ธํฉ๋๋ค.
gcloud auth login
- ์ด ํํ ๋ฆฌ์ผ์์ ์ฌ์ฉ๋๋ ๊ตฌ์ฑ ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
export REGION=us-central1 gcloud config set run/region ${REGION} gcloud config set run/platform managed gcloud config set eventarc/location ${REGION} export SERVICE_NAME=helloworld-events
- ๊ฐ์ฌ ๋ก๊ทธ์ ๊ธฐ๋ก๋๋ ๋ฐ์ดํฐ ์ก์ธ์ค๋ฅผ ๊ตฌ์ฑํ๋ ค๋ฉด
storage.googleapis.com
์๋น์ค์ ๋ํดADMIN_READ
,DATA_READ
,DATA_WRITE
๋ก๊ทธ ์ ํ์ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.- ํ๋ก์ ํธ์ IAM ์ ์ฑ
์ ์ฝ๊ณ ํ์ผ์ ์ ์ฅํฉ๋๋ค.
gcloud projects get-iam-policy PROJECT_ID > /tmp/policy.yaml
/tmp/policy.yaml
์์ ์ ์ฑ ์ ์์ ํ๋, ๋ฐ์ดํฐ ์ก์ธ์ค ๊ฐ์ฌ ๋ก๊ทธ ๊ตฌ์ฑ๋ง ์ถ๊ฐํ๊ฑฐ๋ ๋ณ๊ฒฝํฉ๋๋ค.auditConfigs: - auditLogConfigs: - logType: ADMIN_READ - logType: DATA_WRITE - logType: DATA_READ service: storage.googleapis.com
- ๋ค์๊ณผ ๊ฐ์ด ์ IAM ์ ์ฑ
์ ์๋๋ค.
์์ ๋ช ๋ น์ด๊ฐ ๋ค๋ฅธ ๋ณ๊ฒฝ์ฌํญ๊ณผ์ ์ถฉ๋์ ๋ณด๊ณ ํ ๊ฒฝ์ฐ ์ด ๋จ๊ณ๋ฅผ ๋ฐ๋ณตํ๋ฉด์ ํ๋ก์ ํธ์ IAM ์ ์ฑ ์ฝ๊ธฐ๋ฅผ ์์ํฉ๋๋ค.gcloud projects set-iam-policy PROJECT_ID /tmp/policy.yaml
- ํ๋ก์ ํธ์ IAM ์ ์ฑ
์ ์ฝ๊ณ ํ์ผ์ ์ ์ฅํฉ๋๋ค.
- ํ๋ก์ ํธ์ ๋ํ ์๋น์ค ๊ณ์ ์ ๋ง๋ญ๋๋ค.
์๋น์ค ๊ณ์ ์ ๋ง๋ ํ ์๋น์ค ๊ณ์ ์ ์ฌ์ฉํ๊ธฐ๊น์ง ์ต๋ 7๋ถ์ด ๊ฑธ๋ฆด ์ ์์ต๋๋ค. ์๋น์ค ๊ณ์ ์ ๋ง๋ ์งํ์ ์ฌ์ฉํ๋ ค๊ณ ํ๋๋ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด 60์ด ์ด์ ๊ธฐ๋ค๋ ธ๋ค๊ฐ ๋ค์ ์๋ํ์ธ์.gcloud iam service-accounts create sample-service-account \ --description="A sample service account" \ --display-name="Sample service account"
sample-service-account
๊ฐ ์์ฑ๋์๋์ง ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค. ์ถ๋ ฅ์ ๋ค์๊ณผ ๋น์ทํ๊ฒ ํ์๋ฉ๋๋ค.gcloud iam service-accounts list
DISPLAY NAME EMAIL DISABLED Default compute service account PROJECT_NUMBER-compute@developer.gserviceaccount.com False Sample service account sample-service-account@PROJECT_ID.iam.gserviceaccount.com False
- ํ๋ก์ ํธ์์ Eventarc ํธ๋ฆฌ๊ฑฐ์ ์ฐ๊ฒฐ๋ ์๋น์ค ๊ณ์ ์ ๋ํด Cloud Run ํธ์ถ์(
run.invoker
) ๋ฐ Eventarc ์ด๋ฒคํธ ์์ ์(roles/eventarc.eventReceiver
) ์ญํ ์ ๋ถ์ฌํฉ๋๋ค.gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:sample-service-account@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/run.invoker"
gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:sample-service-account@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/eventarc.eventReceiver"
PROJECT_ID
๋ฅผ Google Cloud ํ๋ก์ ํธ ID๋ก ๋ฐ๊ฟ๋๋ค.์ด๋ ๊ฒ ํ๋ฉด ํ ์คํธ ๋ชฉ์ ์ผ๋ก ํ๋ก์ ํธ์์ ๋ชจ๋ Cloud Run ์๋น์ค ๋ฐ ์์ ์ ๋ํด Cloud Run ํธ์ถ์ ์ญํ ์ด ๋ถ์ฌ๋์ง๋ง, ์ฌ์ฉ์๊ฐ ์๋น์ค์ ์ญํ ์ ๋ถ์ฌํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ Cloud Run ์๋น์ค ๊ถํ ๋ถ์ฌ๋ฅผ ์ฐธ์กฐํ์ธ์.
Cloud Run ํธ์ถ์ ์ญํ ์ ๋ถ์ฌํ์ง ์๊ณ ์ธ์ฆ๋ Cloud Run ์๋น์ค์ ๋ํ ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ค์ด๋ ํธ๋ฆฌ๊ฑฐ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋๋ฉฐ ํ์ฑํ๋ฉ๋๋ค. ํ์ง๋ง ํธ๋ฆฌ๊ฑฐ๊ฐ ์์ํ ๋๋ก ์๋ํ์ง ์๊ณ ๋ค์๊ณผ ๋น์ทํ ๋ฉ์์ง๊ฐ ๋ก๊ทธ์ ํ์๋ฉ๋๋ค.
The request was not authenticated. Either allow unauthenticated invocations or set the proper Authorization header.
Artifact Registry ํ์ค ์ ์ฅ์ ๋ง๋ค๊ธฐ
์ปจํ ์ด๋ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ Artifact Registry ํ์ค ์ ์ฅ์๋ฅผ ๋ง๋ญ๋๋ค.Console
- Google Cloud ์ฝ์์์ ์ ์ฅ์ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์ ์ฅ์ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ์ ์ฅ์ ๊ตฌ์ฑ:
- ๊ณ ์ ํ ์ด๋ฆ์ ์ ๋ ฅํ์ธ์.
- ํ์์์ Docker๋ฅผ ์ ํํฉ๋๋ค.
- ๋ชจ๋์ ํ์ค์ ์ ํํฉ๋๋ค.
- ์์น ์ ํ์์ ๋ฆฌ์ ์ ์ ํํฉ๋๋ค.
- ๋ฆฌ์ ๋ชฉ๋ก์์ us-central1(์์ด์ค์)์ ์ ํํฉ๋๋ค.
- ๋ค๋ฅธ ๊ธฐ๋ณธ๊ฐ์ ๊ทธ๋๋ก ๋๊ณ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
gcloud
gcloud artifacts repositories create REPOSITORY \ --repository-format=docker \ --location=$REGION
REPOSITORY
๋ฅผ Artifact Registry ์ ์ฅ์์ ๊ณ ์ ํ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
Cloud Storage ๋ฒํท ๋ง๋ค๊ธฐ
์ด ํํ ๋ฆฌ์ผ์์๋ Cloud Storage๋ฅผ ์ด๋ฒคํธ ์์ค๋ก ์ฌ์ฉํฉ๋๋ค. ์คํ ๋ฆฌ์ง ๋ฒํท์ ๋ง๋ค๋ ค๋ฉด ๋ค์์ ์คํํ์ธ์.
Console
- Google Cloud ์ฝ์์์ ๋ฒํท ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ๋ฒํท ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๊ฐ ๋จ๊ณ๋ฅผ ์๋ฃํ๋ ค๋ฉด ๋ฒํท ์ ๋ณด๋ฅผ ์
๋ ฅํ๊ณ ๊ณ์์ ํด๋ฆญํฉ๋๋ค.
- ๊ณ ์ ํ ์ด๋ฆ์ ์
๋ ฅํ์ธ์. ์๋ฅผ ๋ค๋ฉด
eventarcbucket
์ ๋๋ค. - ์์น ์ ํ์ผ๋ก ๋ฆฌ์ ์ ์ ํํฉ๋๋ค.
- ์์น๋ก us-central1 (์์ด์ค์)์ ์ ํํฉ๋๋ค.
- ๊ธฐ๋ณธ ์คํ ๋ฆฌ์ง ํด๋์ค๋ก ํ์ค์ ์ ํํฉ๋๋ค.
- ์ก์ธ์ค ์ ์ด๋ก ๊ท ์ผ์ ์ ํํฉ๋๋ค.
- ๊ณ ์ ํ ์ด๋ฆ์ ์
๋ ฅํ์ธ์. ์๋ฅผ ๋ค๋ฉด
- ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
gcloud
gcloud storage buckets create gs://events-tutorial-PROJECT_ID/ --location=$REGION
์ด๋ฒคํธ ์์ค๊ฐ ์์ฑ๋๋ฉด Cloud Run์ ์ด๋ฒคํธ ์์ ์ ์๋น์ค๋ฅผ ๋ฐฐํฌํ ์ ์์ต๋๋ค.
Cloud Run์ ์ด๋ฒคํธ ์์ ์ ์๋น์ค ๋ฐฐํฌ
์ด๋ฒคํธ๋ฅผ ์์ ํ๊ณ ๋ก๊น ํ๋ Cloud Run ์๋น์ค๋ฅผ ๋ฐฐํฌํฉ๋๋ค. ์ํ ์ด๋ฒคํธ ์์ ์ ์๋น์ค๋ฅผ ๋ฐฐํฌํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ฝ์
- ์ํ ์ ์ฅ์๋ฅผ GitHub ๊ณ์ ์ ํด๋ก ํฉ๋๋ค.
- GitHub์์ GoogleCloudPlatform/golang-samples๋ก ์ด๋ํฉ๋๋ค.
- ํฌํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ์ ์ฅ์๋ฅผ ํฌํฌํ ์์น๋ฅผ ์ ํํฉ๋๋ค.
- GitHub์์ GoogleCloudPlatform/java-docs-samples๋ก ์ด๋ํฉ๋๋ค.
- ํฌํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ์ ์ฅ์๋ฅผ ํฌํฌํ ์์น๋ฅผ ์ ํํฉ๋๋ค.
- GitHub์์ GoogleCloudPlatform/dotnet-docs-samples๋ก ์ด๋ํฉ๋๋ค.
- ํฌํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ์ ์ฅ์๋ฅผ ํฌํฌํ ์์น๋ฅผ ์ ํํฉ๋๋ค.
- GitHub์์ GoogleCloudPlatform/nodejs-docs-samplesโ๋ก ์ด๋ํฉ๋๋ค.
- ํฌํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ์ ์ฅ์๋ฅผ ํฌํฌํ ์์น๋ฅผ ์ ํํฉ๋๋ค.
- GitHub์์ GoogleCloudPlatform/python-docs-samples๋ก ์ด๋ํฉ๋๋ค.
- ํฌํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ์ ์ฅ์๋ฅผ ํฌํฌํ ์์น๋ฅผ ์ ํํฉ๋๋ค.
- Google Cloud ์ฝ์์์ ์๋น์ค ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์๋น์ค ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํ์ฌ ์๋น์ค ๋ง๋ค๊ธฐ ์์์ ํ์ํฉ๋๋ค.
- ์ ์ฅ์์์ ์ง์์ ์ผ๋ก ๋ฐฐํฌ๋ฅผ ์ ํํฉ๋๋ค.
GitHub ์ ์ฅ์์ ๋ณ๊ฒฝ์ฌํญ์ Artifact Registry์ ์ปจํ ์ด๋ ์ด๋ฏธ์ง์ ์๋์ผ๋ก ๋น๋๋๊ณ Cloud Run์ ๋ฐฐํฌ๋ฉ๋๋ค.
- Cloud Build๋ก ์ค์ ์ ํด๋ฆญํ์ฌ Cloud Build๋ก ์ค์ ์์์ ์ฝ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด Cloud Build API ๋ฐ Artifact Analysis API๋ฅผ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.
- GitHub๋ก GitHub๋ฅผ ์ ํํฉ๋๋ค.
- ๋ฉ์์ง๊ฐ ํ์๋๋ฉด Google Cloud Build ์ค์น๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ์ ์ฅ์๋ก ํฌํฌํ GitHub ์ ์ฅ์๋ฅผ ์ ํํฉ๋๋ค.
- ๋ค์์ ํด๋ฆญํฉ๋๋ค.
- ๋ถ๊ธฐ ํ๋์
^main$
๋ฅผ ์ ๋ ฅํฉ๋๋ค. - Dockerfile์ผ๋ก Dockerfile์ ์ ํํ๊ณ Dockerfile์ ์์ค ์์น๋ฅผ ์ ๊ณตํฉ๋๋ค.
eventarc/audit-storage/Dockerfile
๋๋
eventarc/audit_storage/Dockerfile
(Go)
- ์ ์ฅ์ ํด๋ฆญํฉ๋๋ค.
- ์๋น์ค ๋ง๋ค๊ธฐ ์์์ ์๋น์ค ์ด๋ฆ์ ์
๋ ฅํฉ๋๋ค.
์๋ฅผ ๋ค๋ฉด
helloworld-events
์ ๋๋ค. - ์๋น์ค๋ฅผ ๋ฐฐ์นํ ๋ฆฌ์ ์ผ๋ก us-central1(์์ด์ค์)์ ์ ํํฉ๋๋ค.
- Cloud Run ์๋น์ค์์ ํ์ฉํ ์ธ๊ทธ๋ ์ค ํธ๋ํฝ์ ๊ธฐ์ค์ผ๋ก ์ธ๊ทธ๋ ์ค ์ต์ ์ ์ ํํฉ๋๋ค.
- ์ธ์ฆ ํ์๋ฅผ ์ ํํฉ๋๋ค.
- ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
Go

์๋ฐ

.NET

Node.js

Python

gcloud
- GitHub ์ ์ฅ์๋ฅผ ํด๋ก ํฉ๋๋ค.
Go
git clone https://github.com/GoogleCloudPlatform/golang-samples.git cd golang-samples/eventarc/audit_storage
์๋ฐ
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git cd java-docs-samples/eventarc/audit-storage
.NET
git clone https://github.com/GoogleCloudPlatform/dotnet-docs-samples.git cd dotnet-docs-samples/eventarc/audit-storage
Node.js
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git cd nodejs-docs-samples/eventarc/audit-storage
Python
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git cd python-docs-samples/eventarc/audit-storage
- ์ปจํ
์ด๋๋ฅผ ๋น๋ํ๊ณ Cloud Build์ ์
๋ก๋ํฉ๋๋ค.
gcloud builds submit --tag $REGION-docker.pkg.dev/PROJECT_ID/REPOSITORY/$SERVICE_NAME:v1
- ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ Cloud Run์ ๋ฐฐํฌํฉ๋๋ค.
gcloud run deploy $SERVICE_NAME \ --image $REGION-docker.pkg.dev/PROJECT_ID/REPOSITORY/$SERVICE_NAME:v1
์ธ์ฆ๋์ง ์์ ํธ์ถ์ ํ์ฉํ ์ง ๋ฌป๋ ๋ฉ์์ง๊ฐ ํ์๋๋ฉด
n
์ ์ ๋ ฅํฉ๋๋ค.๋ฐฐํฌ๊ฐ ์ฑ๊ณตํ๋ฉด ๋ช ๋ น์ค์ ์๋น์ค URL์ด ํ์๋ฉ๋๋ค.
์ด์ helloworld-events
๋ผ๋ ์ด๋ฒคํธ ์์ ์ ์๋น์ค๋ฅผ Cloud Run์ ๋ฐฐํฌํ์ผ๋ฏ๋ก ํธ๋ฆฌ๊ฑฐ๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
Eventarc ํธ๋ฆฌ๊ฑฐ ๋ง๋ค๊ธฐ
Eventarc ํธ๋ฆฌ๊ฑฐ๋ Cloud Storage ๋ฒํท์ ์ด๋ฒคํธ๋ฅผ helloworld-events
Cloud Run ์๋น์ค๋ก ์ ์กํฉ๋๋ค.
Console
- Google Cloud Console์์ ํธ๋ฆฌ๊ฑฐ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ํธ๋ฆฌ๊ฑฐ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ํธ๋ฆฌ๊ฑฐ ์ด๋ฆ์ ์
๋ ฅํฉ๋๋ค.
ํธ๋ฆฌ๊ฑฐ์ ID์ด๋ฉฐ ๋ฌธ์๋ก ์์ํด์ผ ํฉ๋๋ค. ์ต๋ 63์(์๋ฌธ ๊ธฐ์ค)์ ์๋ฌธ์, ์ซ์, ํ์ดํ์ ํฌํจํ ์ ์์ต๋๋ค.
- ํธ๋ฆฌ๊ฑฐ ์ ํ์ ์ ํํฉ๋๋ค.
- ํผ์คํธํํฐ โ Google Cloud ์ ๊ณต์ ์ฒด(์ง์ ๋๋ Cloud ๊ฐ์ฌ ๋ก๊ทธ ํญ๋ชฉ์ ํตํด) ๋๋ Pub/Sub ๋ฉ์์ง๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ก๋ ์ด๋ฒคํธ๋ฅผ ํํฐ๋งํฉ๋๋ค.
- ์๋ํํฐ: ํ์ฌ ์ ๊ณต์ ์ฒด์์ ๋ณด๋ธ ์ด๋ฒคํธ๋ฅผ ํํฐ๋งํฉ๋๋ค.
- ์ด๋ฒคํธ ์ ๊ณต์ ๋ชฉ๋ก์์ Cloud Storage๋ฅผ ์ด๋ฒคํธ ์์ค๋ก ์ ํํฉ๋๋ค.
- ์ด๋ฒคํธ ์ ํ ๋ชฉ๋ก์์ storage.objects.create๋ฅผ ์ ํํฉ๋๋ค.
- ๋ฆฌ์ ๋ชฉ๋ก์์ ์ด๋ฒคํธ๋ฅผ ์์ ํ ๋ฆฌ์ ์ผ๋ก us-central1์ ์ ํํฉ๋๋ค.
- ์์ฑํ ์๋น์ค ๊ณ์ ์ ์ ํํฉ๋๋ค. ์๋ฅผ ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
SERVICE_ACCOUNT_ID@PROJECT_ID
.iam.gserviceaccount.com. - ์ด๋ฒคํธ ๋์ ๋ชฉ๋ก์์ Cloud Run์ ์ ํํฉ๋๋ค.
- Cloud Run ์๋น์ค ์ ํ ๋ชฉ๋ก์์ helloworld-events๋ฅผ ์ ํํฉ๋๋ค.
- ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค. Cloud Run ์ฝ์ ํ์ด์ง๋ฅผ ์ฌ์ฉํ์ฌ Eventarc ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ค ์๋ ์์ต๋๋ค.
gcloud
- Cloud Storage ์ด๋ฒคํธ๋ฅผ ํํฐ๋งํ๊ณ ์์ฑ๋ ์๋น์ค ๊ณ์ ์ ์ฌ์ฉํ๋ ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ญ๋๋ค.
gcloud eventarc triggers create events-tutorial-trigger \ --destination-run-service=$SERVICE_NAME \ --destination-run-region=$REGION \ --event-filters="type=google.cloud.audit.log.v1.written" \ --event-filters="serviceName=storage.googleapis.com" \ --event-filters="methodName=storage.objects.create" \ --service-account=sample-service-account@PROJECT_ID.iam.gserviceaccount.com
PROJECT_ID
๋ฅผ Google Cloud ํ๋ก์ ํธ ID๋ก ๋ฐ๊ฟ๋๋ค.๊ฐ ํญ๋ชฉ์ ์๋ฏธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
type
: ํธ๋ฆฌ๊ฑฐ์ ํํฐ ๊ธฐ์ค์ด ์ถฉ์กฑ๋๋ฉด ๊ฐ์ฌ ๋ก๊ทธ๊ฐ ์์ฑ๋๋๋ก ์ง์ ํฉ๋๋ค.serviceName
: Cloud Storage์ ํด๋นํ๋ ๊ฐ์ฌ ๋ก๊ทธ๋ฅผ ์์ฑํ๋ ์๋น์ค์ ๋๋ค.methodName
:storage.objects.create
์ ํด๋นํ๋ ๊ฐ์ฌ ๋์ ์์ ์ ๋๋ค.
events-tutorial-trigger
๋ผ๋ ํธ๋ฆฌ๊ฑฐ๊ฐ ์์ฑ๋ฉ๋๋ค. events-tutorial-trigger
์ด ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์๋์ง ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค.gcloud eventarc triggers list --location=$REGION
ํธ๋ฆฌ๊ฑฐ
events-tutorial-trigger
๊ฐ helloworld-events
์ ๋์๊ณผ ํจ๊ป ๋์ด๋ฉ๋๋ค.
์ด๋ฒคํธ ์์ฑ ๋ฐ ํ์ธ
- ์ด๋ฒคํธ๋ฅผ ์์ฑํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ฝ์
- ํ์ผ ์ด๋ฆ์ด
random.txt
์ด๊ณ ํ ์คํธ๊ฐ 'Hello World'์ธ ํ ์คํธ ํ์ผ์ ๋ง๋ญ๋๋ค. - Google Cloud ์ฝ์์์ ๋ฒํท ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ๋ง๋ ์คํ ๋ฆฌ์ง ๋ฒํท์ ์ ํํฉ๋๋ค.
- ๊ฐ์ฒด ํญ์์ ํ์ผ ์
๋ก๋๋ฅผ ํด๋ฆญํ๊ณ
random.txt
ํ์ผ์ ์ ๋ก๋ํฉ๋๋ค.
gcloud
ํ ์คํธ ํ์ผ์ Cloud Storage์ ์ ๋ก๋ํฉ๋๋ค.
echo "Hello World" > random.txt gcloud storage cp random.txt gs://events-tutorial-PROJECT_ID/random.txt
- ํ์ผ ์ด๋ฆ์ด
- ๋ก๊ทธ ํญ๋ชฉ์ ๋ณด๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
- Google Cloud ์ฝ์์์ ์๋น์ค ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์๋น์ค ๋ชฉ๋ก์์ ์์ฑํ ์๋น์ค์ ์ด๋ฆ์ ํด๋ฆญํ์ฌ ์๋น์ค ์ธ๋ถ์ ๋ณด ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ๋ก๊ทธ ํญ์ ํด๋ฆญํ์ฌ ์ด ์๋น์ค์ ๋ชจ๋ ๋ฒ์ ์ ๋ํ ์์ฒญ ๋ฐ ์ปจํ ์ด๋ ๋ก๊ทธ๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ๋ก๊ทธ ์ฌ๊ฐ๋ ์์ค์ผ๋ก ํํฐ๋งํ ์ ์์ต๋๋ค.
- ๋ค์๊ณผ ๊ฐ์ ๋ก๊ทธ ํญ๋ชฉ์ ์ฐพ์ต๋๋ค.
์ฌ๊ธฐ์Detected change in Cloud Storage bucket: storage.googleapis.com/projects/_/buckets/BUCKET_NAME/objects/random.txt
BUCKET_NAME
์ Cloud Storage ๋ฒํท์ ์ด๋ฆ์ ๋๋ค. -
gcloud logging read "resource.labels.service_name=helloworld-events AND textPayload:random.txt" --format=json
- ๋ค์๊ณผ ๊ฐ์ ๋ก๊ทธ ํญ๋ชฉ์ ์ฐพ์ต๋๋ค.
์ฌ๊ธฐ์Detected change in Cloud Storage bucket: storage.googleapis.com/projects/_/buckets/BUCKET_NAME/objects/random.txt
BUCKET_NAME
์ Cloud Storage ๋ฒํท์ ์ด๋ฆ์ ๋๋ค.
Console
gcloud
Cloud Run์ ์ด๋ฒคํธ ์์ ์ ์๋น์ค๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๋ฐฐํฌํ๊ณ , Eventarc ํธ๋ฆฌ๊ฑฐ๋ฅผ ๋ง๋ค๊ณ , Cloud Storage์์ ์ด๋ฒคํธ๋ฅผ ์์ฑํ๊ณ , ์ด๋ฅผ Cloud Run ๋ก๊ทธ์์ ํ์ธํ์ต๋๋ค.
์ญ์
Cloud Run์์๋ ์๋น์ค๋ฅผ ์ฌ์ฉํ์ง ์์ ๋ ๋น์ฉ์ด ์ฒญ๊ตฌ๋์ง ์์ง๋ง Artifact Registry์ ์ปจํ ์ด๋ ์ด๋ฏธ์ง ์ ์ฅ, Cloud Storage ๋ฒํท์ ํ์ผ ์ ์ฅ, Eventarc ๋ฆฌ์์ค์ ๋ํ ์๊ธ์ ๋ถ๊ณผ๋ ์ ์์ต๋๋ค.๋ค์๊ณผ ๊ฐ์ ์์ ์ ํ ์ ์์ต๋๋ค.
๋๋ Google Cloud ํ๋ก์ ํธ๋ฅผ ์ญ์ ํ์ฌ ๋น์ฉ ์ฒญ๊ตฌ๋ฅผ ๋ฐฉ์งํ ์ ์์ต๋๋ค. Google Cloud ํ๋ก์ ํธ๋ฅผ ์ญ์ ํ๋ฉด ํ๋ก์ ํธ ๋ด์์ ์ฌ์ฉ๋๋ ๋ชจ๋ ๋ฆฌ์์ค์ ๋ํ ๋น์ฉ ์ฒญ๊ตฌ๊ฐ ์ค์ง๋ฉ๋๋ค.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID