Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bintool: add constructor for docker-based tools #7

Open
aexvir opened this issue May 24, 2022 · 1 comment
Open

bintool: add constructor for docker-based tools #7

aexvir opened this issue May 24, 2022 · 1 comment

Comments

@aexvir
Copy link

aexvir commented May 24, 2022

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

@aexvir
Copy link
Author

aexvir commented May 24, 2022

note: I'm already achieving this more or less by running docker commands with shellcmd, but it feels hacky and clunky having to manually generate those commands; and by natively supporting docker as bin source and leveraging docker sdk I can imagine adding additional capabilities in the future, by exec-ing into the container and running more commands, or by reusing containers between tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant