[Python] Is it possible to install the Google Cloud CLI on alpine Linux Without it installing...

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    Problem Background


    I am building an Alpine Linux docker image to use as a (relatively) lightweight CI image. In this image, I need to have the Google Cloud gcloud CLI installed.

    I am installing Python from my Dockerfile like this:

    RUN apk add python3


    On Alpine Linux 3.20, (on 2024/12/03,) this installs Python 3.12.7. Installing some version of python appears to be a pre-requisite for even running the Google Cloud CLI install script.

    / # cat /etc/alpine-release
    3.20.0
    / # python --version
    Python 3.12.7


    Google Cloud CLI claims to be compatible with Python 3.8 to 3.13 - source, under the "Linux" tab.

    I am installing the Google Cloud CLI using a script like this, run from inside my container being built:

    mkdir -p /usr/local/gcloud
    curl -s https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz | tar -xz -C /usr/local/gcloud
    /usr/local/gcloud/google-cloud-sdk/install.sh --quiet --usage-reporting false


    When I run this script as part of my Docker image build, I see this:

    #17 8.452 Your current Google Cloud CLI version is: 502.0.0
    #17 8.452 Installing components from version: 502.0.0
    #17 8.452
    #17 8.495 ┌─────────────────────────────────────────────────────────────────────────────┐
    #17 8.495 │ These components will be installed. │
    #17 8.496 ├─────────────────────────────────────────────────────┬────────────┬──────────┤
    #17 8.496 │ Name │ Version │ Size │
    #17 8.497 ├─────────────────────────────────────────────────────┼────────────┼──────────┤
    #17 8.497 │ BigQuery Command Line Tool │ 2.1.9 │ 1.7 MiB │
    #17 8.499 │ BigQuery Command Line Tool (Platform Specific) │ 2.1.8 │ < 1 MiB │
    #17 8.501 │ Bundled Python 3.11 (Platform Specific) │ 3.11.9 │ 74.4 MiB │
    #17 8.503 │ Cloud Storage Command Line Tool │ 5.31 │ 11.3 MiB │
    #17 8.504 │ Cloud Storage Command Line Tool (Platform Specific) │ 5.30 │ < 1 MiB │
    #17 8.506 │ Google Cloud CLI Core Libraries (Platform Specific) │ 2024.08.30 │ < 1 MiB │
    #17 8.507 │ Google Cloud CRC32C Hash Tool (Platform Specific) │ 1.0.0 │ 1.3 MiB │
    #17 8.509 │ gcloud cli dependencies (Platform Specific) │ 2021.04.16 │ < 1 MiB │
    #17 8.510 └─────────────────────────────────────────────────────┴────────────┴──────────┘


    The line that caught my eye is the ~75MiB "Bundled Python 3.11" line. I would like to prevent the installer script from downloading and using a Bundled version of Python. Is this possible?

    Things I've Tried

    --install-python false Flag


    When I run the --help on the script to see options, one catches my eye:

    /usr/local/gcloud/google-cloud-sdk/install.sh --help

    # ....
    --install-python INSTALL_PYTHON
    (true/false) Attempt to install Python. MacOS only.


    Sure enough, this flag appears to not do anything on Alpine Linux (I still see the install script downloading and installing Python 3.11).

    Setting CLOUDSDK_PYTHON environment variable


    After some Googling around, I attempted to set the CLOUDSDK_PYTHON environment variable in my Dockerfile in two ways:

    ENV CLOUDSDK_PYTHON="/usr/bin/python"
    ENV CLOUDSDK_PYTHON="/usr/bin/python3"


    Neither worked (I still see the install script downloading and installing Python 3.11).

    Not a solution for me: Google Provided Docker Container


    I understand that Google provides a base image that already has the gcloud CLI installed. For reasons that aren't fully relevant to the main thrust of this question, I can't use that to elide this problem. I have to use a different Alpine Linux based base image.

    Continue reading...

Compartilhe esta Página