Skip to content

Commit 5460fc5

Browse files
committed
Init
Signed-off-by: Paweł Gronowski <[email protected]>
0 parents  commit 5460fc5

File tree

16 files changed

+783
-0
lines changed

16 files changed

+783
-0
lines changed

.demo.gif

164 KB
Loading

.devcontainer/devcontainer.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"build": {
3+
"context": "..",
4+
"dockerfile": "../Dockerfile",
5+
"target": "devcontainer"
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"golang.go"
11+
]
12+
}
13+
}
14+
}

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.21-bullseye AS base
2+
3+
FROM base as build
4+
5+
WORKDIR /go/src
6+
7+
COPY go.mod go.sum ./
8+
RUN --mount=type=bind,src=./go.mod,target=./go.mod \
9+
--mount=type=bind,src=./go.sum,target=./go.sum \
10+
go mod download
11+
12+
ARG TARGETOS
13+
ARG TARGETARCH
14+
RUN --mount=type=bind,target=/go/src \
15+
--mount=type=cache,target=/root/.cache/go-build \
16+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /binary ./cmd/edit
17+
18+
19+
FROM base AS gopls
20+
RUN --mount=type=cache,target=/root/.cache/go-build \
21+
--mount=type=cache,target=/go/pkg/mod \
22+
GOBIN=/build/ GO111MODULE=on go install "golang.org/x/tools/gopls@latest" \
23+
&& /build/gopls version
24+
25+
26+
FROM base as devcontainer
27+
COPY --from=gopls /build/gopls /usr/local/bin/gopls
28+
29+
30+
FROM scratch AS binary
31+
COPY --from=build /binary /docker-edit

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: binary
2+
.PHONY: vendor
3+
4+
binary:
5+
docker buildx build . -o type=local,dest=bin
6+
7+
install: binary
8+
cp bin/docker-edit ~/.docker/cli-plugins/docker-edit
9+
10+
vendor:
11+
docker run --init -it --rm \
12+
-v docker-plugin-edit-cache:/root/.cache \
13+
-v ./:/proj -w /proj \
14+
$(shell docker buildx build . -q --target base) \
15+
go mod tidy

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# docker edit <volume> <file-path>
2+
3+
`sudoedit` but for files in Docker volumes.
4+
5+
## Installation
6+
7+
```shell
8+
$ echo "FROM vlnd/docker-edit" | docker buildx build - -o type=local,dest=$HOME/.docker/cli-plugins --pull
9+
```
10+
11+
## Usage
12+
13+
```shell
14+
$ docker edit <volume> <file-path-in-volume>
15+
```
16+
17+
## Building
18+
19+
```shell
20+
$ make # Build bin/docker-edit binary
21+
$ make install # Install binary to ~/.docker/cli-plugins
22+
```
23+
24+
## Demo
25+
26+
![demo](https://raw.githubusercontent.com/vvoland/docker-plugin-edit/master/.demo.gif)

cmd/edit/edit.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"github.com/docker/cli/cli-plugins/manager"
5+
"github.com/docker/cli/cli-plugins/plugin"
6+
"github.com/docker/cli/cli/command"
7+
"github.com/spf13/cobra"
8+
"github.com/vvoland/docker-plugin-edit/internal/app"
9+
)
10+
11+
func Command(dockerCli command.Cli) *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "edit <volume> <file>",
14+
Short: "Edit a text file inside a named volume",
15+
Args: cobra.ExactArgs(2),
16+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
17+
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
18+
return err
19+
}
20+
return nil
21+
},
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
ctx := cmd.Context()
24+
volumeName := args[0]
25+
path := args[1]
26+
27+
return app.Edit(ctx, dockerCli, volumeName, path)
28+
},
29+
}
30+
31+
return cmd
32+
}
33+
34+
func main() {
35+
plugin.Run(Command, manager.Metadata{
36+
SchemaVersion: "0.1.0",
37+
Vendor: "Paweł Gronowski",
38+
Version: "0.1.0",
39+
})
40+
}

