|
1 | | -# The docker image to generate Golang code from Protocol Buffers. |
2 | | -FROM golang:1.21-alpine3.19 AS builder |
| 1 | +# The docker image to generate Golang code from Protol Buffer. |
| 2 | +FROM golang:1.17.0-alpine3.14 as builder |
3 | 3 | LABEL intermediate=true |
| 4 | +MAINTAINER DL NGP-App-Infra-API <ngp-app-infra-api@infoblox.com> |
4 | 5 |
|
| 6 | +ARG AAT_VERSION=master |
| 7 | +ARG PGG_VERSION=v0.20.4 |
| 8 | +ARG PGAQV_VERSION=master |
| 9 | +ARG PGAV_VERSION=master |
| 10 | +ARG PGP_VERSION=master |
| 11 | + |
| 12 | +# Set up mandatory Go environmental variables. |
5 | 13 | ENV CGO_ENABLED=0 |
6 | | -ENV GOPATH=/go |
| 14 | +ENV GO111MODULE=off |
7 | 15 |
|
8 | 16 | RUN apk update \ |
9 | 17 | && apk add --no-cache --purge git curl upx |
10 | 18 |
|
11 | | -# Clone all dependencies into GOPATH/src (replicating the old glide layout) |
12 | | -# This ensures proto files end up in the right place for protoc -I paths. |
13 | | -WORKDIR ${GOPATH}/src |
14 | | - |
15 | | -# Standard proto / gogo |
16 | | -RUN git clone --depth 1 --branch v1.3.1 https://github.com/golang/protobuf.git github.com/golang/protobuf && \ |
17 | | - git clone --depth 1 --branch v1.0.0 https://github.com/gogo/protobuf.git github.com/gogo/protobuf && \ |
18 | | - git clone --depth 1 https://github.com/google/protobuf.git github.com/google/protobuf |
19 | | - |
20 | | -# grpc-gateway (upstream for protoc-gen-grpc-gateway) |
21 | | -RUN git clone --depth 1 --branch v1.14.8 https://github.com/grpc-ecosystem/grpc-gateway.git github.com/grpc-ecosystem/grpc-gateway |
22 | | - |
23 | | -# googleapis |
24 | | -RUN git clone --depth 1 --branch master https://github.com/googleapis/googleapis.git github.com/googleapis/googleapis |
25 | | - |
26 | | -# Validators |
27 | | -RUN git clone --depth 1 --branch v0.1.0 https://github.com/envoyproxy/protoc-gen-validate.git github.com/envoyproxy/protoc-gen-validate && \ |
28 | | - git clone --depth 1 https://github.com/mwitkow/go-proto-validators.git github.com/mwitkow/go-proto-validators |
29 | | - |
30 | | -# Documentation generator |
31 | | -RUN git clone --depth 1 --branch v1.0.0 https://github.com/pseudomuto/protoc-gen-doc.git github.com/pseudomuto/protoc-gen-doc |
32 | | - |
33 | | -# JSON schema generator |
34 | | -RUN git clone --depth 1 https://github.com/chrusty/protoc-gen-jsonschema.git github.com/chrusty/protoc-gen-jsonschema |
35 | | - |
36 | | -# Infoblox plugins |
37 | | -RUN git clone --depth 1 --branch v0.20.3 https://github.com/infobloxopen/protoc-gen-gorm.git github.com/infobloxopen/protoc-gen-gorm && \ |
38 | | - git clone --depth 1 --branch v0.19.6 https://github.com/infobloxopen/atlas-app-toolkit.git github.com/infobloxopen/atlas-app-toolkit && \ |
39 | | - git clone --depth 1 --branch v0.5.1 https://github.com/infobloxopen/protoc-gen-atlas-query-validate.git github.com/infobloxopen/protoc-gen-atlas-query-validate && \ |
40 | | - git clone --depth 1 --branch v0.4.1 https://github.com/infobloxopen/protoc-gen-atlas-validate.git github.com/infobloxopen/protoc-gen-atlas-validate && \ |
41 | | - git clone --depth 1 --branch v0.3.3 https://github.com/infobloxopen/protoc-gen-preprocess.git github.com/infobloxopen/protoc-gen-preprocess |
42 | | - |
43 | | -# gorm / inflection (runtime deps for protoc-gen-gorm) |
44 | | -RUN git clone --depth 1 --branch v1.9.1 https://github.com/jinzhu/gorm.git github.com/jinzhu/gorm && \ |
45 | | - git clone --depth 1 https://github.com/jinzhu/inflection.git github.com/jinzhu/inflection |
46 | | - |
47 | | -# Misc deps needed by the above |
48 | | -RUN git clone --depth 1 https://github.com/ghodss/yaml.git github.com/ghodss/yaml && \ |
49 | | - git clone --depth 1 https://github.com/go-openapi/spec.git github.com/go-openapi/spec && \ |
50 | | - git clone --depth 1 https://github.com/golang/glog.git github.com/golang/glog |
51 | | - |
52 | | -# Build all protoc plugins in GOPATH mode |
53 | | -ENV GO111MODULE=off |
54 | | - |
55 | | -RUN go install github.com/golang/protobuf/protoc-gen-go && \ |
56 | | - go install github.com/gogo/protobuf/protoc-gen-combo && \ |
57 | | - go install github.com/gogo/protobuf/protoc-gen-gofast && \ |
58 | | - go install github.com/gogo/protobuf/protoc-gen-gogo && \ |
59 | | - go install github.com/gogo/protobuf/protoc-gen-gogofast && \ |
60 | | - go install github.com/gogo/protobuf/protoc-gen-gogofaster && \ |
61 | | - go install github.com/gogo/protobuf/protoc-gen-gogoslick && \ |
62 | | - go install github.com/gogo/protobuf/protoc-gen-gogotypes && \ |
63 | | - go install github.com/gogo/protobuf/protoc-gen-gostring && \ |
64 | | - go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && \ |
65 | | - go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway && \ |
66 | | - go install github.com/envoyproxy/protoc-gen-validate && \ |
67 | | - go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators && \ |
68 | | - go install github.com/pseudomuto/protoc-gen-doc/cmd/... && \ |
69 | | - go install github.com/infobloxopen/protoc-gen-preprocess && \ |
70 | | - go install github.com/infobloxopen/protoc-gen-gorm |
71 | | - |
72 | | -# These two use dep for their own deps |
73 | | -RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-query-validate && \ |
74 | | - go install . && \ |
75 | | - cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-validate && \ |
76 | | - go install . |
77 | | - |
78 | | -# Build protoc-gen-swagger with atlas_patch fork |
79 | | -RUN rm -rf ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \ |
80 | | - git clone --single-branch -b atlas-patch https://github.com/infobloxopen/grpc-gateway.git \ |
81 | | - ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \ |
82 | | - cd ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger && \ |
83 | | - go build -o ${GOPATH}/bin/protoc-gen-swagger . |
84 | | - |
85 | | -RUN mkdir -p /out/usr/bin && \ |
86 | | - install -c ${GOPATH}/bin/protoc-gen* /out/usr/bin/ |
87 | | - |
88 | | -# Collect proto files |
89 | | -RUN mkdir -p /out/go/src && \ |
90 | | - find ${GOPATH}/src -name "*.proto" -exec cp --parents {} /out/ \; |
91 | | - |
92 | | -RUN upx --lzma /out/usr/bin/protoc-gen-* |
93 | | - |
94 | | -FROM alpine:3.19 |
| 19 | +# The version and the binaries checksum for the glide package manager. |
| 20 | +ENV GLIDE_VERSION 0.12.3 |
| 21 | +ENV GLIDE_DOWNLOAD_URL https://github.com/Masterminds/glide/releases/download/v${GLIDE_VERSION}/glide-v${GLIDE_VERSION}-linux-amd64.tar.gz |
| 22 | +ENV GLIDE_DOWNLOAD_SHA256 0e2be5e863464610ebc420443ccfab15cdfdf1c4ab63b5eb25d1216900a75109 |
| 23 | + |
| 24 | +# Download and install the glide package manager. |
| 25 | +RUN curl -fsSL ${GLIDE_DOWNLOAD_URL} -o glide.tar.gz \ |
| 26 | + && echo "${GLIDE_DOWNLOAD_SHA256} glide.tar.gz" | sha256sum -c - \ |
| 27 | + && tar -xzf glide.tar.gz --strip-components=1 -C /usr/local/bin \ |
| 28 | + && rm -rf glide.tar.gz |
| 29 | + |
| 30 | +# Download and install dep. |
| 31 | +ENV INSTALL_DIRECTORY /usr/local/bin |
| 32 | +RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
| 33 | + |
| 34 | +# Install as the protoc plugins as build-time dependecies. |
| 35 | +COPY glide.yaml.tmpl . |
| 36 | + |
| 37 | +# glide is unable to resolve correctly these deps requiring |
| 38 | +# to import all the dependencies in ghodss/yaml |
| 39 | +RUN go get github.com/ghodss/yaml |
| 40 | + |
| 41 | +# Compile binaries for the protocol buffer plugins. We need specific |
| 42 | +# versions of these tools, this is why we at first step install glide, |
| 43 | +# download required versions and then installing them. |
| 44 | +RUN sed -e "s/@AATVersion/$AAT_VERSION/" \ |
| 45 | + -e "s/@PGGVersion/$PGG_VERSION/" \ |
| 46 | + -e "s/@PGAQVVersion/$PGAQV_VERSION/" \ |
| 47 | + -e "s/@PGAVVersion/$PGAV_VERSION/" \ |
| 48 | + -e "s/@PGPVersion/$PGP_VERSION/" \ |
| 49 | + glide.yaml.tmpl > glide.yaml |
| 50 | +RUN glide up --skip-test |
| 51 | +RUN cp -r vendor/* ${GOPATH}/src/ |
| 52 | + |
| 53 | +RUN go install github.com/golang/protobuf/protoc-gen-go |
| 54 | +RUN go install github.com/gogo/protobuf/protoc-gen-combo |
| 55 | +RUN go install github.com/gogo/protobuf/protoc-gen-gofast |
| 56 | +RUN go install github.com/gogo/protobuf/protoc-gen-gogo |
| 57 | +RUN go install github.com/gogo/protobuf/protoc-gen-gogofast |
| 58 | +RUN go install github.com/gogo/protobuf/protoc-gen-gogofaster |
| 59 | +RUN go install github.com/gogo/protobuf/protoc-gen-gogoslick |
| 60 | +RUN go install github.com/gogo/protobuf/protoc-gen-gogotypes |
| 61 | +RUN go install github.com/gogo/protobuf/protoc-gen-gostring |
| 62 | +# Pin logrus to Go 1.17 compatible version before go get pulls latest |
| 63 | +RUN rm -rf ${GOPATH}/src/github.com/sirupsen/logrus && \ |
| 64 | + git clone --depth 1 --branch v1.9.3 https://github.com/sirupsen/logrus.git ${GOPATH}/src/github.com/sirupsen/logrus |
| 65 | +RUN go get github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema |
| 66 | +RUN go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema |
| 67 | +RUN go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway |
| 68 | +RUN go install github.com/envoyproxy/protoc-gen-validate |
| 69 | +RUN go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators |
| 70 | +RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/... |
| 71 | +RUN go install github.com/infobloxopen/protoc-gen-preprocess |
| 72 | +RUN go install \ |
| 73 | + -ldflags "-X github.com/infobloxopen/protoc-gen-gorm/plugin.ProtocGenGormVersion=$PGG_VERSION -X github.com/infobloxopen/protoc-gen-gorm/plugin.AtlasAppToolkitVersion=$AAT_VERSION" \ |
| 74 | + github.com/infobloxopen/protoc-gen-gorm |
| 75 | +# Download all dependencies of protoc-gen-atlas-query-validate |
| 76 | +RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-query-validate && dep ensure -vendor-only |
| 77 | +RUN go install github.com/infobloxopen/protoc-gen-atlas-query-validate |
| 78 | + |
| 79 | +# Download all dependencies of protoc-gen-atlas-validate |
| 80 | +RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-validate && dep ensure -vendor-only |
| 81 | +RUN go install github.com/infobloxopen/protoc-gen-atlas-validate |
| 82 | + |
| 83 | +RUN mkdir -p /out/usr/bin |
| 84 | + |
| 85 | +RUN rm -rf vendor/* ${GOPATH}/pkg/* \ |
| 86 | + && install -c ${GOPATH}/bin/protoc-gen* /out/usr/bin/ |
| 87 | + |
| 88 | +# build protoc-gen-swagger separately with atlas_patch |
| 89 | +RUN go get github.com/go-openapi/spec && \ |
| 90 | + rm -rf ${GOPATH}/src/github.com/grpc-ecosystem/ \ |
| 91 | + && mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/ && \ |
| 92 | + cd ${GOPATH}/src/github.com/grpc-ecosystem && \ |
| 93 | + git clone --single-branch -b atlas-patch https://github.com/infobloxopen/grpc-gateway.git && \ |
| 94 | + cd grpc-gateway/protoc-gen-swagger && go build -o /out/usr/bin/protoc-gen-swagger main.go |
| 95 | + |
| 96 | +RUN mkdir -p /out/protos && \ |
| 97 | + find ${GOPATH}/src -name "*.proto" -exec cp --parents {} /out/protos \; |
| 98 | + |
| 99 | +RUN upx --lzma \ |
| 100 | + /out/usr/bin/protoc-gen-* |
| 101 | + |
| 102 | +FROM alpine:3.8 |
95 | 103 | RUN apk add --no-cache libstdc++ protobuf-dev |
96 | 104 | COPY --from=builder /out/usr /usr |
97 | | -COPY --from=builder /out/go/src /go/src |
| 105 | +COPY --from=builder /out/protos / |
98 | 106 |
|
99 | 107 | WORKDIR /go/src |
100 | 108 |
|
| 109 | +# protoc as an entry point for all plugins with import paths set |
101 | 110 | ENTRYPOINT ["protoc", "-I.", \ |
| 111 | + # required import paths for protoc-gen-grpc-gateway plugin |
102 | 112 | "-Igithub.com/grpc-ecosystem/grpc-gateway/third_party/googleapis", \ |
| 113 | + # required import paths for protoc-gen-swagger plugin |
103 | 114 | "-Igithub.com/grpc-ecosystem/grpc-gateway", "-Igithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options", \ |
| 115 | + # required import paths for protoc-gen-validate plugin |
104 | 116 | "-Igithub.com/envoyproxy/protoc-gen-validate/validate", \ |
| 117 | + # required import paths for go-proto-validators plugin |
105 | 118 | "-Igithub.com/mwitkow/go-proto-validators", \ |
| 119 | + # googleapis proto files |
106 | 120 | "-Igithub.com/googleapis/googleapis", \ |
| 121 | + # required import paths for protoc-gen-gorm plugin |
107 | 122 | "-Igithub.com/infobloxopen/protoc-gen-gorm", \ |
| 123 | + # required import paths for protoc-gen-atlas-query-validate plugin |
108 | 124 | "-Igithub.com/infobloxopen/protoc-gen-atlas-query-validate", \ |
| 125 | + # required import paths for protoc-gen-preprocess plugin |
109 | 126 | "-Igithub.com/infobloxopen/protoc-gen-preprocess", \ |
| 127 | + # required import paths for protoc-gen-atlas-validate plugin |
110 | 128 | "-Igithub.com/infobloxopen/protoc-gen-atlas-validate" \ |
111 | 129 | ] |
0 commit comments