-
Notifications
You must be signed in to change notification settings - Fork 378
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
akutz
wants to merge
1
commit into
container-storage-interface:master
from
akutz:feature/dockerfile-go2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
FROM golang:1.9.3-alpine as build | ||
MAINTAINER Andrew Kutz <[email protected]> | ||
|
||
# The versions of the software used in the build image. Please note | ||
# that the version of the protobuf Go packages and their transitive | ||
# dependencies are defined in the local files lib/go/Gopkg.toml and | ||
# lib/go/Gopkg.lock. | ||
ENV PROTOC_VER 3.5.1 | ||
ENV DEP_VER 0.4.1 | ||
|
||
ENV PKGPATH ${GOPATH}/src/csi | ||
RUN mkdir -p ${PKGPATH} | ||
WORKDIR ${PKGPATH} | ||
|
||
# Update the package cache and install the required tools. | ||
RUN apk update && apk add unzip curl git | ||
|
||
# Download protoc. | ||
ENV PROTOC_ZIP protoc-$PROTOC_VER-linux-x86_64.zip | ||
ENV PROTOC_BIN bin/protoc | ||
RUN curl -LO https://github.com/google/protobuf/releases/download/v${PROTOC_VER}/${PROTOC_ZIP} && \ | ||
unzip ${PROTOC_ZIP} && \ | ||
chmod 0755 ${PROTOC_BIN} && \ | ||
mv ${PROTOC_BIN} /usr/local/bin | ||
|
||
# Download dep. | ||
ENV DEP_BIN dep-linux-amd64 | ||
RUN curl -LO https://github.com/golang/dep/releases/download/v${DEP_VER}/${DEP_BIN} && \ | ||
chmod 0755 ${DEP_BIN} && \ | ||
mv ${DEP_BIN} /usr/local/bin/dep | ||
|
||
# Copy the Go source file, dependency manifest, and lock file into the image. | ||
COPY lib/go/csi.go . | ||
COPY lib/go/Gopkg.toml . | ||
COPY lib/go/Gopkg.lock . | ||
|
||
# Download the Go dependencies. | ||
RUN dep ensure -v | ||
|
||
# Build the protogen-go binary. | ||
ENV PROTOC_GEN_GO_BIN protoc-gen-go | ||
RUN go build -o /usr/local/bin/${PROTOC_GEN_GO_BIN} ./vendor/github.com/golang/protobuf/protoc-gen-go | ||
|
||
# Start the second build stage. | ||
FROM alpine:3.7 | ||
RUN mkdir -p /csi | ||
WORKDIR /csi | ||
|
||
# The versions of the software used in the primary image. | ||
ENV GLIBC_VERSION 2.26-r0 | ||
|
||
# Download and install glibc. | ||
# This step is credited to https://github.com/jeanblanchard/docker-alpine-glibc. | ||
RUN apk update && apk add curl | ||
RUN curl -Lo /etc/apk/keys/sgerrand.rsa.pub https://github.com/raw/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \ | ||
curl -Lo glibc.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" && \ | ||
curl -Lo glibc-bin.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" && \ | ||
apk add glibc-bin.apk glibc.apk && \ | ||
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \ | ||
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf | ||
|
||
# Copy the protoc and protoc-gen-go binaries from the build image. | ||
COPY --from=build /usr/local/bin/protoc* /usr/local/bin/ | ||
|
||
# Copy the entrypoint script from the local lib/go directory. | ||
COPY lib/go/spec.sh . | ||
RUN chmod 0755 spec.sh | ||
|
||
ENTRYPOINT [ "./spec.sh" ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# Refer to https://github.com/toml-lang/toml for detailed TOML docs. | ||
|
||
# The following packages are required because they're either build | ||
# tools or are dependencies only if the "csi" package is already | ||
# generated. However, if the "csi" package is removed (a valid | ||
# condition), a "dep ensure" will not fetch the dependencies it | ||
# no longer sees in the project's dependency graph. Including the | ||
# dependencies in the "required" list ensures they're always | ||
# downloaded. | ||
required = [ | ||
"github.com/golang/protobuf/protoc-gen-go", | ||
"golang.org/x/net/context", | ||
"google.golang.org/grpc" | ||
] | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/golang/protobuf" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "golang.org/x/net" | ||
|
||
[[constraint]] | ||
name = "google.golang.org/grpc" | ||
version = "1.6.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
|
||
# Check to see if there is any content in STDIN. If nothing is read | ||
# after 1 second, then exit with an error. | ||
if IFS= read -rt 1 line; then | ||
echo "$line" > csi.spec | ||
else | ||
echo "usage: cat spec.md | docker run -i golang/csi" | ||
exit 1 | ||
fi | ||
|
||
while IFS= read -r line; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we replace this |
||
echo "$line" >> csi.spec | ||
done | ||
|
||
sed -ne '/```protobuf$/,/```$/ p' < csi.spec | \ | ||
sed -e 's@^```.*$@////////@g' > csi.proto | ||
|
||
if [ "$1" = "proto" ]; then | ||
cat csi.proto | ||
else | ||
protoc -I . --go_out=plugins=grpc:. csi.proto | ||
cat csi.pb.go | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?