docker-bake.hcl

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
group "default" {
2+
targets = ["bin-image-all"]
3+
}
4+
5+
target "bin-image" {
6+
type = "image"
7+
platform = "local"
8+
tags = ["vlnd/docker-edit"]
9+
}
10+
11+
target "bin-image-all" {
12+
inherits = ["bin-image"]
13+
platforms = [
14+
"linux/amd64",
15+
"linux/arm64",
16+
"darwin/amd64",
17+
"darwin/arm64",
18+
"windows/arm64",
19+
"windows/amd64"
20+
]
21+
}

go.mod

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module github.com/vvoland/docker-plugin-edit
2+
3+
go 1.21
4+
5+
require (
6+
github.com/docker/cli v25.0.3+incompatible
7+
github.com/docker/docker v25.0.3+incompatible
8+
github.com/spf13/cobra v1.8.0
9+
)
10+
11+
require (
12+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
13+
github.com/Microsoft/go-winio v0.4.14 // indirect
14+
github.com/beorn7/perks v0.0.0-20150223135152-b965b613227f // indirect
15+
github.com/containerd/log v0.1.0 // indirect
16+
github.com/distribution/reference v0.5.0 // indirect
17+
github.com/docker/distribution v2.8.3+incompatible // indirect
18+
github.com/docker/docker-credential-helpers v0.8.1 // indirect
19+
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect
20+
github.com/docker/go-connections v0.5.0 // indirect
21+
github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916 // indirect
22+
github.com/docker/go-units v0.5.0 // indirect
23+
github.com/felixge/httpsnoop v1.0.4 // indirect
24+
github.com/fvbommel/sortorder v1.1.0 // indirect
25+
github.com/go-logr/logr v1.4.1 // indirect
26+
github.com/go-logr/stdr v1.2.2 // indirect
27+
github.com/gogo/protobuf v1.3.2 // indirect
28+
github.com/golang/protobuf v1.5.3 // indirect
29+
github.com/gorilla/mux v1.7.0 // indirect
30+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
31+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
32+
github.com/miekg/pkcs11 v1.0.2 // indirect
33+
github.com/moby/sys/sequential v0.5.0 // indirect
34+
github.com/moby/term v0.5.0 // indirect
35+
github.com/morikuni/aec v1.0.0 // indirect
36+
github.com/opencontainers/go-digest v1.0.0 // indirect
37+
github.com/opencontainers/image-spec v1.1.0 // indirect
38+
github.com/pkg/errors v0.9.1 // indirect
39+
github.com/prometheus/client_golang v0.9.0-pre1.0.20180209125602-c332b6f63c06 // indirect
40+
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 // indirect
41+
github.com/prometheus/common v0.0.0-20180110214958-89604d197083 // indirect
42+
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7 // indirect
43+
github.com/sirupsen/logrus v1.9.3 // indirect
44+
github.com/spf13/pflag v1.0.5 // indirect
45+
github.com/theupdateframework/notary v0.7.0 // indirect
46+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
47+
go.opentelemetry.io/otel v1.23.1 // indirect
48+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.1 // indirect
49+
go.opentelemetry.io/otel/metric v1.23.1 // indirect
50+
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
51+
go.opentelemetry.io/otel/trace v1.23.1 // indirect
52+
golang.org/x/crypto v0.16.0 // indirect
53+
golang.org/x/net v0.19.0 // indirect
54+
golang.org/x/sync v0.6.0 // indirect
55+
golang.org/x/sys v0.16.0 // indirect
56+
golang.org/x/term v0.15.0 // indirect
57+
golang.org/x/time v0.5.0 // indirect
58+
google.golang.org/protobuf v1.32.0 // indirect
59+
gotest.tools/v3 v3.5.1 // indirect
60+
)

0 commit comments

Comments
 (0)