{"id":79445,"date":"2024-10-08T02:54:11","date_gmt":"2024-10-07T23:24:11","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/deploying-a-stateless-container-in-cloud-run-2j11\/"},"modified":"2024-10-08T02:54:11","modified_gmt":"2024-10-07T23:24:11","slug":"deploying-a-stateless-container-in-cloud-run-2j11","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/deploying-a-stateless-container-in-cloud-run-2j11\/","title":{"rendered":"\u0627\u0633\u062a\u0642\u0631\u0627\u0631 \u06cc\u06a9 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0628\u062f\u0648\u0646 \u062d\u0627\u0644\u062a \u062f\u0631 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc"},"content":{"rendered":"<p>Summarize this content to 400 words in Persian Lang <\/p>\n<p>\u0645\u0646 \u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0642\u0631\u0627\u0631 \u06cc\u06a9 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0633\u0627\u062f\u0647 \u0631\u0627 \u062f\u0631 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc \u0646\u0634\u0627\u0646 \u062e\u0648\u0627\u0647\u0645 \u062f\u0627\u062f.<\/p>\n<p>Cloud Run \u06cc\u06a9 \u067e\u0644\u062a \u0641\u0631\u0645 \u06a9\u0627\u0645\u0644\u0627\u064b \u0645\u062f\u06cc\u0631\u06cc\u062a \u0634\u062f\u0647 \u0627\u0633\u062a \u06a9\u0647 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u06a9\u062f \u062e\u0648\u062f \u0631\u0627 \u0645\u0633\u062a\u0642\u06cc\u0645\u0627\u064b \u062f\u0631 \u0628\u0627\u0644\u0627\u06cc \u0632\u06cc\u0631\u0633\u0627\u062e\u062a \u0645\u0642\u06cc\u0627\u0633 \u067e\u0630\u06cc\u0631 Google \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f. Cloud Run \u0633\u0627\u062f\u0647\u060c \u062e\u0648\u062f\u06a9\u0627\u0631 \u0648 \u0628\u0631\u0627\u06cc \u0628\u0647\u0631\u0647 \u0648\u0631\u06cc \u0628\u06cc\u0634\u062a\u0631 \u0634\u0645\u0627 \u0637\u0631\u0627\u062d\u06cc \u0634\u062f\u0647 \u0627\u0633\u062a.<\/p>\n<p>\u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0628\u0631\u0646\u0627\u0645\u0647 \u0633\u0627\u062f\u0647 hello world \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u06a9\u062a\u0627\u0628\u062e\u0627\u0646\u0647 fastapi (python)<br \/>\n\u0628\u0631\u0646\u0627\u0645\u0647 \u0631\u0627 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u06cc \u06a9\u0646\u06cc\u062f<br \/>\n\u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 \u0631\u0627 \u0628\u0627 GCP \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f<br \/>\n\u0627\u0632 \u0637\u0631\u06cc\u0642 \u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 github\u060c \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0631\u0627 \u0631\u0648\u06cc \u0633\u0631\u0648\u06cc\u0633 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc \u0645\u0633\u062a\u0642\u0631 \u06a9\u0646\u06cc\u062f<\/p>\n<p>\u0645\u0646 \u0633\u0646\u062f \u0631\u0633\u0645\u06cc fastapi \u0631\u0627 \u062f\u0646\u0628\u0627\u0644 \u06a9\u0631\u062f\u0645 \u062a\u0627 \u06cc\u06a9 \u0628\u0631\u0646\u0627\u0645\u0647 hello world \u0631\u0627 \u0628\u0686\u0631\u062e\u0627\u0646\u0645\u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0627\u0644\u0632\u0627\u0645\u0627\u062a. txt  \u0641\u0627\u06cc\u0644<\/p>\n<p>fastapi[standard]\npydantic&gt;=2.7.0,&lt;3.0.0<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>\u06cc\u06a9 \u0641\u0647\u0631\u0633\u062a \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f \u0648 \u0622\u0646 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<br \/>\n\u06cc\u06a9 \u0641\u0627\u06cc\u0644 \u062e\u0627\u0644\u06cc \u0628\u0633\u0627\u0632\u06cc\u062f init.py<br \/>\n\u06cc\u06a9 \u0641\u0627\u06cc\u0644 main.py \u0628\u0627:<\/p>\n<p>from typing import Union<\/p>\n<p>from fastapi import FastAPI<\/p>\n<p>app = FastAPI()<\/p>\n<p>@app.get(&#8220;https:\/\/dev.to\/&#8221;)<br \/>\ndef read_root():<br \/>\n    return {&#8220;Hello&#8221;: &#8220;World&#8221;}<\/p>\n<p>@app.get(&#8220;\/items\/{item_id}&#8221;)<br \/>\ndef read_item(item_id: int, q: Union[str, None] = None):<br \/>\n    return {&#8220;item_id&#8221;: item_id, &#8220;q&#8221;: q}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>\u06cc\u06a9 Dockerfile \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/p>\n<p>FROM python:3.9<\/p>\n<p>WORKDIR \/code<\/p>\n<p>COPY .\/requirements.txt \/code\/requirements.txt<\/p>\n<p>RUN pip install &#8211;no-cache-dir &#8211;upgrade -r \/code\/requirements.txt<\/p>\n<p>COPY .\/app \/code\/app<\/p>\n<p>CMD [&#8220;fastapi&#8221;, &#8220;run&#8221;, &#8220;app\/main.py&#8221;, &#8220;&#8211;port&#8221;, &#8220;80&#8221;]\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>\u0627\u06a9\u0634\u0646 GitHub\u0628\u0631\u0627\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0641\u0631\u0622\u06cc\u0646\u062f \u0627\u0642\u062f\u0627\u0645\u0627\u062a GitHub \u0628\u062a\u0648\u0627\u0646\u062f \u0641\u0627\u06cc\u0644 YAML \u0631\u0627 \u062f\u0631\u06cc\u0627\u0641\u062a \u06a9\u0646\u062f\u060c \u0645\u06a9\u0627\u0646 \u062e\u0627\u0635\u06cc \u0628\u0631\u0627\u06cc \u0632\u0646\u062f\u06af\u06cc \u0622\u0646 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f. \u0647\u0631 \u0645\u062e\u0632\u0646 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06a9\u0634\u0646 \u0647\u0627 \u0628\u0647 \u06cc\u06a9 \u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc \u0628\u0647 \u0646\u0627\u0645 \/.github\/workflows \u0646\u06cc\u0627\u0632 \u062f\u0627\u0631\u062f<\/p>\n<p>*\u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u0627\u06cc\u0646 \u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 \u0628\u0627 GCP \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u0628\u06cc\u0634\u062a\u0631 *<\/p>\n<p># This workflow build and push a Docker container to Google Artifact Registry<br \/>\n# and deploy it on Cloud Run when a commit is pushed to the $default-branch<br \/>\n# branch.<br \/>\n#<br \/>\n# To configure this workflow:<br \/>\n#<br \/>\n# 1. Enable the following Google Cloud APIs:<br \/>\n#<br \/>\n#    &#8211; Artifact Registry (artifactregistry.googleapis.com)<br \/>\n#    &#8211; Cloud Run (run.googleapis.com)<br \/>\n#    &#8211; IAM Credentials API (iamcredentials.googleapis.com)<br \/>\n#<br \/>\n#    You can learn more about enabling APIs at<br \/>\n#    https:\/\/support.google.com\/googleapi\/answer\/6158841.<br \/>\n#<br \/>\n# 2. Create and configure a Workload Identity Provider for GitHub:<br \/>\n#    https:\/\/github.com\/google-github-actions\/auth#preferred-direct-workload-identity-federation.<br \/>\n#<br \/>\n#    Depending on how you authenticate, you will need to grant an IAM principal<br \/>\n#    permissions on Google Cloud:<br \/>\n#<br \/>\n#    &#8211; Artifact Registry Administrator (roles\/artifactregistry.admin)<br \/>\n#    &#8211; Cloud Run Developer (roles\/run.developer)<br \/>\n#<br \/>\n#    You can learn more about setting IAM permissions at<br \/>\n#    https:\/\/cloud.google.com\/iam\/docs\/manage-access-other-resources<br \/>\n#<br \/>\n# 3. Change the values in the &#8220;env&#8221; block to match your values.<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>\u06cc\u06a9 \u0641\u0627\u06cc\u0644 google-cloudrun-docker.yml \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/p>\n<p>name: &#8216;Build and Deploy to Cloud Run&#8217;<\/p>\n<p>on:<br \/>\n  push:<br \/>\n    branches:<br \/>\n      &#8211; &#8216;$default-branch&#8217;<\/p>\n<p>env:<br \/>\n  PROJECT_ID: &#8216;my-project&#8217; # TODO: update to your Google Cloud project ID<br \/>\n  REGION: &#8216;us-central1&#8217; # TODO: update to your region<br \/>\n  SERVICE: &#8216;my-service&#8217; # TODO: update to your service name<br \/>\n  WORKLOAD_IDENTITY_PROVIDER: &#8216;projects\/123456789\/locations\/global\/workloadIdentityPools\/my-pool\/providers\/my-provider&#8217; # TODO: update to your workload identity provider<\/p>\n<p>jobs:<br \/>\n  deploy:<br \/>\n    runs-on: &#8216;ubuntu-latest&#8217;<\/p>\n<p>    permissions:<br \/>\n      contents: &#8216;read&#8217;<br \/>\n      id-token: &#8216;write&#8217;<\/p>\n<p>    steps:<br \/>\n      &#8211; name: &#8216;Checkout&#8217;<br \/>\n        uses: &#8216;actions\/checkout@692973e3d937129bcbf40652eb9f2f61becf3332&#8217; # actions\/checkout@v4<\/p>\n<p>      # Configure Workload Identity Federation and generate an access token.<br \/>\n      #<br \/>\n      # See https:\/\/github.com\/google-github-actions\/auth for more options,<br \/>\n      # including authenticating via a JSON credentials file.<br \/>\n      &#8211; id: &#8216;auth&#8217;<br \/>\n        name: &#8216;Authenticate to Google Cloud&#8217;<br \/>\n        uses: &#8216;google-github-actions\/auth@f112390a2df9932162083945e46d439060d66ec2&#8217; # google-github-actions\/auth@v2<br \/>\n        with:<br \/>\n          workload_identity_provider: &#8216;${{ env.WORKLOAD_IDENTITY_PROVIDER }}&#8217;<\/p>\n<p>      # BEGIN &#8211; Docker auth and build<br \/>\n      #<br \/>\n      # If you already have a container image, you can omit these steps.<br \/>\n      &#8211; name: &#8216;Docker Auth&#8217;<br \/>\n        uses: &#8216;docker\/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567&#8217; # docker\/login-action@v3<br \/>\n        with:<br \/>\n          username: &#8216;oauth2accesstoken&#8217;<br \/>\n          password: &#8216;${{ steps.auth.outputs.auth_token }}&#8217;<br \/>\n          registry: &#8216;${{ env.REGION }}-docker.pkg.dev&#8217;<\/p>\n<p>      &#8211; name: &#8216;Build and Push Container&#8217;<br \/>\n        run: |-<br \/>\n          DOCKER_TAG=&#8221;$${{ env.REGION }}-docker.pkg.dev\/${{ env.PROJECT_ID }}\/${{ env.SERVICE }}:${{ github.sha }}&#8221;<br \/>\n          docker build &#8211;tag &#8220;${DOCKER_TAG}&#8221; .<br \/>\n          docker push &#8220;${DOCKER_TAG}&#8221;<br \/>\n      &#8211; name: &#8216;Deploy to Cloud Run&#8217;<\/p>\n<p>        # END &#8211; Docker auth and build<\/p>\n<p>        uses: &#8216;google-github-actions\/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17&#8217; # google-github-actions\/deploy-cloudrun@v2<br \/>\n        with:<br \/>\n          service: &#8216;${{ env.SERVICE }}&#8217;<br \/>\n          region: &#8216;${{ env.REGION }}&#8217;<br \/>\n          # NOTE: If using a pre-built image, update the image name below:<\/p>\n<p>          image: &#8216;${{ env.REGION }}-docker.pkg.dev\/${{ env.PROJECT_ID }}\/${{ env.SERVICE }}:${{ github.sha }}&#8217;<br \/>\n      # If required, use the Cloud Run URL output in later steps<br \/>\n      &#8211; name: &#8216;Show output&#8217;<br \/>\n        run: |2-<\/p>\n<p>          echo ${{ steps.deploy.outputs.url }}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>\u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc<\/p>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u0628\u0627\u06cc\u062f \u06cc\u06a9 \u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc \u0645\u0627\u0646\u0646\u062f:<\/p>\n<p>\u251c\u2500\u2500 app<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py<br \/>\n\u2502   \u2514\u2500\u2500 main.py<br \/>\n\u251c\u2500\u2500 Dockerfile<br \/>\n\u2514\u2500\u2500 requirements.txt<br \/>\n\u2514\u2500\u2500 requirements.txt<br \/>\n\u251c\u2500\u2500 .github<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 workflows<br \/>\n         \u251c\u2500\u2500 google-cloudrun-docker.yml<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>&gt; 1. Create a new repo in gitHUb<br \/>\n&gt; 2. Push your exisisting code to new repository on default branch<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<div data-article-id=\"2028055\" id=\"article-body\">\n<p><\/p>\n<p>\u0645\u0646 \u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0642\u0631\u0627\u0631 \u06cc\u06a9 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0633\u0627\u062f\u0647 \u0631\u0627 \u062f\u0631 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc \u0646\u0634\u0627\u0646 \u062e\u0648\u0627\u0647\u0645 \u062f\u0627\u062f.<\/p>\n<blockquote>\n<p>Cloud Run \u06cc\u06a9 \u067e\u0644\u062a \u0641\u0631\u0645 \u06a9\u0627\u0645\u0644\u0627\u064b \u0645\u062f\u06cc\u0631\u06cc\u062a \u0634\u062f\u0647 \u0627\u0633\u062a \u06a9\u0647 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u06a9\u062f \u062e\u0648\u062f \u0631\u0627 \u0645\u0633\u062a\u0642\u06cc\u0645\u0627\u064b \u062f\u0631 \u0628\u0627\u0644\u0627\u06cc \u0632\u06cc\u0631\u0633\u0627\u062e\u062a \u0645\u0642\u06cc\u0627\u0633 \u067e\u0630\u06cc\u0631 Google \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f. Cloud Run \u0633\u0627\u062f\u0647\u060c \u062e\u0648\u062f\u06a9\u0627\u0631 \u0648 \u0628\u0631\u0627\u06cc \u0628\u0647\u0631\u0647 \u0648\u0631\u06cc \u0628\u06cc\u0634\u062a\u0631 \u0634\u0645\u0627 \u0637\u0631\u0627\u062d\u06cc \u0634\u062f\u0647 \u0627\u0633\u062a.<\/p>\n<\/blockquote>\n<ol>\n<li>\u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0628\u0631\u0646\u0627\u0645\u0647 \u0633\u0627\u062f\u0647 hello world \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u06a9\u062a\u0627\u0628\u062e\u0627\u0646\u0647 fastapi (python)<\/li>\n<li>\u0628\u0631\u0646\u0627\u0645\u0647 \u0631\u0627 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u06cc \u06a9\u0646\u06cc\u062f<\/li>\n<li>\u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 \u0631\u0627 \u0628\u0627 GCP \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f<\/li>\n<li>\u0627\u0632 \u0637\u0631\u06cc\u0642 \u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 github\u060c \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0631\u0627 \u0631\u0648\u06cc \u0633\u0631\u0648\u06cc\u0633 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc \u0645\u0633\u062a\u0642\u0631 \u06a9\u0646\u06cc\u062f<\/li>\n<\/ol>\n<p>\u0645\u0646 \u0633\u0646\u062f \u0631\u0633\u0645\u06cc fastapi \u0631\u0627 \u062f\u0646\u0628\u0627\u0644 \u06a9\u0631\u062f\u0645 \u062a\u0627 \u06cc\u06a9 \u0628\u0631\u0646\u0627\u0645\u0647 hello world \u0631\u0627 \u0628\u0686\u0631\u062e\u0627\u0646\u0645<br \/>\u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 <strong><u>\u0627\u0644\u0632\u0627\u0645\u0627\u062a. txt<\/u><\/strong>  \u0641\u0627\u06cc\u0644<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>fastapi[standard]\npydantic&gt;=2.7.0,&lt;3.0.0\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<ul>\n<li>\u06cc\u06a9 \u0641\u0647\u0631\u0633\u062a \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f \u0648 \u0622\u0646 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/li>\n<li>\u06cc\u06a9 \u0641\u0627\u06cc\u0644 \u062e\u0627\u0644\u06cc \u0628\u0633\u0627\u0632\u06cc\u062f <strong>init<\/strong>.py<\/li>\n<li>\u06cc\u06a9 \u0641\u0627\u06cc\u0644 main.py \u0628\u0627:<\/li>\n<\/ul>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>from typing import Union\n\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n\n@app.get(\"https:\/\/dev.to\/\")\ndef read_root():\n    return {\"Hello\": \"World\"}\n\n\n@app.get(\"\/items\/{item_id}\")\ndef read_item(item_id: int, q: Union[str, None] = None):\n    return {\"item_id\": item_id, \"q\": q}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u06cc\u06a9 Dockerfile \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>FROM python:3.9\n\nWORKDIR \/code\n\nCOPY .\/requirements.txt \/code\/requirements.txt\n\nRUN pip install --no-cache-dir --upgrade -r \/code\/requirements.txt\n\nCOPY .\/app \/code\/app\n\nCMD [\"fastapi\", \"run\", \"app\/main.py\", \"--port\", \"80\"]\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0627\u06a9\u0634\u0646 GitHub<\/strong><br \/>\u0628\u0631\u0627\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0641\u0631\u0622\u06cc\u0646\u062f \u0627\u0642\u062f\u0627\u0645\u0627\u062a GitHub \u0628\u062a\u0648\u0627\u0646\u062f \u0641\u0627\u06cc\u0644 YAML \u0631\u0627 \u062f\u0631\u06cc\u0627\u0641\u062a \u06a9\u0646\u062f\u060c \u0645\u06a9\u0627\u0646 \u062e\u0627\u0635\u06cc \u0628\u0631\u0627\u06cc \u0632\u0646\u062f\u06af\u06cc \u0622\u0646 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f. \u0647\u0631 \u0645\u062e\u0632\u0646 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06a9\u0634\u0646 \u0647\u0627 \u0628\u0647 \u06cc\u06a9 \u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc \u0628\u0647 \u0646\u0627\u0645 \/.github\/workflows \u0646\u06cc\u0627\u0632 \u062f\u0627\u0631\u062f<\/p>\n<p>*<em>\u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u0627\u06cc\u0646 \u06af\u0631\u062f\u0634 \u06a9\u0627\u0631 \u0628\u0627 GCP \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u0628\u06cc\u0634\u062a\u0631 *<\/em><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code># This workflow build and push a Docker container to Google Artifact Registry\n# and deploy it on Cloud Run when a commit is pushed to the $default-branch\n# branch.\n#\n# To configure this workflow:\n#\n# 1. Enable the following Google Cloud APIs:\n#\n#    - Artifact Registry (artifactregistry.googleapis.com)\n#    - Cloud Run (run.googleapis.com)\n#    - IAM Credentials API (iamcredentials.googleapis.com)\n#\n#    You can learn more about enabling APIs at\n#    https:\/\/support.google.com\/googleapi\/answer\/6158841.\n#\n# 2. Create and configure a Workload Identity Provider for GitHub:\n#    https:\/\/github.com\/google-github-actions\/auth#preferred-direct-workload-identity-federation.\n#\n#    Depending on how you authenticate, you will need to grant an IAM principal\n#    permissions on Google Cloud:\n#\n#    - Artifact Registry Administrator (roles\/artifactregistry.admin)\n#    - Cloud Run Developer (roles\/run.developer)\n#\n#    You can learn more about setting IAM permissions at\n#    https:\/\/cloud.google.com\/iam\/docs\/manage-access-other-resources\n#\n# 3. Change the values in the \"env\" block to match your values.\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u06cc\u06a9 \u0641\u0627\u06cc\u0644 google-cloudrun-docker.yml \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>name: 'Build and Deploy to Cloud Run'\n\non:\n  push:\n    branches:\n      - '$default-branch'\n\nenv:\n  PROJECT_ID: 'my-project' # TODO: update to your Google Cloud project ID\n  REGION: 'us-central1' # TODO: update to your region\n  SERVICE: 'my-service' # TODO: update to your service name\n  WORKLOAD_IDENTITY_PROVIDER: 'projects\/123456789\/locations\/global\/workloadIdentityPools\/my-pool\/providers\/my-provider' # TODO: update to your workload identity provider\n\njobs:\n  deploy:\n    runs-on: 'ubuntu-latest'\n\n    permissions:\n      contents: 'read'\n      id-token: 'write'\n\n    steps:\n      - name: 'Checkout'\n        uses: 'actions\/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions\/checkout@v4\n\n      # Configure Workload Identity Federation and generate an access token.\n      #\n      # See https:\/\/github.com\/google-github-actions\/auth for more options,\n      # including authenticating via a JSON credentials file.\n      - id: 'auth'\n        name: 'Authenticate to Google Cloud'\n        uses: 'google-github-actions\/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions\/auth@v2\n        with:\n          workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'\n\n      # BEGIN - Docker auth and build\n      #\n      # If you already have a container image, you can omit these steps.\n      - name: 'Docker Auth'\n        uses: 'docker\/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567' # docker\/login-action@v3\n        with:\n          username: 'oauth2accesstoken'\n          password: '${{ steps.auth.outputs.auth_token }}'\n          registry: '${{ env.REGION }}-docker.pkg.dev'\n\n      - name: 'Build and Push Container'\n        run: |-\n          DOCKER_TAG=\"$${{ env.REGION }}-docker.pkg.dev\/${{ env.PROJECT_ID }}\/${{ env.SERVICE }}:${{ github.sha }}\"\n          docker build --tag \"${DOCKER_TAG}\" .\n          docker push \"${DOCKER_TAG}\"\n      - name: 'Deploy to Cloud Run'\n\n        # END - Docker auth and build\n\n        uses: 'google-github-actions\/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions\/deploy-cloudrun@v2\n        with:\n          service: '${{ env.SERVICE }}'\n          region: '${{ env.REGION }}'\n          # NOTE: If using a pre-built image, update the image name below:\n\n          image: '${{ env.REGION }}-docker.pkg.dev\/${{ env.PROJECT_ID }}\/${{ env.SERVICE }}:${{ github.sha }}'\n      # If required, use the Cloud Run URL output in later steps\n      - name: 'Show output'\n        run: |2-\n\n          echo ${{ steps.deploy.outputs.url }}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc<\/strong><\/p>\n<blockquote>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u0628\u0627\u06cc\u062f \u06cc\u06a9 \u0633\u0627\u062e\u062a\u0627\u0631 \u062f\u0627\u06cc\u0631\u06a9\u062a\u0648\u0631\u06cc \u0645\u0627\u0646\u0646\u062f:<\/p>\n<\/blockquote>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>\u251c\u2500\u2500 app\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 main.py\n\u251c\u2500\u2500 Dockerfile\n\u2514\u2500\u2500 requirements.txt\n\u2514\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 .github\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 workflows\n         \u251c\u2500\u2500 google-cloudrun-docker.yml\n\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>\n&gt; 1. Create a new repo in gitHUb\n&gt; 2. Push your exisisting code to new repository on default branch\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summarize this content to 400 words in Persian Lang \u0645\u0646 \u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0642\u0631\u0627\u0631 \u06cc\u06a9 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631 \u0633\u0627\u062f\u0647 \u0631\u0627 \u062f\u0631 \u0627\u062c\u0631\u0627\u06cc \u0627\u0628\u0631\u06cc \u0646\u0634\u0627\u0646 \u062e\u0648\u0627\u0647\u0645 \u062f\u0627\u062f. Cloud Run \u06cc\u06a9 \u067e\u0644\u062a \u0641\u0631\u0645 \u06a9\u0627\u0645\u0644\u0627\u064b \u0645\u062f\u06cc\u0631\u06cc\u062a \u0634\u062f\u0647 \u0627\u0633\u062a \u06a9\u0647 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u06a9\u062f \u062e\u0648\u062f \u0631\u0627 \u0645\u0633\u062a\u0642\u06cc\u0645\u0627\u064b \u062f\u0631 \u0628\u0627\u0644\u0627\u06cc \u0632\u06cc\u0631\u0633\u0627\u062e\u062a \u0645\u0642\u06cc\u0627\u0633 \u067e\u0630\u06cc\u0631 Google \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f. Cloud Run \u0633\u0627\u062f\u0647\u060c \u062e\u0648\u062f\u06a9\u0627\u0631 \u0648 \u0628\u0631\u0627\u06cc &hellip;<\/p>\n","protected":false},"author":2,"featured_media":79446,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-79445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/79445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=79445"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/79445\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/79446"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=79445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=79445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=79445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}