[FEATURE REQUEST] Add GO templating capabilities to images and/or list commands

Aperta
#12,948 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #12949 di @leoperegrino — chiusa senza merge
  • #13952 di @scarab-systems — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
docker-compose, go
Ambito
cli

Direzione di ricerca

Inizia dagli entry point docker compose ls e docker compose images e confronta il loro comportamento attuale con --format json con comandi come docker ps e docker images. Il lavoro è completato quando entrambi i comandi accettano i template Go e producono un output coerente con i comandi esistenti compatibili con i template, preservando al contempo il comportamento leggibile dalle macchine richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

kind/feature
Description

There are situations where I'd like to down all projects and this requires access to all project names in a machine readable format.
Given that several docker CLI/compose commands provide templating capabilities with the --format flag I'd expect to solve this with:

docker compose ls --format '{{.Name}}' | xargs -I{} docker compose -p {} down 

But docker compose ls --format <format> only offers json or table format therefore it's only possible to get project names using external applications.

If using table format you'd have to hack a shell pipeline.

docker compose ls | tail -n +2 | awk '{print $1}' | xargs -I{} docker compose -p {} down 

If using json format, even though json is machine readable, it requires you to pipe to a parser, such as jq, which very likely it's not available.

docker compose ls --format json | jq '.[].Name' | xargs -I{} docker compose -p {} down

The docker CLI and compose already provide GO Templates formatting for several commands such as:

  • docker ps --format <TEMPLATE>
  • docker images --format <TEMPLATE>
  • docker stats --format <TEMPLATE>
  • docker compose ps --format <TEMPLATE>

The list goes on.

In compose there is compose images and compose ls which not only are not able to handle Templates but they also print JSON in a different way than the ones that support Templates.
The commands that have support print each object as a separate JSON in a different line, while the ones that don't print a JSON list in a single line:

docker images --format json
# {"Containers":"N/A","CreatedAt":"2014-07-19 04:02:32 -0300 -03","CreatedSince":"10 years ago","Digest":"\u003cnone\u003e","ID":"350b164e7ae1","Repository":"gcr.io/google-containers/pause","SharedSize":"N/A","Size":"240kB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"239.8kB"}
# {"Containers":"N/A","CreatedAt":"1979-12-31 21:00:00 -0300 -03","CreatedSince":"45 years ago","Digest":"\u003cnone\u003e","ID":"f576b2d0af25","Repository":"test","SharedSize":"N/A","Size":"2.06GB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"2.056GB"}


docker compose images --format json
# [{"ID":"sha256:350b164e7ae1dcddeffadd65c76226c9b6dc5553f5179153fb0e36b78f2a5e06","ContainerName":"test_1-compose_test-1","Repository":"gcr.io/google-containers/pause","Tag":"latest","Size":239840,"LastTagTime":"0001-01-01T00:00:00Z"},{"ID":"sha256:350b164e7ae1dcddeffadd65c76226c9b6dc5553f5179153fb0e36b78f2a5e06","ContainerName":"test_1-compose_test_2-1","Repository":"gcr.io/google-containers/pause","Tag":"latest","Size":239840,"LastTagTime":"0001-01-01T00:00:00Z"}]

Implementing templating capabilities for these commands would change the output format but only to conform with already existing behavior.

Lingua principale
Go
Stelle
38.9k
Fork
6k
Merge medio
2g 22h
PR unite (30g)
81

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docker/compose

Tutte le issue di docker/compose

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.