|
| 1 | +FROM golang:1.9.3-alpine as build |
| 2 | +MAINTAINER Andrew Kutz < [email protected]> |
| 3 | + |
| 4 | +# The versions of the software used in the build image. Please note |
| 5 | +# that the version of the protobuf Go packages and their transitive |
| 6 | +# dependencies are defined in the local files lib/go/Gopkg.toml and |
| 7 | +# lib/go/Gopkg.lock. |
| 8 | +ENV PROTOC_VER 3.5.1 |
| 9 | +ENV DEP_VER 0.4.1 |
| 10 | + |
| 11 | +ENV PKGPATH ${GOPATH}/src/csi |
| 12 | +RUN mkdir -p ${PKGPATH} |
| 13 | +WORKDIR ${PKGPATH} |
| 14 | + |
| 15 | +# Update the package cache and install the required tools. |
| 16 | +RUN apk update && apk add unzip curl git |
| 17 | + |
| 18 | +# Download protoc. |
| 19 | +ENV PROTOC_ZIP protoc-$PROTOC_VER-linux-x86_64.zip |
| 20 | +ENV PROTOC_BIN bin/protoc |
| 21 | +RUN curl -LO https://github.com/google/protobuf/releases/download/v${PROTOC_VER}/${PROTOC_ZIP} && \ |
| 22 | + unzip ${PROTOC_ZIP} && \ |
| 23 | + chmod 0755 ${PROTOC_BIN} && \ |
| 24 | + mv ${PROTOC_BIN} /usr/local/bin |
| 25 | + |
| 26 | +# Download dep. |
| 27 | +ENV DEP_BIN dep-linux-amd64 |
| 28 | +RUN curl -LO https://github.com/golang/dep/releases/download/v${DEP_VER}/${DEP_BIN} && \ |
| 29 | + chmod 0755 ${DEP_BIN} && \ |
| 30 | + mv ${DEP_BIN} /usr/local/bin/dep |
| 31 | + |
| 32 | +# Copy the Go source file, dependency manifest, and lock file into the image. |
| 33 | +COPY lib/go/csi.go . |
| 34 | +COPY lib/go/Gopkg.toml . |
| 35 | +COPY lib/go/Gopkg.lock . |
| 36 | + |
| 37 | +# Download the Go dependencies. |
| 38 | +RUN dep ensure -v |
| 39 | + |
| 40 | +# Build the protogen-go binary. |
| 41 | +ENV PROTOC_GEN_GO_BIN protoc-gen-go |
| 42 | +RUN go build -o /usr/local/bin/${PROTOC_GEN_GO_BIN} ./vendor/github.com/golang/protobuf/protoc-gen-go |
| 43 | + |
| 44 | +# Start the second build stage. |
| 45 | +FROM alpine:3.7 |
| 46 | +RUN mkdir -p /csi |
| 47 | +WORKDIR /csi |
| 48 | + |
| 49 | +# The versions of the software used in the primary image. |
| 50 | +ENV GLIBC_VERSION 2.26-r0 |
| 51 | + |
| 52 | +# Download and install glibc. |
| 53 | +# This step is credited to https://github.com/jeanblanchard/docker-alpine-glibc. |
| 54 | +RUN apk update && apk add curl |
| 55 | +RUN curl -Lo /etc/apk/keys/sgerrand.rsa.pub https://github.com/raw/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \ |
| 56 | + curl -Lo glibc.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" && \ |
| 57 | + curl -Lo glibc-bin.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" && \ |
| 58 | + apk add glibc-bin.apk glibc.apk && \ |
| 59 | + /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \ |
| 60 | + echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf |
| 61 | + |
| 62 | +# Copy the protoc and protoc-gen-go binaries from the build image. |
| 63 | +COPY --from=build /usr/local/bin/protoc* /usr/local/bin/ |
| 64 | + |
| 65 | +# Copy the entrypoint script from the local lib/go directory. |
| 66 | +COPY lib/go/spec.sh . |
| 67 | +RUN chmod 0755 spec.sh |
| 68 | + |
| 69 | +ENTRYPOINT [ "./spec.sh" ] |
0 commit comments