Skip to content

Generating Go Bindings with Docker #181

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

Closed

Conversation

akutz
Copy link
Contributor

@akutz akutz commented Feb 1, 2018

This patch replaces #180 and introduces the ability to generate Go language bindings using Docker with Dockerfile-go and a spec file provided at runtime:

# builds the container image
$ docker build -t csi/golang -f Dockerfile-go .

# emits the go bindings to stdout
$ cat spec.md | docker run --rm -i csi/golang

Error Handling

If the image is run without content available on STDIN then the following error is emitted:

$ docker run csi/golang
usage: cat spec.md | docker run --rm -i golang/csi

$ docker run -i csi/golang
usage: cat spec.md | docker run --rm -i golang/csi

Emit the Protobuf

The image can also be used to emit the generated protobufs as well, just add the token proto at the end of the command used to generate the Go bindings:

# emits the protobuf to stdout
$ cat spec.md | docker run --rm -i csi/golang proto

Image Size

Due to the usage of build stages, the size of the final image is only 25MB!

$ docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED              SIZE
csi/golang                         latest              bfe16b5e4bb4        About a minute ago   25MB

Docker Hub (akutz/csi-golang)

As I lack the ability to push to the Docker hub for the csi organization, I've pushed the image to the Docker hub as akutz/csi-golang. Please give it a whirl!

$ cat spec.md | docker run --rm -i akutz/csi-golang
Unable to find image 'akutz/csi-golang:latest' locally
latest: Pulling from akutz/csi-golang
ff3a5c916c92: Already exists 
f9fb51a84b3e: Pull complete 
9e169ec17526: Pull complete 
0aaec76a3e6b: Pull complete 
6182241d2b25: Pull complete 
b7d1cfe2d7c2: Pull complete 
Digest: sha256:7291fee5b3169be78ce9de02cc45334100f2958f6fc279d1e61e7172ee846a46
Status: Downloaded newer image for akutz/csi-golang:latest
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: csi.proto

/*
Package csi is a generated protocol buffer package.

It is generated from these files:
	csi.proto

...

cc @saad-ali @cpuguy83

@lpabon
Copy link

lpabon commented Feb 1, 2018

Does it take the spec.md (markdown) and spit out the proto file? If it does, that is super cool

@akutz
Copy link
Contributor Author

akutz commented Feb 1, 2018

No, it spits out the Go bindings. I can enhance it to spit out various pieces depending on flags, but by default, since it’s named “csi/golang”, it emits the Go bindings.

FWIW, the PR States it emits the Go bindings.

@lpabon
Copy link

lpabon commented Feb 1, 2018

Sorry, yeah, i meant go bindings.

This patch introduces the ability to generate Go language bindings using
Docker with `Dockerfile-go` and a spec file provided at runtime:

        # builds the container image
        $ docker build -t csi/golang -f Dockerfile-go .

        # emits the go bindings to stdout
        $ cat spec.md | docker run -i csi/golang

If the image is run without content available on STDIN then the
following error is emitted.

        $ docker run csi/golang
        usage: cat spec.md | docker run -i golang/csi

        $ docker run -i csi/golang
        usage: cat spec.md | docker run -i golang/csi

The image can also be used to emit the generated protobuf instead of the
golang bindings:

        # emits the protobuf to stdout
        $ cat spec.md | docker run -i csi/golang proto
@akutz akutz force-pushed the feature/dockerfile-go2 branch from 81fc48a to 1f2440e Compare February 1, 2018 01:38
@akutz
Copy link
Contributor Author

akutz commented Feb 1, 2018

Ha! I'm glad you mistyped it, because I just rebased this PR and now it can emit the protobuf as well, just add the command proto at the end :)

cat spec.md | docker run -i csi/golang proto

@akutz
Copy link
Contributor Author

akutz commented Feb 1, 2018

Hi @saad-ali,

Would you, @jieyu, @julian-hj, and @cpuguy83 please review and approve (or not) this PR? Even if it's not yet in the build pipeline, this PR provides a very simple, standard way for people to generate the bindings locally.

@akutz akutz mentioned this pull request Feb 9, 2018
exit 1
fi

while IFS= read -r line; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we replace this while loop with a simple cat >> csi.spec?

@@ -0,0 +1,69 @@
FROM golang:1.9.3-alpine as build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this dockerfile at the root of the repo, instead of in the lib/go subtree?

@jdef jdef added the lifecycle/stale PR has been inactive for 90+ days. label Oct 4, 2018
@saad-ali
Copy link
Member

saad-ali commented Nov 7, 2018

@saad-ali saad-ali added lifecycle/rotten Stale PR has been inactive for 30+ days. and removed lifecycle/stale PR has been inactive for 90+ days. labels Nov 7, 2018
@saad-ali
Copy link
Member

saad-ali commented Nov 7, 2018

We should do this at some point though.

@saad-ali
Copy link
Member

saad-ali commented Mar 6, 2019

@saad-ali saad-ali closed this Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Stale PR has been inactive for 30+ days.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants