Skip to content

bintool: add constructor for docker-based tools #7

@aexvir

Description

@aexvir

first of all, mage + bintool is a really refreshing combo, thanks for developing this package

binaries are amazing because of how portable they are, but unfortunately not all linters are developed in languages that can compile to a self-contained binary, like markdownlint or yamllint; which require their own runtime, js and python to be available

while there might be some alternatives to those linters, written in languages able to output a binary, that's not always the case nor the solution, as those two linters are very mature and well recognized, and it's a shame to have to give up on that

docker containers help solving this issue, as it packs all the required runtime and dependencies into a single image that's able to run pretty much anywhere, and it would be really nice if we could leverage bintool for this, via a new constructor similar to how the go package constructor works right now

func Lint(ctx context.Context) error {
	mdl, _ := bintool.NewDocker(
		"ghcr.io/igorshubovych/markdownlint-cli", // image
		"0.31.1", // tag
		bintool.WithVolume(
			os.Getwd(), // host path
			"/src", // container path
		),
		bintool.WithEntrypoint("sh"),
		bintool.WithRemove(true),
	)
	mdl.Ensure()

	return mdl.Command("markdownlint-cli /src").Run()
}

which would be equivalent to

docker run --rm -v /.../whatever:/src --entrypoint sh ghcr.io/igorshubovych/markdownlint-cli:0.31.1 markdownlint-cli /src

and this could be used for other things than linting, e.g. spinning up a db to use as test target before calling go test on some test target in the magefile; or using some python cli for uploading artifacts to some bucket as part of some lint target.

would you be up for having this functionality on the package?
I'd be up for giving a try to implement it and submitting a pr if noone else picks it up first

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions