-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
123 lines (76 loc) · 2.59 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#
## This Dockerfile aims to simpolify generation of ready-to-use gRPC interfaces for multiple programming languages.
#
ARG LANG=unknown
ARG VER_ALPINE=3.11
ARG VER_PYTHON=3.8
ARG VER_GO=1.14
#
## Return an error when language not provided
#
FROM alpine:$VER_ALPINE AS unknown-builder
RUN printf '\nERR: $LANG has to be specified, try:\n\t%s\n\n' \
'docker build --build-arg="LANG=python" …'
RUN exit 1
# TODO: Create & use non-root users for each container that's run w/volume
#
## This stage creates image that can be used to download all protos:
# DOCKER_BUILDKIT=1 docker build --target protos-downloader --tag protos-downloader .
# docker run --rm -it -v=$(pwd)/:/protos protos-downloader v0.9.0
#
FROM alpine:$VER_ALPINE AS protos-downloader
RUN apk add --no-cache git jq
COPY scripts/download /usr/local/bin/
RUN mkdir /protos
WORKDIR /protos
VOLUME /protos
ENTRYPOINT ["download"]
CMD ["all"]
#
## Use the previously defined downloader to fetch all (lnd & deps) protos here
FROM protos-downloader AS protos-download
RUN download --output=/protos all
#
## Create an image able to generate .go source files in a specified volume
#
FROM golang:$VER_GO-alpine$VER_ALPINE AS go-builder
# `git` for Go
# `findutils`, because `busybox`'s `find` is stupidly slow
RUN apk add --no-cache git findutils protoc
RUN go get -u google.golang.org/grpc
RUN go get -u github.com/golang/protobuf/protoc-gen-go
COPY scripts/generate-go /usr/local/bin/
ENV PROTOS /data/proto/
ENV GO_OUT /data/go/
RUN mkdir -p "$PROTOS" "$GO_OUT"
WORKDIR $PROTOS
VOLUME $GO_OUT
COPY --from=protos-download /protos/ $PROTOS
ENTRYPOINT ["generate-go", "--output=/data/go/"]
CMD ["all"]
#
## TODO: consider generation of other interfaces (client-only would be great…)
#
FROM go-builder AS go-builder-extra
RUN go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
RUN go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
#
## Create an image able to generate .py source files in a specified volume
#
FROM python:$VER_PYTHON-alpine$VER_ALPINE AS python-builder
RUN apk add --no-cache gcc g++ findutils protoc
RUN python -m pip install --upgrade pip
RUN python -m pip install grpcio grpcio-tools
COPY scripts/generate-python /usr/local/bin/
ENV PROTOS /data/proto/
ENV PYTHON_OUT /data/python/
RUN mkdir -p "$PROTOS" "$PYTHON_OUT"
WORKDIR $PROTOS
VOLUME $PYTHON_OUT
COPY --from=protos-download /protos/ $PROTOS
ENTRYPOINT ["generate-python", "--output=/data/python/"]
CMD ["all"]
#
## A convergence point for all LANGs
#
FROM $LANG-builder AS final