Build

Build resource allows to submit new builds and access current build progress.

In fact, build consists of a few tasks, one per chroot, and detailed information is available through resource Build Task.

Structure of the build entity

{
    "enable_net": true,
    "source_metadata": {
        "tmp": "tmpUNPJWO",
        "pkg": "python-marshmallow-2.0.0b5-1.fc22.src.rpm"
    },
    "submitted_on": 1440753750,
    "repos": [],
    "built_packages": [
        {
            "version": "2.0.0b5",
            "name": "python3-marshmallow"
        },
        {
            "version": "2.0.0b5",
            "name": "python-marshmallow"
        }
    ],
    "started_on": null,
    "source_type": "srpm_upload",
    "state": "succeeded",
    "ended_on": 1440754058,
    "package_version": "2.0.0b5-1.fc22",
    "package_name": "python-marshmallow",
    "id": 106882,
    "submitter": "asamalik"
}

Build fields

Field Type Description
id int unique build identifier
state string current state of the build, value is aggregated from build tasks
submitted_on int(unixtime UTC) time of the build submission
started_on int(unixtime UTC) time when the first build task started, otherwise null
ended_on int(unixtime UTC) time when the last build task ended, otherwise null
source_type string method used for build creation
source_metadata json object build source information
package_version string version of the source package
package_name string name of the source package
enable_net bool defines if network is available during the build
repos list of string list of additional repositories enabled during the build
built_packages list of hash maps list of the built packages, each hash map has two keys: name and version
submitter string name of the user who submitted the build

Note

Only the state field is editable by the PUT method. All other fields are read-only. There is a different structure used for build creation, see details at Submit new build.

List builds

POST /api_2/builds

Returns a list of builds according to the given query parameters.

Query Parameters:
 
  • owner (str) – select only builds from projects owned by this user
  • project_id (str) – select only projects owned by this project
  • offset (int) – offset number, default value is 0
  • limit (int) – limit number, default value is 100
Status Codes:

Example request:

GET /api_2/builds?project_id=3985&limit=1 HTTP/1.1
Host: copr.fedoraproject.org

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "_links": {
    "self": {
      "href": "/api_2/builds?project_id=3985&limit=1"
    }
  },
  "builds": [
    {
      "_links": {
        "project": {
          "href": "/api_2/projects/3985"
        },
        "self": {
          "href": "/api_2/builds/106897"
        },
        "build_tasks": {
          "href": "/api_2/build_tasks?build_id=106897"
        }
      },
      "build": {
        "enable_net": true,
        "source_metadata": {
          "url": "http://miroslav.suchy.cz/copr/copr-ping-1-1.fc20.src.rpm"
        },
        "package_name": "copr-ping",
        "submitted_on": 1441366834,
        "package_version": "1-1.fc20",
        "built_packages": [
          {
            "version": "1",
            "name": "copr-ping"
          }
        ],
        "started_on": null,
        "source_type": "srpm_link",
        "state": "succeeded",
        "ended_on": 1441366969,
        "id": 106897,
        "repos": [],
        "submitter": "asamalik"
      }
    }
  ]
}

Submit new build

REQUIRES AUTH

There are more ways to submit new build. Copr services currently provides the following options for build submission:

From SRPM URL

{
    "project_id": 3985,
    "chroots": ["fedora-22-i386", "fedora-21-i386"],
    "srpm_url": "http://miroslav.suchy.cz/copr/copr-ping-1-1.fc20.src.rpm"
}
Field Type Description
project_id int identifier of the parent project
chroots list of strings which chroots should be used for build
srpm_url string(URL) URL to the publicly available source package
enable_net bool allows to disable network access during the build, default: True
POST /api_2/builds
Request Headers:
 
Response Headers:
 
  • Location – contains URL to the submitted build
Status Codes:

Example request:

POST /api_2/builds HTTP/1.1
Host: copr.fedoraproject.org
Authorization: Basic base64=encoded=string
Content-Type: application/json

{
    "project_id": 3985,
    "chroots": ["fedora-22-i386", "fedora-21-i386"],
    "srpm_url": "http://miroslav.suchy.cz/copr/copr-ping-1-1.fc20.src.rpm"
}

Response:

HTTP/1.1 201 CREATED
Location: /api_2/builds/106897

Using SRPM file upload

To upload source package you MUST use multipart/form-data content type. An additional build information MUST be present in metadata part in JSON format. Source package MUST be uploaded as binary srpm file.

{
    "project_id": 3985,
    "chroots": ["fedora-22-i386", "fedora-21-i386"],
    "enable_net": false
}
Field Type Description
project_id int identifier of the parent project
chroots list of strings which chroots should be used for build
enable_net bool allows to disable network access during the build, default: True
POST /api_2/builds
Request Headers:
 
Form Parameters:
 
  • metadata – JSON with the build info, MUST have a content type application/json
  • srpm – file with source package, MUST have a content type application/x-rpm
