Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,8 @@ dmypy.json
tests/credentials.py
tmp*/*
.idea/*
demos/build-info/liba
demos/build-info/mypkg
demos/build-info/.conanrc
**/.conan_home/**
demos/build-info/*.json
112 changes: 112 additions & 0 deletions demos/build-info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Using Build Info with Conan
===========================

Demo Pre-Requisites
-------------------

Have an Artifactory instance running (needs a version with API support, Artifactory
Community Edition won't work for this) with at least one repository called ``develop``.

To test the Relase Bundles generation you also need a [signing key already
created](https://jfrog.com/help/r/jfrog-artifactory-documentation/setting-up-rsa-keys-pairs)
in Artifactory.

To easily run an Artifactory in Docker:

```
docker run --name artifactory -d -e JF_SHARED_DATABASE_TYPE=derby -e JF_SHARED_DATABASE_ALLOWNONPOSTGRESQL=true -p 8081:8081 -p 8082:8082 releases-docker.jfrog.io/jfrog/artifactory-pro:latest
```

To test, you need to have the extensions installed:

```
conan config install https://github.com/conan-io/conan-extensions.git
```

We will create a BuildInfo with ``build_name=<Release/Debug>_build`` ``build_number=1``
and then create an aggregated Build Info for both Release and Debug configurations

mypkg depending on liba, liba already in Artifactory, we are only building mypkg.

Two paralell jobs creating Release and Debug, each one with a BuildInfo, then aggregate
them

![Alt build](diagram.png?raw=true)

Running the demo
----------------

```

# Add the repos if you haven't already

conan remote add develop http://localhost:8081/artifactory/api/conan/develop
conan remote login develop admin -p password

# Also configure the server for the Build Info command

conan art:server add myartifactory http://localhost:8081/artifactory --user=admin --password=password

# Also you need to have the packages ready for creation:

conan new cmake_lib -d name=liba -d version=1.0 -o=liba
conan new cmake_lib -d name=mypkg -d version=1.0 -o=mypkg -d requires="liba/1.0"

# Start from a clean state

conan remove "*" -r=develop -c
conan remove "liba*" -c
conan remove "mypkg*" -c

# Create liba

conan create liba -s build_type=Release -tf=""
conan create liba -s build_type=Debug -tf=""

# We upload to Artifactory, we will pick the information for the build info from there later

conan upload "liba*" -r=develop -c

conan remove "liba*" -c

# Release CI JOB

# build mypkg Release, will pick liba from Artifactory

conan create mypkg --format=json -s build_type=Release --build="mypkg*" -r=develop > create_release.json

conan upload "mypkg*" -r=develop -c

# create the Build Info for Release and set the properties to the Artifacts in Artifactory

conan art:build-info create create_release.json release_build 1 develop --server=myartifactory --with-dependencies > release_build.json

# Upload the Build Info

conan art:build-info upload release_build.json --server=myartifactory

# Debug CI JOB

# build mypkg Debug, will pick liba from Artifactory

conan create mypkg --format=json -s build_type=Debug --build="mypkg*" -r=develop > create_debug.json

conan upload "mypkg*" -r=develop -c

# create the Build Info for Debug and set the properties to the Artifacts in Artifactory

conan art:build-info create create_debug.json debug_build 1 develop --server=myartifactory --with-dependencies > debug_build.json

# Upload the Build Info

conan art:build-info upload debug_build.json --server=myartifactory

# parent CI job

conan art:build-info append aggregated_build 1 --server=myartifactory --build-info=release_build,1 --build-info=debug_build,1 > aggregated_build.json
conan art:build-info upload aggregated_build.json --server=myartifactory

# Still in Beta

conan art:build-info create-bundle aggregated_build.json develop aggregated_bundle 1.0 test_key_pair --server=myartifactory
```
Binary file added demos/build-info/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 24 additions & 9 deletions extensions/commands/art/cmd_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ def create(self):


def _manifest_from_build_info(build_info, repository, with_dependencies=True):
manifest = {"files": []}
manifest = {"artifacts": []}
for module in build_info.get("modules"):
for artifact in module.get("artifacts"):
manifest["files"].append({"path": artifact.get("path"), "checksum": artifact.get("sha256")})
manifest["artifacts"].append({"path": artifact.get("path"), "sha256": artifact.get("sha256")})
if with_dependencies:
for dependency in module.get("dependencies"):
full_reference = dependency.get("id").split("::")[0].strip()
Expand All @@ -345,8 +345,8 @@ def _manifest_from_build_info(build_info, repository, with_dependencies=True):
pkgid = full_reference.split(":")[1].split("#")[0]
prev = full_reference.split(":")[1].split("#")[1]
full_path = repository + "/" + _get_remote_path(rrev, pkgid, prev) + "/" + filename
if not any(d['path'] == full_path for d in manifest["files"]):
manifest["files"].append({"path": full_path, "checksum": dependency.get("sha256")})
if not any(d['path'] == full_path for d in manifest["artifacts"]):
manifest["artifacts"].append({"path": full_path, "sha256": dependency.get("sha256")})
return manifest


Expand Down Expand Up @@ -609,7 +609,7 @@ def build_info_append(conan_api: ConanAPI, parser, subparser, *args):
@conan_subcommand()
def build_info_create_bundle(conan_api: ConanAPI, parser, subparser, *args):
"""
Creates an Artifactory Release Bundle from the information of the Build Info
Creates an Artifactory Release Bundle (v2) from the information of the Build Info.
"""
_add_default_arguments(subparser, is_bi_create_bundle=True)

Expand All @@ -622,6 +622,8 @@ def build_info_create_bundle(conan_api: ConanAPI, parser, subparser, *args):

subparser.add_argument("sign_key_name", help="Signing Key name.")

subparser.add_argument("--project", help="Project key for the Release Bundle in Artifactory", default=None)

args = parser.parse_args(*args)
assert_server_or_url_user_password(args)

Expand All @@ -632,13 +634,26 @@ def build_info_create_bundle(conan_api: ConanAPI, parser, subparser, *args):
manifest = _manifest_from_build_info(data, args.repository, with_dependencies=True)

bundle_json = {
"payload": manifest
"release_bundle_name": args.bundle_name,
"release_bundle_version": args.bundle_version,
"source_type": "artifacts",
"source": manifest
}

request_url = f"{url}/api/release_bundles/from_files/{args.bundle_name}/{args.bundle_version}"
print(json.dumps(bundle_json))

response = api_request("post", request_url, user, password, json_data=json.dumps(bundle_json),
sign_key_name=args.sign_key_name)
request_url = f"{url}/lifecycle/api/v2/release_bundle?async=false"
if args.project:
request_url += f"&project={args.project}"

response = api_request(
"post",
request_url,
user,
password,
json_data=json.dumps(bundle_json),
sign_key_name=args.sign_key_name
)

if response:
cli_out_write(response)
2 changes: 1 addition & 1 deletion tests/test_artifactory_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_build_info_create_deps():
# run(f'conan install --requires=mypkg/1.0')

# Promotions using Release Bundles do work with depdendencies, but they are not implemented in the testing Artifactory
# conan art:build-info create-bundle ${build_name}_aggregated.json develop full_bundle 1.0 ${ART_URL} test_key_pair --user=${CONAN_LOGIN_USERNAME_DEVELOP} --password="${CONAN_PASSWORD_DEVELOP}"
run(f'conan art:build-info create-bundle ${build_name}_aggregated.json develop full_bundle 1.0 --server="artifactory" test_key_pair')

# Remove build-infos to clean artifactory
run(f'conan art:build-info delete {build_name}_release --build-number={build_number} --server="artifactory" --delete-all --delete-artifacts')
Expand Down
Loading