temporalio / sdk-python

Temporal Python SDK
MIT License
452 stars 66 forks source link

[Bug] Unable to install temporalio within [image: sonarsource/sonar-scanner-cli:4.6] container #309

Closed kaustav1996 closed 1 year ago

kaustav1996 commented 1 year ago

What are you really trying to do?

While running CI in our GitLab CI Pipeline we are unable to install temporalio because it is unable to find protoc-wheel-0

Describe the bug

Here is our Job :

merge-request-static-analyzer:
  image: sonarsource/sonar-scanner-cli:4.6
  stage: sonar_analysis
  before_script:
    - echo "Source -> ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} Target -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} MR -> ${CI_MERGE_REQUEST_IID}"
  script:
    - ls -lah
    - apk add --update --no-cache python3 postgresql-libs postgresql-dev gcc python3-dev musl-dev groff alpine-sdk bash jq curl libffi-dev openssl-dev util-linux go postgresql-client curl-dev python3-dev libressl-dev
    - python3 -m ensurepip
    - pip3 install --ignore-installed --no-cache --upgrade pip setuptools virtualenv bump2version==1.0.1
    - rm -rf venv && virtualenv venv
    - source venv/bin/activate
    - pip3 install --find-links=protoc_wheel_0-21.10-py2.py3-none-any.whl protoc-wheel-0
    - pip3 freeze
    - pip3 install -r requirements.txt
    - source ./test/environments/.prod.env
    - make test.coverage
    - coverage xml --fail-under 95
    - sonar-scanner
      -Dsonar.projectKey=zion
      -Dsonar.sources=.
      -Dsonar.qualitygate.wait=true
      -Dsonar.exclusions="./deployment/**, ./test/**, ./venv/**"
      -Dsonar.login=${SONAR_LOGIN}
      -Dsonar.host.url=${SONAR_HOST}
      -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID}
      -Dsonar.pullrequest.branch=${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}
      -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
    - echo "Done"
  artifacts:
    when: always
    reports:
      junit: coverage.xml
  only:
    - merge_requests

Since we were first unable to install protoc-wheel-0 on this architecture we built the whl file and exported it using a separate docker :

FROM alpine:3.17
RUN apk update
RUN apk add --no-cache --virtual build-dependencies wget unzip gnupg libffi-dev gcc libc-dev linux-headers
RUN apk add --no-cache git python3-dev py-pip bash shellcheck 'nodejs>12' openjdk11-jre curl musl-locales musl-locales-lang;
RUN git clone https://gitlab.com/dfritzsche/create-protoc-wheel.git  protoc
WORKDIR /protoc
RUN pip install -r requirements.txt
RUN python create_protoc_wheel.py 21.10

I am then going inside the container building the wheel and exporting it. Hence the line is there in the CI job to install it within the sonar container :

- pip3 install --find-links=protoc_wheel_0-21.10-py2.py3-none-any.whl protoc-wheel-0

Output when the Job runs :

$ source venv/bin/activate
$ pip3 install --find-links=protoc_wheel_0-21.10-py2.py3-none-any.whl protoc-wheel-0
Looking in links: protoc_wheel_0-21.10-py2.py3-none-any.whl
Processing ./protoc_wheel_0-21.10-py2.py3-none-any.whl
Installing collected packages: protoc-wheel-0
Successfully installed protoc-wheel-0-21.10
$ pip3 freeze
protoc-wheel-0==21.10
$ pip3 install -r requirements.txt
.
.
.
Collecting temporalio==1.1.0
  Downloading temporalio-1.1.0.tar.gz (851 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 851.4/851.4 kB 41.5 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [11 lines of output]
      Collecting poetry-core>=1.0.0
        Downloading poetry_core-1.5.2-py3-none-any.whl (465 kB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 465.2/465.2 kB 8.1 MB/s eta 0:00:00
      Collecting setuptools
        Using cached setuptools-67.6.1-py3-none-any.whl (1.1 MB)
      Collecting wheel
        Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
      Collecting setuptools-rust
        Downloading setuptools_rust-1.5.2-py3-none-any.whl (23 kB)
      ERROR: Could not find a version that satisfies the requirement protoc-wheel-0 (from versions: none)
      ERROR: No matching distribution found for protoc-wheel-0
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.

What I cannot understand is why it is not able to detect the already installed protoc-wheel-0 even though it is mentioned in pyproject.toml that ^21.1 is required. :

[tool.poetry.dev-dependencies]
protoc-wheel-0 = "^21.1"

Environment/Versions

kaustav1996 commented 1 year ago

I just saw in the last line of pyproject.toml it says :

requires = ["poetry-core>=1.0.0", "setuptools", "wheel", "setuptools-rust", "protoc-wheel-0"]

does it mean it will always try to download it and not use the one that is installed in the env?

cretz commented 1 year ago

What is happening is pip is trying to install temporalio from source instead of using a prebuilt one because you are using Alpine. This uses musl instead of glibc which we don't provide pre-built package for. Then, when it tries to build it is installing dev dependencies which includes protoc-wheel-0 which also does not seem to provide a musl-based package for Alpine.

We have a couple of options here. You can stop using Alpine. If this is not an option, maybe we can make protoc-wheel-0 an optional dev dependency. But you'll have to make protoc available on the PATH somehow because this will need to build via Rust and one of our crates requires protoc. Also the build will take a while. It is suggested to just use a different distro (just about any non-alpine should work) so that you don't have to build the SDK.

kaustav1996 commented 1 year ago

@cretz Thanks for the response. We found a way to use an alternate Distro and were able to install temporalio there.

tynianovddi commented 1 year ago

What should I do if i can not use any other distro apart from alpine?

cretz commented 1 year ago

You can attempt to build the SDK yourself with MUSL for the Rust part and it will likely work fine. We just don't distribute one. You'll have to use an alternative protoc approach, but that should also not be hard (we only depend on it as a dev dependency so devs don't have to manually download when building).

tynianovddi commented 1 year ago

@cretz thanks, are there any guides how to do that or some mentions how to address this issue?

cretz commented 1 year ago

At the bottom of the README is the build guide. You'll have to research and adapt it for MUSL and to disable protoc Python dependency (to use your own on the PATH) as this is a setup we don't support by default.