cnabio / cnab-to-oci

Tool to convert CNAB bundle.json to OCI index
Apache License 2.0
54 stars 41 forks source link

Add log-level flag and more verbosity #60

Closed silvin-lubecki closed 5 years ago

silvin-lubecki commented 5 years ago

Adding a global --log-level to cnab-to-oci binary to set the log level. Also added logs to print manifests, descriptors or payloads sent or received to/from the registry.

Fixing #36 Fixing #37

Log example while pushing a bundle:

Starting to copy image cnab/helloworld:0.1.1...
Completed image cnab/helloworld:0.1.1 copy
INFO[0001] Pushing CNAB Bundle docker.io/slubecki/example 
INFO[0001] Pushing CNAB Bundle Config                   
INFO[0001] Trying to push CNAB Bundle Config            
INFO[0001] CNAB Bundle Config Descriptor                
INFO[0001] {
  "mediaType": "application/vnd.cnab.config.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0002] Trying to push CNAB Bundle Config Manifest   
INFO[0002] {"schemaVersion":2,"config":{"mediaType":"application/vnd.cnab.config.v1+json","digest":"sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2","size":85},"layers":null} 
INFO[0002] CNAB Bundle Config Manifest Descriptor       
INFO[0002] {
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "digest": "sha256:48e531da09f75a06f71f7006886217b242066c387eec6a033d8ef9d537f91eb4",
  "size": 187
} 
INFO[0002] Failed to push CNAB Bundle Config Manifest, trying with a fallback method 
INFO[0002] Trying to push CNAB Bundle Config            
INFO[0002] CNAB Bundle Config Descriptor                
INFO[0002] {
  "mediaType": "application/vnd.oci.image.config.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0002] Trying to push CNAB Bundle Config Manifest   
INFO[0002] {"schemaVersion":2,"config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2","size":85},"layers":null} 
INFO[0002] CNAB Bundle Config Manifest Descriptor       
INFO[0002] {
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "digest": "sha256:f771c1a50c316b5a75ebdea214c61ac1c5b9c7aac9461e2bd5de75ae8a7101a3",
  "size": 192
} 
INFO[0003] Failed to push CNAB Bundle Config Manifest, trying with a fallback method 
INFO[0003] Trying to push CNAB Bundle Config            
INFO[0003] CNAB Bundle Config Descriptor                
INFO[0003] {
  "mediaType": "application/vnd.docker.container.image.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0003] Trying to push CNAB Bundle Config Manifest   
INFO[0003] {
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/vnd.docker.container.image.v1+json",
      "size": 85,
      "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2"
   },
   "layers": null
} 
INFO[0003] CNAB Bundle Config Manifest Descriptor       
INFO[0003] {
  "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
  "digest": "sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca",
  "size": 314
} 
INFO[0003] CNAB Bundle Config pushed                    
INFO[0003] Pushing CNAB Index                           
INFO[0003] Trying to push OCI Index                     
INFO[0003] {"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca","size":314,"annotations":{"io.cnab.manifest.type":"config"}},{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:a59a4e74d9cc89e4e75dfb2cc7ea5c108e4236ba6231b53081a9e2506d1197b6","size":942,"annotations":{"io.cnab.manifest.type":"invocation"}}],"annotations":{"io.cnab.keywords":"[\"helloworld\",\"cnab\",\"tutorial\"]","io.cnab.runtime_version":"v1.0.0-WD","org.opencontainers.artifactType":"application/vnd.cnab.manifest.v1","org.opencontainers.image.authors":"[{\"name\":\"Jane Doe\",\"email\":\"jane.doe@example.com\",\"url\":\"https://example.com\"}]","org.opencontainers.image.description":"A short description of your bundle","org.opencontainers.image.title":"helloworld","org.opencontainers.image.version":"0.1.1"}} 
INFO[0003] OCI Index Descriptor                         
INFO[0003] {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:5ebd1c9faa0b056a48eeac5ae3a65f1964dbebd72e7742e65b5d8d07529e648d",
  "size": 939
} 
INFO[0003] Trying to push Index with Manifest list as fallback 
INFO[0003] {"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca","size":314,"annotations":{"io.cnab.manifest.type":"config"}},{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:a59a4e74d9cc89e4e75dfb2cc7ea5c108e4236ba6231b53081a9e2506d1197b6","size":942,"annotations":{"io.cnab.manifest.type":"invocation"}}],"annotations":{"io.cnab.keywords":"[\"helloworld\",\"cnab\",\"tutorial\"]","io.cnab.runtime_version":"v1.0.0-WD","org.opencontainers.artifactType":"application/vnd.cnab.manifest.v1","org.opencontainers.image.authors":"[{\"name\":\"Jane Doe\",\"email\":\"jane.doe@example.com\",\"url\":\"https://example.com\"}]","org.opencontainers.image.description":"A short description of your bundle","org.opencontainers.image.title":"helloworld","org.opencontainers.image.version":"0.1.1"},"mediaType":"application/vnd.docker.distribution.manifest.list.v2+json"} 
INFO[0003] Manifest list Descriptor                     
INFO[0003] {
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "digest": "sha256:9211937178808b38655f461c6753b1e585e98fbf20a8f43d349ee70fefe8be80",
  "size": 1011
} 
INFO[0004] CNAB Index pushed                            
Pushed successfully, with digest "sha256:9211937178808b38655f461c6753b1e585e98fbf20a8f43d349ee70fefe8be80"

silvin@Silvins-MacBook-Pro ~/dev/go/src/github.com/docker/cnab-to-oci                                                                                                                                                                                     [17:19:02] 
> $ make bin/cnab-to-oci && ./bin/cnab-to-oci push examples/helloworld-cnab/bundle.json -t slubecki/example --log-level=info                                                                                                                            [±master ●●]
CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/docker/cnab-to-oci/internal.GitCommit=0bf8355 -X github.com/docker/cnab-to-oci/internal.Version=0bf8355-dirty -X github.com/docker/cnab-to-oci/internal.BuildTime=2019-08-07T15:50:44Z" -o bin/cnab-to-oci ./cmd/cnab-to-oci
INFO[0000] Fixing up bundle docker.io/slubecki/example  
INFO[0000] Fixing image cnab/helloworld:0.1.1           
Starting to copy image cnab/helloworld:0.1.1...
Completed image cnab/helloworld:0.1.1 copy
INFO[0001] Bundle fixed                                 
INFO[0001] Pushing CNAB Bundle docker.io/slubecki/example 
INFO[0001] Pushing CNAB Bundle Config                   
INFO[0001] Trying to push CNAB Bundle Config            
INFO[0001] CNAB Bundle Config Descriptor                
INFO[0001] {
  "mediaType": "application/vnd.cnab.config.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0002] Trying to push CNAB Bundle Config Manifest   
INFO[0002] {"schemaVersion":2,"config":{"mediaType":"application/vnd.cnab.config.v1+json","digest":"sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2","size":85},"layers":null} 
INFO[0002] CNAB Bundle Config Manifest Descriptor       
INFO[0002] {
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "digest": "sha256:48e531da09f75a06f71f7006886217b242066c387eec6a033d8ef9d537f91eb4",
  "size": 187
} 
INFO[0002] Failed to push CNAB Bundle Config Manifest, trying with a fallback method 
INFO[0002] Trying to push CNAB Bundle Config            
INFO[0002] CNAB Bundle Config Descriptor                
INFO[0002] {
  "mediaType": "application/vnd.oci.image.config.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0002] Trying to push CNAB Bundle Config Manifest   
INFO[0002] {"schemaVersion":2,"config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2","size":85},"layers":null} 
INFO[0002] CNAB Bundle Config Manifest Descriptor       
INFO[0002] {
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "digest": "sha256:f771c1a50c316b5a75ebdea214c61ac1c5b9c7aac9461e2bd5de75ae8a7101a3",
  "size": 192
} 
INFO[0003] Failed to push CNAB Bundle Config Manifest, trying with a fallback method 
INFO[0003] Trying to push CNAB Bundle Config            
INFO[0003] CNAB Bundle Config Descriptor                
INFO[0003] {
  "mediaType": "application/vnd.docker.container.image.v1+json",
  "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2",
  "size": 85
} 
INFO[0003] Trying to push CNAB Bundle Config Manifest   
INFO[0003] {
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/vnd.docker.container.image.v1+json",
      "size": 85,
      "digest": "sha256:4932714d45b6c6da0b2c3665406703cef66d0b655dc0f1ad700a9977ceab92c2"
   },
   "layers": null
} 
INFO[0003] CNAB Bundle Config Manifest Descriptor       
INFO[0003] {
  "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
  "digest": "sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca",
  "size": 314
} 
INFO[0003] CNAB Bundle Config pushed                    
INFO[0003] Pushing CNAB Index                           
INFO[0003] Trying to push OCI Index                     
INFO[0003] {"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca","size":314,"annotations":{"io.cnab.manifest.type":"config"}},{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:a59a4e74d9cc89e4e75dfb2cc7ea5c108e4236ba6231b53081a9e2506d1197b6","size":942,"annotations":{"io.cnab.manifest.type":"invocation"}}],"annotations":{"io.cnab.keywords":"[\"helloworld\",\"cnab\",\"tutorial\"]","io.cnab.runtime_version":"v1.0.0-WD","org.opencontainers.artifactType":"application/vnd.cnab.manifest.v1","org.opencontainers.image.authors":"[{\"name\":\"Jane Doe\",\"email\":\"jane.doe@example.com\",\"url\":\"https://example.com\"}]","org.opencontainers.image.description":"A short description of your bundle","org.opencontainers.image.title":"helloworld","org.opencontainers.image.version":"0.1.1"}} 
INFO[0003] OCI Index Descriptor                         
INFO[0003] {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:5ebd1c9faa0b056a48eeac5ae3a65f1964dbebd72e7742e65b5d8d07529e648d",
  "size": 939
} 
INFO[0003] Trying to push Index with Manifest list as fallback 
INFO[0003] {"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:c7f0fc9c7507708a723f7a2315977268632ae7bde76a25d1fbb3bec436db2dca","size":314,"annotations":{"io.cnab.manifest.type":"config"}},{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:a59a4e74d9cc89e4e75dfb2cc7ea5c108e4236ba6231b53081a9e2506d1197b6","size":942,"annotations":{"io.cnab.manifest.type":"invocation"}}],"annotations":{"io.cnab.keywords":"[\"helloworld\",\"cnab\",\"tutorial\"]","io.cnab.runtime_version":"v1.0.0-WD","org.opencontainers.artifactType":"application/vnd.cnab.manifest.v1","org.opencontainers.image.authors":"[{\"name\":\"Jane Doe\",\"email\":\"jane.doe@example.com\",\"url\":\"https://example.com\"}]","org.opencontainers.image.description":"A short description of your bundle","org.opencontainers.image.title":"helloworld","org.opencontainers.image.version":"0.1.1"},"mediaType":"application/vnd.docker.distribution.manifest.list.v2+json"} 
INFO[0003] Manifest list Descriptor                     
INFO[0003] {
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "digest": "sha256:9211937178808b38655f461c6753b1e585e98fbf20a8f43d349ee70fefe8be80",
  "size": 1011
} 
INFO[0004] CNAB Index pushed                            
Pushed successfully, with digest "sha256:9211937178808b38655f461c6753b1e585e98fbf20a8f43d349ee70fefe8be80"
silvin-lubecki commented 5 years ago

cc @radu-matei

rumpl commented 5 years ago

Shouldn't the existing fmt.Print* calls be converted to logrus?