<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jayanth MKV</title>
    <description>The latest articles on Forem by Jayanth MKV (@jayanth-mkv).</description>
    <link>https://forem.com/jayanth-mkv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2455287%2F22e1cb52-d012-481f-9496-1d037d7ca31f.jpg</url>
      <title>Forem: Jayanth MKV</title>
      <link>https://forem.com/jayanth-mkv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jayanth-mkv"/>
    <language>en</language>
    <item>
      <title>The Dark Side of VLMs: What's Really Going Wrong</title>
      <dc:creator>Jayanth MKV</dc:creator>
      <pubDate>Thu, 28 Nov 2024 06:28:58 +0000</pubDate>
      <link>https://forem.com/jayanth-mkv/the-dark-side-of-vlms-whats-really-going-wrong-4im3</link>
      <guid>https://forem.com/jayanth-mkv/the-dark-side-of-vlms-whats-really-going-wrong-4im3</guid>
      <description>&lt;p&gt;Your high-stakes decisions might be based on flawed logic. Here's the scoop:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Systemic Reasoning: The Weak Link&lt;/strong&gt;&lt;br&gt;
Vision-Language Models (VLMs) are notorious for skipping over systematic thought processes, arriving at answers too quickly and with catastrophic results. Think 9 out of 10 times wrong. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The LLaVA-o1 Revolution&lt;/strong&gt;&lt;br&gt;
Meet LLaVA-o1, a VLM game-changer. By reason step-by-step, it avoids premature conclusions and verified results:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stage-level beam search&lt;/li&gt;
&lt;li&gt;Inference-time scaling&lt;/li&gt;
&lt;li&gt;Iterative reasoning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What makes OpenAI's o1 model so unique?&lt;/strong&gt;&lt;br&gt;
It breaks down complex problems into bite-sized pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logical thinking at its finest&lt;/li&gt;
&lt;li&gt;Using multiple attempts to reach the correct solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Four Game-Changing Stages of Reasoning&lt;/strong&gt;&lt;br&gt;
LLaVA-o1's secret sauce: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Problem Analysis&lt;/li&gt;
&lt;li&gt;Hypothesis Generation&lt;/li&gt;
&lt;li&gt;Hypothesis Verification&lt;/li&gt;
&lt;li&gt;Confidence Assessment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Will VLMs ever be trusted for critical decision-making? It's time to rethink our reliance on these models.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>llm</category>
    </item>
    <item>
      <title>Pushing Python Packages to Artifact Registry Using Cloud Build</title>
      <dc:creator>Jayanth MKV</dc:creator>
      <pubDate>Fri, 22 Nov 2024 11:15:53 +0000</pubDate>
      <link>https://forem.com/jayanth-mkv/pushing-python-packages-to-artifact-registry-using-cloud-build-2pg</link>
      <guid>https://forem.com/jayanth-mkv/pushing-python-packages-to-artifact-registry-using-cloud-build-2pg</guid>
      <description>&lt;p&gt;Google Artifact Registry is a powerful solution for managing and hosting Python package artifacts in a private, secure, and scalable way. This guide provides a step-by-step walkthrough to push Python package &lt;code&gt;.whl&lt;/code&gt; files to the Artifact Registry using &lt;strong&gt;Google Cloud Build&lt;/strong&gt; and a secret (&lt;code&gt;creds&lt;/code&gt;) from &lt;strong&gt;Google Secret Manager&lt;/strong&gt; for authentication.&lt;/p&gt;




&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Artifact Registry Setup&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Python repository in your Artifact Registry:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; gcloud artifacts repositories create python-packages &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--repository-format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;python &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Python packages repository"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Secret Setup&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store your key as a secret in Google Secret Manager:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; gcloud secrets create creds &lt;span class="nt"&gt;--data-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;path/to/key.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Grant Cloud Build access to the secret:(Optional, can also be done using IAM)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; gcloud secrets add-iam-policy-binding creds &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;gcloud projects describe &lt;span class="nv"&gt;$PROJECT_ID&lt;/span&gt; &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'value(projectNumber)'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;@cloudbuild.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/secretmanager.secretAccessor"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Build Permissions&lt;/strong&gt;:
Ensure your Cloud Build service account has the necessary permissions to access the Artifact Registry and Secret Manager.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Cloud Build YAML Configuration
&lt;/h3&gt;

