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

proposal: cmd/go: build: add -container flag #26657

Closed
tamalsaha opened this issue Jul 28, 2018 · 5 comments
Closed

proposal: cmd/go: build: add -container flag #26657

tamalsaha opened this issue Jul 28, 2018 · 5 comments

Comments

@tamalsaha
Copy link

tamalsaha commented Jul 28, 2018

This is a proposal to add -container flag to go build.

We use Go to write our cloud native applications. Most of the time, we don't use the binary itself directly. Rather we turn that into a Docker image using alpine or busybox as the From image. This flag will allow Go developers to produce a Docker image for Go applications in most simple cases. The example command could look like this:

go build -o mycompany/myapp:v1 -container busybox ./...

It is now possible to build Docker images (which are just tar files for most part) without needing any Docker daemon thanks to Buildkit and @jessfraz's img project.

cc: @AkihiroSuda

@gopherbot gopherbot added this to the Proposal milestone Jul 28, 2018
@AkihiroSuda
Copy link
Contributor

IIUC this is only for static binaries?

BTW, have you looked into ko? Although it depends on Kube: https://github.com/google/go-containerregistry/tree/master/cmd/ko

@tamalsaha
Copy link
Author

IIUC this is only for static binaries?

We mostly use static binaries. But is that necessary?

I have not looked into ko before. I don't think anyone wants Kubernetes dependency for building OCI images.

@AkihiroSuda
Copy link
Contributor

For dynamic binaries you are likely to require a bunch of apt/dnf packages, and probably it is better to use Docker/BuildKit/img/Buildah/whatever?

@mvdan
Copy link
Member

mvdan commented Jul 28, 2018

Is the purpose here to build Go binaries that are runnable on certain container environments, or to build the container image too?

If you want the former, I presume that the already accepted #26492 will do the job.

If you want the latter, I'd imagine that the solution would pull in lots of code into the Go tree. Why not have that as a build/release tool that wraps go build instead?

@rsc
Copy link
Contributor

rsc commented Aug 6, 2018

The go command and the go project cannot serve every possible need. Instead we aim to provide a good foundation and good building blocks for custom tooling. It should be very easy to write a go-to-docker given the current go command functionality. And maybe -static in #26492 will make it even easier. A docker container can be and is often a lot more than one binary. It makes much more sense for additional tools layered on top of the go command to build those containers. If more from the go command is needed, great, let us know details. But broader packaging issues like generating docker containers directly is far beyond the go command's scope.

@rsc rsc closed this as completed Aug 6, 2018
@golang golang locked and limited conversation to collaborators Aug 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants