containers / skopeo

Work with remote images registries - retrieving information, images, signing content
Apache License 2.0
8.24k stars 780 forks source link

help: skopeo sync How to preserve the project name of the mirror #1992

Open jinjianming opened 1 year ago

jinjianming commented 1 year ago

For example mine : sync.yml

 registry.js.design:
      images:
          justwatch/elasticsearch_exporter:
              - "1.1.0"
          elasticsearch/elasticsearch:
              - "7.8.1"

My Sync Command

skopeo sync --tls-verify=false --src yaml --dest docker sync.yml js-registry:5000/

My expected effect

js-registry:5000/justwatch/elasticsearch_exporter:1.1.0
js-registry:5000/elasticsearch/elasticsearch:7.8.1

Actual effect

js-registry:5000/elasticsearch_exporter:1.1.0
js-registry:5000/elasticsearch:7.8.1
mtrmac commented 1 year ago

There is --scoped, but that might also not do exactly what you need.

jinjianming commented 1 year ago

--scoped,但这也可能无法完全满足您的需要。

I tried it and brought over the domain name of the source warehouse. I only want to bring the following path

[root@js-staging-env-177 ~]# skopeo sync  --scoped --src docker --dest docker --src-tls-verify=false --dest-tls-verify=false registry.js.design/bitnami/redis-exporter:1.24.0-debian-10-r9 js-registry:5000/
INFO[0000] Tag presence check                            imagename="registry.js.design/bitnami/redis-exporter:1.24.0-debian-10-r9" tagged=true
INFO[0000] Copying image ref 1/1                         from="docker://registry.js.design/bitnami/redis-exporter:1.24.0-debian-10-r9" to="docker://js-registry:5000/registry.js.design/bitnami/redis-exporter:1.24.0-debian-10-r9"

reality

js-registry:5000/registry.js.design/bitnami/redis-exporter:1.24.0-debian-10-r9

expect

js-registry:5000/bitnami/redis-exporter:1.24.0-debian-10-r9
mtrmac commented 1 year ago

Yes; I think the only way right now is to split up the YAML file and run skopeo sync several times with different destinations.

jinjianming commented 1 year ago

是的; 我认为现在唯一的方法是拆分 YAML 文件并skopeo sync在不同的目的地运行多次。

I implemented it through the following script

function sync_docker(){
    REGISTRY="js-registry:5000"
    local yml_file=$2
# Get image names and tags from sync.yml and iterate through them
 cat $yml_file  | yq -o=json .[].images | jq -r 'to_entries[] | "\(.key):\(.value[0])"' | while read line; do
    image=$(echo "$line" | cut -d',' -f2)   # Extract image name and tag
    project=$(echo "$line" | cut -d',' -f1 | cut -d'/' -f1 )   # Extract project name
    dest_image="${REGISTRY}/${project}"   # Construct destination image name

    # Use skopeo sync to copy image from source to destination
    skopeo --insecure-policy sync \
        --src docker \
        --dest docker \
        --src-tls-verify=false \
        --dest-tls-verify=false \
        "registry.js.design/${image}" "${dest_image}"
done
}
github-actions[bot] commented 1 year ago

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] commented 1 year ago

A friendly reminder that this issue had no activity for 30 days.