-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0719aff
Showing
11 changed files
with
954 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
docker-tree | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
VERSION := 0.0.1 | ||
|
||
build: test | ||
go build -ldflags="-X 'main.version=$(VERSION)'" -o docker-tree ./cmd/ | ||
|
||
test: | ||
go vet ./... | ||
go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# docker-tree | ||
|
||
[//]: # ([![GitHub release](https://img.shields.io/github/release/sergkondr/docker-tree.svg)](https://github.com/sergkondr/docker-tree/releases/latest)) | ||
[//]: # ([![Go Report Card](https://goreportcard.com/badge/github.com/sergkondr/docker-tree)](https://goreportcard.com/report/github.com/sergkondr/docker-tree)) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT%202.0-blue.svg)](https://github.com/wagoodman/dive/blob/main/LICENSE) | ||
|
||
This command shows the directory tree of a Docker image, like the 'tree' command. | ||
Provide the image name and an optional tag or digest to view the file structure inside the image. | ||
You can also specify a directory to see the file tree relative to this directory. | ||
|
||
This is not a replacement for the amazing [Dive](https://github.com/wagoodman/dive) utility, but it works as a Docker plugin, so you might find it simpler and more convenient | ||
Think of this app mainly as an attempt to understand how Docker images work and how to create Docker plugins. However, it does work, and I hope you find it useful. | ||
|
||
### Install | ||
``` | ||
cp ./docker-tree ~/.docker/cli-plugins/docker-tree | ||
``` | ||
|
||
### Usage | ||
```shell | ||
➜ docker tree alpine:3.20 /etc/ssl | ||
3.20: Pulling from library/alpine | ||
a258b2a6b59a: Pull complete | ||
Digest: sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 | ||
Status: Downloaded newer image for alpine:3.20 | ||
docker.io/library/alpine:3.20 | ||
ssl/ | ||
├── cert.pem | ||
├── certs/ | ||
│ └── ca-certificates.crt | ||
├── ct_log_list.cnf | ||
├── ct_log_list.cnf.dist | ||
├── openssl.cnf | ||
├── openssl.cnf.dist | ||
└── private/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/skondrashov/docker-tree/internal/docker" | ||
|
||
"github.com/docker/cli/cli-plugins/manager" | ||
"github.com/docker/cli/cli-plugins/plugin" | ||
"github.com/docker/cli/cli/command" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
version string | ||
) | ||
|
||
func main() { | ||
plugin.Run( | ||
func(dockerCli command.Cli) *cobra.Command { | ||
var ( | ||
quiet bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "tree NAME[:TAG|@DIGEST] [DIRECTORY]", | ||
Short: "Display the directory tree of a Docker image", | ||
Long: `This command displays the directory tree of a Docker image, similar to the 'tree' command. | ||
Provide the image name and an optional tag or digest to view the file structure within the image. | ||
You can also specify a directory to see the file tree relative to this directory.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 || len(args) > 2 { | ||
fmt.Fprintln(dockerCli.Out(), cmd.UsageString()) | ||
os.Exit(0) | ||
} | ||
|
||
imageID := args[0] | ||
if imageID == "" { | ||
fmt.Fprintln(dockerCli.Out(), "no imageID provided") | ||
os.Exit(1) | ||
} | ||
|
||
treeRoot := "/" | ||
if len(args) == 2 && args[1] != "" { | ||
treeRoot = args[1] | ||
} | ||
|
||
treeStrings, err := docker.GetImageTree(docker.GetTreeOpts{ | ||
Cli: dockerCli, | ||
ImageID: imageID, | ||
Quiet: quiet, | ||
TreeRoot: treeRoot, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(dockerCli.Err(), "can't get image tree: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Fprintf(dockerCli.Out(), "%s", treeStrings) | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.BoolVarP(&quiet, "quiet", "q", false, "Suppress verbose output") | ||
|
||
cmd.AddCommand() | ||
return cmd | ||
}, | ||
|
||
manager.Metadata{ | ||
SchemaVersion: "0.1.0", | ||
Vendor: "Sergei Kondrashov", | ||
Version: version, | ||
ShortDescription: "Docker image tree", | ||
URL: "https://github.com/sergkondr/docker-tree", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module github.com/skondrashov/docker-tree | ||
|
||
go 1.22.1 | ||
|
||
require ( | ||
github.com/docker/cli v27.0.3+incompatible | ||
github.com/docker/docker v27.0.3+incompatible | ||
github.com/spf13/cobra v1.8.1 | ||
) | ||
|
||
require ( | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.4.14 // indirect | ||
github.com/beorn7/perks v0.0.0-20150223135152-b965b613227f // indirect | ||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||
github.com/containerd/log v0.1.0 // indirect | ||
github.com/distribution/reference v0.6.0 // indirect | ||
github.com/docker/distribution v2.8.3+incompatible // indirect | ||
github.com/docker/docker-credential-helpers v0.8.2 // indirect | ||
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect | ||
github.com/docker/go-connections v0.5.0 // indirect | ||
github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/felixge/httpsnoop v1.0.4 // indirect | ||
github.com/fvbommel/sortorder v1.1.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.4 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/gorilla/mux v1.7.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/miekg/pkcs11 v1.0.2 // indirect | ||
github.com/moby/docker-image-spec v1.3.1 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v0.9.0-pre1.0.20180209125602-c332b6f63c06 // indirect | ||
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 // indirect | ||
github.com/prometheus/common v0.0.0-20180110214958-89604d197083 // indirect | ||
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/theupdateframework/notary v0.7.0 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect | ||
go.opentelemetry.io/otel v1.28.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.28.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.28.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.28.0 // indirect | ||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect | ||
golang.org/x/crypto v0.24.0 // indirect | ||
golang.org/x/net v0.26.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.22.0 // indirect | ||
golang.org/x/term v0.21.0 // indirect | ||
golang.org/x/text v0.16.0 // indirect | ||
golang.org/x/time v0.5.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect | ||
google.golang.org/grpc v1.64.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gotest.tools/v3 v3.5.1 // indirect | ||
) |
Oops, something went wrong.