Response Headers:
 
  • Location – contains URL to the created build
Status Codes:

Note

Using a multipart/form-data might not be nice to read. To make your life a bit brighter, a Python example is included below.

Example request:

POST /api_2/builds HTTP/1.1
Host: copr.fedoraproject.org
Authorization: Basic base64=encoded=string
Content-Length: xxxx
Content-Type: multipart/form-data; boundary=--------------------31063722920652

------------------------------31063722920652
Content-Disposition: form-data; name="metadata"
Content-Type: application/json

{
    "project_id": 3985,
    "chroots": ["fedora-22-i386", "fedora-21-i386"],
    "enable_net": false
}

------------------------------31063722920652
Content-Disposition: form-data; name="srpm"; filename="package-2.6-fc21.src.rpm"
Content-Type: application/x-rpm

<< SRPM BINARY CONTENT HERE >>

-----------------------------31063722920652--

Response:

HTTP/1.1 201 CREATED
Location: /api_2/builds/106897

Python Example:

Here we use python-requests lib:

>>> import json
>>> from requests import post
>>> api_url = "http://copr-fe-dev.cloud.fedoraproject.org/api_2/builds"
>>> api_login = "my api login"
>>> api_token = "my api token"
>>> metadata = {
>>>     'chroots': ['fedora-22-i386', 'fedora-21-i386'],
>>>     'project_id': 3985,
>>> }
>>> files = {
>>>     "srpm": ('pkg.src.rpm', open('/path/to/pkg.src.rpm'), 'application/x-rpm'),
>>>     "metadata": ('', json.dumps(metadata))
>>>     # here some requests specific, see http://stackoverflow.com/questions/12385179
>>> }
>>> r = post(api_url, auth=(api_login, api_token), files=files)
>>> r.status_code
201
>>> r.headers["Location"]
http://copr-fe-dev.cloud.fedoraproject.org/api_2/builds/106899

Get build details

GET /api_2/builds/(int: build_id)

Returns details about build

Parameters:
  • build_id (int) – a unique identifier of the build
Query Parameters:
 
  • show_build_tasks (bool) – embed Build Task sub-resources into the result, default is False
Status Codes:

Example request

GET /api_2/builds/106897?show_build_tasks=True HTTP/1.1
Host: copr.fedoraproject.org

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "build_tasks": [
    {
      "tasks": {
        "build_id": 3985,
        "chroot_name": "fedora-21-i386",
        "started_on": 1441366860,
        "state": "succeeded",
        "ended_on": 1441366969,
        "result_dir_url": "http://copr-be-dev.cloud.fedoraproject.org/results/vgologuz/aeghqawgt/fedora-21-i386/00106897-copr-ping",
        "git_hash": "8daed2e23140243d8beaafb0fee436c1bca3fdf7"
      },
      "_links": {
        "project": {
          "href": "/api_2/projects/3985"
        },
        "self": {
          "href": "/api_2/build_tasks/106897/fedora-21-i386"
        }
      }
    }
  ],
  "_links": {
    "project": {
      "href": "/api_2/projects/3985"
    },
    "self": {
      "href": "/api_2/builds/106897?show_chroots=True"
    },
    "build_tasks": {
      "href": "/api_2/build_tasks/?build_id=3985"
    }
  },
  "build": {
    "enable_net": true,
    "source_metadata": {
      "url": "http://miroslav.suchy.cz/copr/copr-ping-1-1.fc20.src.rpm"
    },
    "package_name": "copr-ping",
    "submitted_on": 1441366834,
    "package_version": "1-1.fc20",
    "built_packages": [
      {
        "version": "1",
        "name": "copr-ping"
      }
    ],
    "started_on": null,
    "source_type": "srpm_link",
    "state": "succeeded",
    "ended_on": 1441366969,
    "id": 106897,
    "repos": [],
    "submitter": "asamalik"
  }
}

Cancel build

Build cancellation is done be setting build state to cancelled.

PUT /api_2/builds/(int: build_id)

REQUIRE AUTH

Parameters:
  • build_id (int) – a unique identifier of the build
Status Codes:

Example request:

PUT /api_2/builds/1 HTTP/1.1
Host: copr.fedoraproject.org
Authorization: Basic base64=encoded=string
Content-Type: application/json

{
    "state": "cancelled"
}

Response

HTTP/1.1 204 NO CONTENT

Delete build

DELETE /api_2/builds/(int: build_id)

REQUIRE AUTH

Deletes build and schedules deletion of build result from the Copr backend

Parameters:
  • build_id (int) – a unique identifier of the build
Status Codes:

Example request:

DELETE /api_2/builds/1 HTTP/1.1
Host: copr.fedoraproject.org
Authorization: Basic base64=encoded=string

Response

HTTP/1.1 204 NO CONTENT