&lt;p&gt;Here's the full working &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;machineType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;E2_HIGHCPU_8&lt;/span&gt;
  &lt;span class="na"&gt;substitutionOption&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ALLOW_LOOSE&lt;/span&gt;
  &lt;span class="na"&gt;logging&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CLOUD_LOGGING_ONLY&lt;/span&gt;

&lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Step 1: Access the secret `creds` and save it as `key.json`&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gcr.io/google.com/cloudsdktool/cloud-sdk'&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;gcloud secrets versions access latest --secret=creds &amp;gt; /workspace/key.json&lt;/span&gt;

  &lt;span class="c1"&gt;# Step 2: Configure `.pypirc` with the Artifact Registry credentials&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;python'&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;cat &amp;gt; ~/.pypirc &amp;lt;&amp;lt; EOL&lt;/span&gt;
        &lt;span class="s"&gt;[distutils]&lt;/span&gt;
        &lt;span class="s"&gt;index-servers = tower-common-repo&lt;/span&gt;

        &lt;span class="s"&gt;[tower-common-repo]&lt;/span&gt;
        &lt;span class="s"&gt;repository: https://us-central1-python.pkg.dev/$PROJECT_ID/python-packages/&lt;/span&gt;
        &lt;span class="s"&gt;username: _json_key_base64&lt;/span&gt;
        &lt;span class="s"&gt;password: $(base64 -w0 /workspace/key.json)&lt;/span&gt;
        &lt;span class="s"&gt;EOL&lt;/span&gt;

        &lt;span class="s"&gt;# Step 3: Build and upload the Python package&lt;/span&gt;
        &lt;span class="s"&gt;pip install twine build &amp;amp;&amp;amp; \&lt;/span&gt;
        &lt;span class="s"&gt;python -m build &amp;amp;&amp;amp; \&lt;/span&gt;
        &lt;span class="s"&gt;twine upload --repository tower-common-repo dist/* --verbose&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step-by-Step Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Define Build Options&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set the machine type, substitution behavior, and logging options.&lt;/li&gt;
&lt;li&gt;These configurations ensure efficient builds and manageable logs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Retrieve &lt;code&gt;key.json&lt;/code&gt; Secret&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;gcloud secrets versions access&lt;/code&gt; to fetch the &lt;code&gt;key.json&lt;/code&gt; file securely from Secret Manager.&lt;/li&gt;
&lt;li&gt;Save the file to a known location (&lt;code&gt;/workspace/key.json&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure &lt;code&gt;.pypirc&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate a &lt;code&gt;.pypirc&lt;/code&gt; file dynamically. This file is required for &lt;code&gt;twine&lt;/code&gt; to authenticate with the Artifact Registry.&lt;/li&gt;
&lt;li&gt;The password is base64-encoded content of &lt;code&gt;key.json&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Build and Push Package&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install necessary tools (&lt;code&gt;twine&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Build the Python package (&lt;code&gt;python -m build&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;twine upload&lt;/code&gt; to push the &lt;code&gt;.whl&lt;/code&gt; file to the Artifact Registry.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Triggering the Build
&lt;/h3&gt;

&lt;p&gt;Save the &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file and trigger the build or can connect to github repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud builds submit &lt;span class="nt"&gt;--config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;cloudbuild.yaml &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Key Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Secure Secrets Management&lt;/strong&gt;: The secret (&lt;code&gt;key.json&lt;/code&gt;) is accessed securely using Google Secret Manager.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Configuration&lt;/strong&gt;: &lt;code&gt;.pypirc&lt;/code&gt; is generated during the build, ensuring no sensitive data is stored in the repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Upload&lt;/strong&gt;: The process automates package building and pushing, reducing manual intervention.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Validation
&lt;/h3&gt;

&lt;p&gt;After the build completes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify the uploaded package in the Artifact Registry:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud artifacts packages list &lt;span class="nt"&gt;--repository&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;python-packages &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Check for errors or warnings in the build logs.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>python</category>
      <category>gcp</category>
      <category>cloudbuild</category>
      <category>docker</category>
    </item>
    <item>
      <title>How to Create a Cloud Build to Allow Docker to Download Python Packages from Artifact Registry</title>
      <dc:creator>Jayanth MKV</dc:creator>
      <pubDate>Fri, 22 Nov 2024 09:12:10 +0000</pubDate>
      <link>https://forem.com/jayanth-mkv/how-to-create-a-cloud-build-to-allow-docker-to-download-python-packages-from-artifact-registry-547f</link>
      <guid>https://forem.com/jayanth-mkv/how-to-create-a-cloud-build-to-allow-docker-to-download-python-packages-from-artifact-registry-547f</guid>
      <description>&lt;p&gt;Google Cloud's Artifact Registry is a powerful tool for managing your application's dependencies. This guide demonstrates how to create a Cloud Build pipeline to enable Docker to access Python packages stored in Artifact Registry. By following these steps, you can securely manage dependencies and streamline deployments.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Google Cloud Project&lt;/strong&gt;: Ensure you have a GCP project set up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Artifact Registry&lt;/strong&gt;: A Python repository should already be configured in the Artifact Registry.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Build&lt;/strong&gt;: Enable the Cloud Build API for your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Configure service account permissions to access the Artifact Registry.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Steps to Configure Cloud Build
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Generate an Artifact Registry Token
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;gcloud auth&lt;/code&gt; to generate an access token that will allow the Docker build process to authenticate with the Artifact Registry. Here's how you can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Generate Artifact Registry token&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gcr.io/google.com/cloudsdktool/cloud-sdk'&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;art=$(gcloud auth print-access-token)&lt;/span&gt;
        &lt;span class="s"&gt;echo "$art" &amp;gt; /workspace/artifact_registry_token&lt;/span&gt;
        &lt;span class="s"&gt;echo "$art"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Use the Token in Docker Build
&lt;/h3&gt;

&lt;p&gt;Once the token is generated, it can be passed to the &lt;code&gt;docker build&lt;/code&gt; process as a build argument. Here's how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/cloud-builders/docker&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;btf=/workspace/artifact_registry_token'&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;docker build \&lt;/span&gt;
          &lt;span class="s"&gt;--build-arg ARTIFACT_REGISTRY_TOKEN=$(cat $btf) \&lt;/span&gt;
          &lt;span class="s"&gt;--build-arg PROJECT_ID=$PROJECT_ID \&lt;/span&gt;
          &lt;span class="s"&gt;-t test-image:latest \&lt;/span&gt;
          &lt;span class="s"&gt;-f Dockerfile .&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Create the Dockerfile
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Dockerfile&lt;/code&gt; is configured to use the token to download Python packages from Artifact Registry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# syntax=docker/dockerfile:1&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.11-slim&lt;/span&gt;

&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; ARTIFACT_REGISTRY_TOKEN&lt;/span&gt;
&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; PROJECT_ID&lt;/span&gt;

&lt;span class="c"&gt;# Keeps Python from buffering stdout and stderr&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PYTHONUNBUFFERED=1&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies using the token&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="nt"&gt;--index-url&lt;/span&gt; https://pypi.org/simple &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="nt"&gt;--extra-index-url&lt;/span&gt; https://oauth2accesstoken:&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ARTIFACT_REGISTRY_TOKEN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;@us-central1-python.pkg.dev/&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/python-packages/simple/ &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="s2"&gt;"your-package-name==your-package-version"&lt;/span&gt;

&lt;span class="c"&gt;# Expose the application port&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8080&lt;/span&gt;

&lt;span class="c"&gt;# Command to run the application&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["uvicorn", "main:app", "--port=8080", "--host=0.0.0.0"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Add Build Config Options
&lt;/h3&gt;

&lt;p&gt;Finally, define other configurations such as machine type, logging, and substitutions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;machineType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;E2_HIGHCPU_8&lt;/span&gt;
  &lt;span class="na"&gt;substitutionOption&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ALLOW_LOOSE&lt;/span&gt;
  &lt;span class="na"&gt;logging&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CLOUD_LOGGING_ONLY&lt;/span&gt;
&lt;span class="na"&gt;substitutions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;_PACKAGE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;your-package-name==your-package-version&lt;/span&gt;
  &lt;span class="na"&gt;_REPOSITORY&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python-packages&lt;/span&gt;
  &lt;span class="na"&gt;_LOCATION&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;us-central1&lt;/span&gt;
  &lt;span class="na"&gt;_PROJECT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;your-project-id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Tags and Metadata
&lt;/h2&gt;

&lt;p&gt;To organize your builds better, include meaningful tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;gcp-cloud-build&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;artifact-registry&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;docker-python-packages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;This setup ensures that your Docker builds in Cloud Build can securely pull Python dependencies from your Artifact Registry using an access token. Adjust the provided configuration to your project-specific details, such as package names, repository URLs, and deployment targets. &lt;/p&gt;

&lt;p&gt;Implementing this pipeline will improve security and make dependency management seamless for your projects.&lt;/p&gt;

</description>
      <category>gcp</category>
      <category>python</category>
      <category>cloudbuild</category>
      <category>docker</category>
    </item>
    <item>
      <title>GCP publish python package in production</title>
      <dc:creator>Jayanth MKV</dc:creator>
      <pubDate>Tue, 19 Nov 2024 15:31:20 +0000</pubDate>
      <link>https://forem.com/jayanth-mkv/gcp-publish-python-package-in-production-59ea</link>
      <guid>https://forem.com/jayanth-mkv/gcp-publish-python-package-in-production-59ea</guid>
      <description>&lt;h2&gt;
  
  
  GCP: Publish Python Package in Production
&lt;/h2&gt;

&lt;p&gt;This guide explains how to use &lt;strong&gt;Google Artifact Registry&lt;/strong&gt; to manage shared Python code as a package. This approach eliminates code duplication between your Cloud Functions and server.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Structure Your Shared Code
&lt;/h2&gt;

&lt;p&gt;Create a new Python package for your shared logic (e.g., &lt;code&gt;common_logic&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;common_logic/
├── setup.py
├── common_logic/
│   ├── __init__.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Create &lt;code&gt;setup.py&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Define your package configuration in a &lt;code&gt;setup.py&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;setuptools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;find_packages&lt;/span&gt;

&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;common_logic&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.1.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;find_packages&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;install_requires&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pandas&amp;gt;=1.3.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your Name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;author_email&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your.email@example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Common logic for app&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Set Up Google Artifact Registry
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Enable the Artifact Registry API:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud services &lt;span class="nb"&gt;enable &lt;/span&gt;artifactregistry.googleapis.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a Python repository:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud artifacts repositories create python-packages &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--repository-format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;python &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Python packages repository"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 4: Configure Authentication
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a service account:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud iam service-accounts create artifact-publisher &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Service account for publishing to Artifact Registry"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Grant necessary permissions:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud artifacts repositories add-iam-policy-binding python-packages &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:artifact-publisher@&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/artifactregistry.writer"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create and download a key:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   gcloud iam service-accounts keys create key.json &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--iam-account&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;artifact-publisher@&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5: Build and Upload Package
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install build tools:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   pip &lt;span class="nb"&gt;install &lt;/span&gt;build twine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Build the package:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   python &lt;span class="nt"&gt;-m&lt;/span&gt; build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Configure &lt;code&gt;twine&lt;/code&gt; for Artifact Registry:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.pypirc &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOL&lt;/span&gt;&lt;span class="sh"&gt;
   [distutils]
   index-servers = common-logic-repo
   [common-logic-repo]
   repository: https://us-central1-python.pkg.dev/&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;/python-packages/
   username: _json_key_base64
   password: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;-w0&lt;/span&gt; key.json&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;
&lt;/span&gt;&lt;span class="no"&gt;   EOL
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Upload the package:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   twine upload &lt;span class="nt"&gt;--repository&lt;/span&gt; common-logic-repo dist/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 6: Use the Package
&lt;/h2&gt;

&lt;h3&gt;
  
  
  In Cloud Functions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;requirements.txt&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   --index-url https://pypi.org/simple
   --extra-index-url https://oauth2accesstoken:${ARTIFACT_REGISTRY_TOKEN}@us-central1-python.pkg.dev/${PROJECT_ID}/python-packages/simple/
   common-logic==0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use the package in your Cloud Function:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;common_logic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="bp"&gt;...&lt;/span&gt;

   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cloud_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
       &lt;span class="c1"&gt;# Your cloud function code using the imported functions
&lt;/span&gt;       &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  In Server Code
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Add to your server's &lt;code&gt;requirements.txt&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   --index-url https://pypi.org/simple
   --extra-index-url https://oauth2accesstoken:${ARTIFACT_REGISTRY_TOKEN}@us-central1-python.pkg.dev/${PROJECT_ID}/python-packages/simple/
   common-logic==0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use it in your server code:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;common_logic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="bp"&gt;...&lt;/span&gt;
   &lt;span class="c1"&gt;# Your server code using the imported functions
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 7: CI/CD Integration
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Add the service account key as a secret in your GitHub repository.&lt;/li&gt;
&lt;li&gt;Update your Cloud Build configuration:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;   &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;python'&lt;/span&gt;
       &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pip&lt;/span&gt;
       &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;install'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;build'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;twine'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;python'&lt;/span&gt;
       &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python&lt;/span&gt;
       &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-m'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;build'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
       &lt;span class="na"&gt;dir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;common_logic'&lt;/span&gt;

     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;python'&lt;/span&gt;
       &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;twine&lt;/span&gt;
       &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;upload'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;--repository'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;common-logic-repo'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dist/*'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
       &lt;span class="na"&gt;dir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;common_logic'&lt;/span&gt;
       &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
         &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;TWINE_USERNAME=_json_key_base64'&lt;/span&gt;
         &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;TWINE_PASSWORD=${_ARTIFACT_REGISTRY_KEY}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 8: Version Management
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Update the version in &lt;code&gt;setup.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Build and upload the new version.&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;requirements.txt&lt;/code&gt; in both Cloud Functions and server code.&lt;/li&gt;
&lt;li&gt;Deploy both components.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;semantic versioning&lt;/strong&gt; for your package.&lt;/li&gt;
&lt;li&gt;Pin specific versions in &lt;code&gt;requirements.txt&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Test new versions thoroughly before deploying.&lt;/li&gt;
&lt;li&gt;Keep a changelog of version changes.&lt;/li&gt;
&lt;li&gt;Use environment variables for &lt;code&gt;PROJECT_ID&lt;/code&gt; and &lt;code&gt;LOCATION&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Include comprehensive documentation in your package.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Issues and Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Authentication Errors
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Verify service account permissions.&lt;/li&gt;
&lt;li&gt;Ensure &lt;code&gt;key.json&lt;/code&gt; is properly encoded.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;.pypirc&lt;/code&gt; configuration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Package Not Found
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Verify repository URL format.&lt;/li&gt;
&lt;li&gt;Check if the package was successfully uploaded.&lt;/li&gt;
&lt;li&gt;Ensure &lt;code&gt;requirements.txt&lt;/code&gt; uses the correct URL format.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Version Conflicts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Pin specific versions of dependencies.&lt;/li&gt;
&lt;li&gt;Use virtual environments for testing.&lt;/li&gt;
&lt;li&gt;Document dependency requirements clearly.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>gcp</category>
      <category>python</category>
      <category>pythonpackage</category>
    </item>
  </channel>
</rss>
