[Python] How to authenticate a Python package between two repos in GitHub and deploy

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    We have a private utility repo in GitHub and we would like to be able to install this package with a GitHub Actions. When developing locally I have created a ssh key, uploaded the public key to deploy keys in GitHub, and everything works fine locally.

    requirements.txt:

    annotated-types==0.7.0
    anyio==4.7.0
    certifi==2024.8.30
    cffi==1.17.1
    click==8.1.7
    colorama==0.4.6
    cryptography==44.0.0
    fastapi==0.115.6
    fastapi-azure-auth==5.0.1
    h11==0.14.0
    httpcore==1.0.7
    httpx==0.28.1
    idna==3.10
    pycparser==2.22
    pydantic==2.10.3
    pydantic-settings==2.6.1
    pydantic_core==2.27.1
    PyJWT==2.10.1
    python-dotenv==1.0.1
    sniffio==1.3.1
    starlette==0.41.3
    typing_extensions==4.12.2
    uvicorn==0.32.1
    azure-monitor-opentelemetry
    databricks
    databricks.sdk
    databricks-sql-connector
    pyarrow
    pandas
    sqlalchemy
    numpy
    azure-identity
    opencensus-ext-azure
    opentelemetry-api
    opentelemetry-sdk
    opentelemetry-instrumentation-fastapi

    git+ssh://github.com/xxx-dna/dna-utils.git@main


    When doing a pip install locally it installs the package because of the ssh setup locally. How do we deploy this? Is it possible somehow to authenticate the two repos to each other? When running the action in GitHub it fails, because the repo is private. Can you configure it somehow to be authenticated, or do you need to add some ssh in the pipeline?

    name: Build and deploy Python app to Azure Web App - xx-xx-port-api-dev

    on:
    push:
    branches:
    - dev
    workflow_dispatch:

    jobs:
    build:
    runs-on: ubuntu-latest
    permissions:
    contents: read

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python version
    uses: actions/setup-python@v5
    with:
    python-version: '3.12'

    - name: Install dependencies
    run: |
    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt

    - name: Zip artifact for deployment
    run: |
    zip -r release.zip . -x "venv/*"

    - name: Upload artifact for deployment jobs
    uses: actions/upload-artifact@v4
    with:
    name: python-app
    path: release.zip

    deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
    name: 'Production'
    url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
    id-token: write
    contents: read

    steps:
    - name: Download artifact from build job
    uses: actions/download-artifact@v4
    with:
    name: python-app

    - name: Unzip artifact for deployment
    run: unzip release.zip

    - name: Login to Azure
    uses: azure/login@v2
    with:
    client-id: ${{ secrets.AZURE_CLIENT_ID }}
    tenant-id: ${{ secrets.AZURE_TENANT_ID }}
    subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

    - name: Deploy to Azure Web App
    uses: azure/webapps-deploy@v3
    id: deploy-to-webapp
    with:
    app-name: 'xx-xx-port-api-dev'
    slot-name: 'Production'
    package: .

    Continue reading...

Compartilhe esta Página