|
| 1 | +:_content-type: CONCEPT |
| 2 | +[id="quay-mirror-api"] |
| 3 | += Using the API to mirror a repository |
| 4 | + |
| 5 | +{productname} administrators can mirror external repositories by using the API. |
| 6 | + |
| 7 | +.Prerequisites |
| 8 | + |
| 9 | +* You have set `FEATURE_REPO_MIRROR: true` in your `config.yaml` file. |
| 10 | +
|
| 11 | +.Procedure |
| 12 | + |
| 13 | +* Create a new repository mirror configuration by using the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#createrepomirrorconfig[`POST /api/v1/repository/{repository}/mirror`] endpoint: |
| 14 | ++ |
| 15 | +[source,terminal] |
| 16 | +---- |
| 17 | +$ curl -X POST "https://<quay-server.example.com>/api/v1/repository/<namespace>/<repo>/mirror" \ |
| 18 | + -H "Authorization: Bearer <access_token>" \ |
| 19 | + -H "Content-Type: application/json" \ |
| 20 | + -d '{ |
| 21 | + "is_enabled": <is_enabled>, |
| 22 | + "external_reference": "<external_reference>", |
| 23 | + "external_registry_username": "<external_registry_username>", |
| 24 | + "external_registry_password": "<external_registry_password>", |
| 25 | + "sync_start_date": "<sync_start_date>", |
| 26 | + "sync_interval": <sync_interval>, |
| 27 | + "robot_username": "<robot_username>", |
| 28 | + "root_rule": { |
| 29 | + "rule": "<rule>", |
| 30 | + "rule_type": "<rule_type>" |
| 31 | + } |
| 32 | + }' |
| 33 | +---- |
| 34 | +
|
| 35 | +* You can return information about the mirror configuration by using the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#getrepomirrorconfig[`GET /api/v1/repository/{repository}/mirror`] endpoint: |
| 36 | ++ |
| 37 | +[source,terminal] |
| 38 | +---- |
| 39 | +$ curl -X GET "https://<quay-server.example.com>/api/v1/repository/<namespace>/<repo>/mirror" \ |
| 40 | + -H "Authorization: Bearer <access_token>" |
| 41 | +---- |
| 42 | ++ |
| 43 | +.Example output |
| 44 | ++ |
| 45 | +[source,terminal] |
| 46 | +---- |
| 47 | +{"is_enabled": true, "mirror_type": "PULL", "external_reference": "https://quay.io/repository/argoproj/argocd", "external_registry_username": null, "external_registry_config": {}, "sync_interval": 86400, "sync_start_date": "2025-01-15T12:00:00Z", "sync_expiration_date": null, "sync_retries_remaining": 3, "sync_status": "NEVER_RUN", "root_rule": {"rule_kind": "tag_glob_csv", "rule_value": ["*.latest*"]}, "robot_username": "quayadmin+mirror_robot"} |
| 48 | +---- |
| 49 | +
|
| 50 | +* You can use the link:https://docs.redhat.com/en/documentation/red_hat_quay/{producty}/html-single/red_hat_quay_api_guide/index#syncnow[`POST /api/v1/repository/{repository}/mirror/sync-now`] endpoint to sync the repositories. For example: |
| 51 | ++ |
| 52 | +[source,terminal] |
| 53 | +---- |
| 54 | +$ curl -X POST "https://<quay-server.example.com>/api/v1/repository/<namespace>/<repo>/mirror/sync-now" \ |
| 55 | + -H "Authorization: Bearer <access_token>" |
| 56 | +---- |
| 57 | ++ |
| 58 | +This command does not return output in the CLI. |
| 59 | +
|
| 60 | +* Alternatively, you can cancel the sync with the link:https://docs.redhat.com/en/documentation/red_hat_quay/{producty}/html-single/red_hat_quay_api_guide/index#synccancel[`POST /api/v1/repository/{repository}/mirror/sync-cancel`] endpoint.For example: |
| 61 | ++ |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +$ curl -X POST "https://<quay-server.example.com>/api/v1/repository/<namespace>/<repo>/mirror/sync-cancel" \ |
| 65 | +---- |
| 66 | ++ |
| 67 | +This command does not return output in the CLI. |
| 68 | +
|
| 69 | +* After creating a mirror configuration, you can make changes with the link:https://docs.redhat.com/en/documentation/red_hat_quay/{producty}/html-single/red_hat_quay_api_guide/index#changerepomirrorconfig[`PUT /api/v1/repository/{repository}/mirror`] command. For example, you might choose to disable automatic synchronizations: |
| 70 | ++ |
| 71 | +[source,terminal] |
| 72 | +---- |
| 73 | +$ curl -X PUT "https://<quay-server.example.com>/api/v1/repository/<namespace>/<repo>/mirror" \ |
| 74 | + -H "Authorization: Bearer <access_token>" \ |
| 75 | + -H "Content-Type: application/json" \ |
| 76 | + -d '{ |
| 77 | + "is_enabled": <false>, <1> |
| 78 | + "external_reference": "<external_reference>", |
| 79 | + "external_registry_username": "<external_registry_username>", |
| 80 | + "external_registry_password": "<external_registry_password>", |
| 81 | + "sync_start_date": "<sync_start_date>", |
| 82 | + "sync_interval": <sync_interval>, |
| 83 | + "robot_username": "<robot_username>", |
| 84 | + "root_rule": { |
| 85 | + "rule": "<rule>", |
| 86 | + "rule_type": "<rule_type>" |
| 87 | + } |
| 88 | + }' |
| 89 | +---- |
| 90 | +<1> Disables automatic synchronization. |
0 commit comments