diff --git a/Dockerfile-go b/Dockerfile-go new file mode 100644 index 00000000..822419a0 --- /dev/null +++ b/Dockerfile-go @@ -0,0 +1,69 @@ +FROM golang:1.9.3-alpine as build +MAINTAINER Andrew Kutz + +# 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://raw.githubusercontent.com/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" ] diff --git a/lib/go/Gopkg.lock b/lib/go/Gopkg.lock new file mode 100644 index 00000000..2740cc2a --- /dev/null +++ b/lib/go/Gopkg.lock @@ -0,0 +1,39 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/golang/protobuf" + packages = ["proto","protoc-gen-go","protoc-gen-go/descriptor","protoc-gen-go/generator","protoc-gen-go/grpc","protoc-gen-go/plugin","ptypes","ptypes/any","ptypes/duration","ptypes/timestamp"] + revision = "ae59567b9aab61b50b2590679a62c3c044030b61" + +[[projects]] + branch = "master" + name = "golang.org/x/net" + packages = ["context","http2","http2/hpack","idna","internal/timeseries","lex/httplex","trace"] + revision = "8351a756f30f1297fe94bbf4b767ec589c6ea6d0" + +[[projects]] + branch = "master" + name = "golang.org/x/text" + packages = ["collate","collate/build","internal/colltab","internal/gen","internal/tag","internal/triegen","internal/ucd","language","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable"] + revision = "1cbadb444a806fd9430d14ad08967ed91da4fa0a" + +[[projects]] + branch = "master" + name = "google.golang.org/genproto" + packages = ["googleapis/rpc/status"] + revision = "1e559d0a00eef8a9a43151db4665280bd8dd5886" + +[[projects]] + name = "google.golang.org/grpc" + packages = [".","codes","connectivity","credentials","grpclb/grpc_lb_v1/messages","grpclog","internal","keepalive","metadata","naming","peer","stats","status","tap","transport"] + revision = "f92cdcd7dcdc69e81b2d7b338479a19a8723cfa3" + version = "v1.6.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "f18038d4a1dd1fc54b0a56880e928dea2081cacd7ab26089cec72462ee2e4c94" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/lib/go/Gopkg.toml b/lib/go/Gopkg.toml new file mode 100644 index 00000000..c4fccb69 --- /dev/null +++ b/lib/go/Gopkg.toml @@ -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" diff --git a/lib/go/spec.sh b/lib/go/spec.sh new file mode 100755 index 00000000..0eb75f90 --- /dev/null +++ b/lib/go/spec.sh @@ -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 + 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