conan-io / conan-package-tools

Conan Package Tools. Helps with massive package creation and CI integration (Travis CI, Appveyor...)
MIT License
166 stars 71 forks source link

CPT error when updating conan #588

Open katetsu opened 2 years ago

katetsu commented 2 years ago

Description of Problem, Request, or Question

Environment Details

Steps to reproduce (Include if Applicable)

I used to be able to build my binaries for some specific in house platforms with travis CI - all linux(Centos and RHEL) but i tried adding a package recently and im getting the below error:

ret["CONAN_USERNAME"] = escape_env(self._reference.user or ret.get("CONAN_USERNAME"))
AttributeError: 'NoneType' object has no attribute 'user'

any ideas?

Build logs (Include if Available)

 >> Build: 1/1
Traceback (most recent call last):
  File "/home/travis/build/software/conan-boost/.travis/build.py", line 11, in <module>
    builder.run()
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/packager.py", line 591, in run
    self.run_builds(base_profile_name=base_profile_name,
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/packager.py", line 744, in run_builds
    r.run(pull_image=not pulled_docker_images[docker_image],
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/runner.py", line 283, in run
    envs = self.get_env_vars()
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/runner.py", line 372, in get_env_vars
    ret["CONAN_USERNAME"] = escape_env(self._reference.user or ret.get("CONAN_USERNAME"))
AttributeError: 'NoneType' object has no attribute 'user'
The command "./.travis/run.sh" exited with 1.
uilianries commented 2 years ago

@katetsu Thank you for reporting and giving details. I'll investigate.

katetsu commented 2 years ago

Thanks. any chance there could be a tested conan/cpt combination that i could use for now?

uilianries commented 2 years ago

@katetsu Downgrade to CPT 0.36.0 for now. I need to recreate your scenario in a test, then provide a hotfix.

uilianries commented 2 years ago

@katetsu How looks like your build.py, also, which env vars are you using? Are you running it on Docker container?

katetsu commented 2 years ago

@uilianries i am seeing a strange situation where some of my other packages do go through and some dont. they used to all go through. their build.py and travis config are more or less identical.

my build.py is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from cpt.packager import ConanMultiPackager
import os
import platform

if __name__ == "__main__":
    build_type = os.environ.get("CONAN_BUILD_TYPES")
    builder = ConanMultiPackager(build_policy=["boost"])
    builder.add({"build_type": build_type})
    builder.run()

and my travis:


env:
   global:
     - CONAN_USERNAME=gen
     - CONAN_PASSWORD=$ARTIFACTORY_PASSWORD
     - CONAN_LOGIN_USERNAME=$ARTIFACTORY_USERNAME
     - CONAN_CHANNEL=stable
     - REGISTRY=$REGISTRY
     - IMAGE_PREFIX=$REGISTRY/foo
os: linux
dist: focal
arch: amd64
language: python
python: "3.9"
services:
  - docker
jobs:
  include:
   - env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=$IMAGE_PREFIX/centos-gcc8 CONAN_ARCHS=x86_64 CONAN_BUILD_TYPES=Debug
install:
  - ./.travis/install.sh
script:
  - ./.travis/run.sh
  - ```
uilianries commented 2 years ago

@katetsu thank you, is your project public on github, can you share its link? So I can read Travis log (if public too).

It's clear the package reference is empty, but I still can't figure out how it happened, because it's validated/parsed before been passed to Docker.

katetsu commented 2 years ago

unfortunately not. is it possible that conan package manager is looking to see if it can find the package in the registry. as this is a new package its possible that the recipe is not there yet....

uilianries commented 2 years ago

@katetsu No problem, I'll investigate using that information.

katetsu commented 2 years ago

full travis log:

 >> - CI detected: Travis CI
WARN: Remotes registry file missing, creating default one in /home/travis/.conan/remotes.json
 >> Branch detected
   >> master
 >> Info
   >> Redefined channel by CI branch matching with 'master$', setting CONAN_CHANNEL to 'stable'
[local_vars]
+---------------------------+-----------------------------------------------+
| Configuration             | value                                         |
|---------------------------+-----------------------------------------------|
| cwd                       | /home/travis/build/software/conan-boost |
| username                  | gen                                           |
| skip_check_credentials    | False                                         |
| upload_only_when_stable   | False                                         |
| upload_only_when_tag      | False                                         |
| upload_only_recipe        | False                                         |
| upload_force              | True                                          |
| stable_branch_pattern     | master$ main$ release.* stable.*              |
| stable_channel            | stable                                        |
| channel                   | stable                                        |
| conanfile                 | conanfile.py                                  |
| use_docker                | True                                          |
| docker_conan_home         | /home/user                                   |
| build_policy              | boost                                         |
| sudo_docker_command       | sudo -E                                       |
| sudo_pip_command          | sudo -E                                       |
| pip_command               | pip                                           |
| docker_pip_command        | pip                                           |
| docker_shell              | /bin/sh -c                                    |
| docker_platform_param     |                                               |
| lcow_user_workaround      |                                               |
| exclude_vcvars_precommand | False                                         |
| upload_dependencies       | all                                           |
| update_dependencies       | False                                         |
| docker_32_images          | False                                         |
| force_selinux             | False                                         |
| conan_pip_package         | conan==1.42.0                                 |
| vs10_x86_64_enabled       | False                                         |
| builds_in_current_page    | []                                            |
| skip_recipe_export        | False                                         |
+---------------------------+-----------------------------------------------+
 >> Running builds...
 >> Verifying credentials...
 >> OK! '[secure]' user logged in 'upload_repo' 
Page: 1/1
+-----+--------------+
|   # | build_type   |
|-----+--------------|
|   1 | Debug        |
+-----+--------------+
 >> Build: 1/1
Traceback (most recent call last):
  File "/home/travis/build/software/conan-boost/.travis/build.py", line 11, in <module>
    builder.run()
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/packager.py", line 585, in run
    self.run_builds(base_profile_name=base_profile_name,
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/packager.py", line 737, in run_builds
    r.run(pull_image=not pulled_docker_images[docker_image],
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/runner.py", line 281, in run
    envs = self.get_env_vars()
  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/cpt/runner.py", line 370, in get_env_vars
    ret["CONAN_USERNAME"] = escape_env(self._reference.user or ret.get("CONAN_USERNAME"))
AttributeError: 'NoneType' object has no attribute 'user'
The command "./.travis/run.sh" exited with 1.
uilianries commented 2 years ago

Tahnk you!

uilianries commented 2 years ago

@katetsu Now I can reproduce your error! Thank you for sharing all details

uilianries commented 2 years ago

@katetsu Checking the code, I can presume your build doesn't have a package reference. That error is because there is no treatment for it, but basically:

1) When ConanMultiPackager is constructed, it can receive the package reference from the parameter reference or CONAN_REFERENCE environment variable. 2) If you pass the reference, CPT parses it and store in self.reference 3) If you don't pass a reference, it loads your conanfile.py and collect both name and version from there to formulate a reference 4) In case your conanfile.py doesn't contain name or version, the reference will be None and CPT won't warn you. 5) When adding a new job with builder.add(...) you can pass the reference as parameter 6) But if you don't pass a parameter, CPT will use self.reference instead, but won't check if is None or not 7) When executing your builds, CPT will collect each build and its data, including the reference stored there. 8) As your reference is None, it can parse it and crash.

So, your package reference is missing. There are multiple ways to pass it, environment variable CONAN_REFERENCE, by filling your conanfile.py with name and version, passing by parameter to ConanMultiPackager constructor, or passing as parameter to .add() method.

That's a prone error, not a bug, but still, CPT should warn the user, or at least fail with a helpful message. I'll open a PR improving it, but you need to fix your side too.

katetsu commented 2 years ago

Thanks a lot @uilianries. this resolved my problem. :)