Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame^] | 1 | # ------------- |
| 2 | # Build stage |
| 3 | |
| 4 | FROM golang:1.10.7-alpine AS build-env |
| 5 | |
| 6 | # Install required packages |
| 7 | RUN apk add --no-cache wget git make build-base protobuf protobuf-dev |
| 8 | |
| 9 | # Install protobuf requirements |
| 10 | RUN git clone https://github.com/googleapis/googleapis.git /usr/local/include/googleapis |
| 11 | RUN go get google.golang.org/genproto/googleapis/api/annotations |
| 12 | |
| 13 | # Prepare directory structure |
| 14 | RUN ["mkdir", "-p", "/src", "src/protos"] |
| 15 | RUN ["mkdir", "-p", "$GOPATH/src", "$GOPATH/pkg", "$GOPATH/bin"] |
| 16 | RUN ["mkdir", "-p", "$GOPATH/src/github.com/opencord"] |
| 17 | RUN ["mkdir", "-p", "$GOPATH/src/github.com/opencord/voltha-go"] |
| 18 | |
| 19 | WORKDIR $GOPATH/src/github.com/opencord |
| 20 | |
| 21 | RUN git clone https://gerrit.opencord.org/voltha-go.git |
| 22 | |
| 23 | WORKDIR $GOPATH/src/github.com/opencord/voltha-go |
| 24 | |
| 25 | |
| 26 | # Copy files |
| 27 | ADD adaptercore ./adapters/openolt/adaptercore |
| 28 | ADD config ./adapters/openolt/config |
| 29 | ADD *.go ./adapters/openolt |
| 30 | |
| 31 | RUN ls ./adapters/openolt |
| 32 | |
| 33 | # Copy required proto files |
| 34 | ADD openolt.proto ./protos |
| 35 | |
| 36 | # Install the protoc-gen-go |
| 37 | RUN go install ./vendor/github.com/golang/protobuf/protoc-gen-go |
| 38 | |
| 39 | # Compile protobuf files |
| 40 | RUN sh protos/scripts/build_protos.sh protos |
| 41 | |
| 42 | RUN protoc --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,plugins=grpc:$GOPATH/src -I protos -I /usr/local/include/googleapis protos/openolt.proto |
| 43 | |
| 44 | # Build openolt |
| 45 | |
| 46 | RUN cd adapters/openolt && go build -o /src/openolt |
| 47 | |
| 48 | # ------------- |
| 49 | # Image creation stage |
| 50 | |
| 51 | FROM alpine:3.8 |
| 52 | |
| 53 | # Set the working directory |
| 54 | WORKDIR /app |
| 55 | |
| 56 | # Copy required files |
| 57 | COPY --from=build-env /src/openolt /app/ |
| 58 | |