shippingservice: minify dockerfile, unify genproto
also fixed a bug causing non-letter chars in tracking ID. Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
44e6671727
commit
2d4f4f884a
6 changed files with 2465 additions and 43 deletions
|
@ -1,31 +1,14 @@
|
|||
FROM golang:1.10.3-alpine3.7 as deps
|
||||
|
||||
FROM golang:1.10-alpine as builder
|
||||
RUN apk add --no-cache \
|
||||
ca-certificates \
|
||||
curl \
|
||||
git \
|
||||
gcc \
|
||||
libffi-dev \
|
||||
make \
|
||||
musl-dev \
|
||||
protobuf \
|
||||
tar
|
||||
git
|
||||
WORKDIR /src/microservices-demo/shippingservice
|
||||
COPY . .
|
||||
RUN go get -d ./...
|
||||
RUN go build -v -o /shippingservice .
|
||||
|
||||
ENV PATH=$PATH:$GOPATH/bin
|
||||
RUN go get -u google.golang.org/grpc && \
|
||||
go get github.com/golang/protobuf/protoc-gen-go
|
||||
|
||||
FROM deps as builder
|
||||
WORKDIR $GOPATH/src/microservices-demo/shipping
|
||||
COPY src/shippingservice $GOPATH/src/microservices-demo/shipping
|
||||
COPY pb/demo.proto $GOPATH/src/microservices-demo/pb/demo.proto
|
||||
|
||||
RUN protoc -I ../pb/ ../pb/demo.proto --go_out=plugins=grpc:../pb
|
||||
RUN go build -o /shipping/shipit
|
||||
|
||||
FROM golang:1.10.3-alpine3.7 as release
|
||||
COPY --from=builder /shipping/shipit /shipit
|
||||
FROM alpine as release
|
||||
COPY --from=builder /shippingservice /shippingservice
|
||||
ENV APP_PORT=50051
|
||||
|
||||
# @TODO add light init system.
|
||||
ENTRYPOINT /shipit
|
||||
EXPOSE 50051
|
||||
ENTRYPOINT /shippingservice
|
||||
|
|
6
src/shippingservice/genproto.sh
Executable file
6
src/shippingservice/genproto.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
PATH=$PATH:$GOPATH/bin
|
||||
protodir=../../pb
|
||||
|
||||
protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto
|
2433
src/shippingservice/genproto/demo.pb.go
Normal file
2433
src/shippingservice/genproto/demo.pb.go
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,10 +10,9 @@ import (
|
|||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
|
||||
pb "microservices-demo/pb"
|
||||
pb "./genproto"
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
default_port = "50051"
|
||||
)
|
||||
|
@ -36,7 +35,7 @@ func (s *server) GetQuote(ctx context.Context, in *pb.GetQuoteRequest) (*pb.GetQ
|
|||
// 3. Generate a response.
|
||||
return &pb.GetQuoteResponse{
|
||||
CostUsd: &pb.MoneyAmount{
|
||||
Decimal: quote.Dollars,
|
||||
Decimal: quote.Dollars,
|
||||
Fractional: quote.Cents,
|
||||
},
|
||||
}, nil
|
||||
|
@ -76,4 +75,4 @@ func main() {
|
|||
if err := s.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
pb "microservices-demo/pb"
|
||||
pb "./genproto"
|
||||
)
|
||||
|
||||
// TestGetQuote is a basic check on the GetQuote RPC service.
|
||||
|
@ -16,17 +17,17 @@ func TestGetQuote(t *testing.T) {
|
|||
Address: &pb.Address{
|
||||
StreetAddress_1: "Muffin Man",
|
||||
StreetAddress_2: "Drury Lane",
|
||||
City: "London",
|
||||
Country: "England",
|
||||
City: "London",
|
||||
Country: "England",
|
||||
},
|
||||
Items: []*pb.CartItem{
|
||||
{
|
||||
ProductId: "23",
|
||||
Quantity: 1,
|
||||
Quantity: 1,
|
||||
},
|
||||
{
|
||||
ProductId: "46",
|
||||
Quantity: 3,
|
||||
Quantity: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -49,17 +50,17 @@ func TestShipOrder(t *testing.T) {
|
|||
Address: &pb.Address{
|
||||
StreetAddress_1: "Muffin Man",
|
||||
StreetAddress_2: "Drury Lane",
|
||||
City: "London",
|
||||
Country: "England",
|
||||
City: "London",
|
||||
Country: "England",
|
||||
},
|
||||
Items: []*pb.CartItem{
|
||||
{
|
||||
ProductId: "23",
|
||||
Quantity: 1,
|
||||
Quantity: 1,
|
||||
},
|
||||
{
|
||||
ProductId: "46",
|
||||
Quantity: 3,
|
||||
Quantity: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -72,4 +73,4 @@ func TestShipOrder(t *testing.T) {
|
|||
if len(res.TrackingId) != 18 {
|
||||
t.Errorf("TestShipOrder: Tracking ID is malformed - has %d characters, %d expected", len(res.TrackingId), 18)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func CreateTrackingId(salt string) string {
|
|||
|
||||
// getRandomLetterCode generates a code point value for a capital letter.
|
||||
func getRandomLetterCode() uint32 {
|
||||
return 65 + uint32(rand.Intn(27))
|
||||
return 65 + uint32(rand.Intn(25))
|
||||
}
|
||||
|
||||
// getRandomNumber generates a string representation of a number with the requested number of digits.
|
||||
|
|
Loading…
Reference in a new issue