Skip to content

Commit

Permalink
go: use dep in builds, remove relative imports
Browse files Browse the repository at this point in the history
Fixes #11.
Fixes #12.
Fixes #13.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
  • Loading branch information
ahmetb committed Aug 4, 2018
1 parent c7dd0cb commit 427f13f
Show file tree
Hide file tree
Showing 36 changed files with 737 additions and 125 deletions.
10 changes: 7 additions & 3 deletions src/cartservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# cartservice_probe
FROM golang:1.10 as builder
WORKDIR /src/microservices-demo/cartservice/probe
COPY probe/ .
RUN go get -d ./...
RUN wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
chmod +x /go/bin/dep
ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe
WORKDIR /go/src/$PROJECT
COPY probe/Gopkg.* ./
RUN dep ensure --vendor-only -v
COPY ./probe ./
RUN go build -o /cartservice_probe .

# cartservice
Expand Down
1 change: 1 addition & 0 deletions src/cartservice/probe/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
101 changes: 101 additions & 0 deletions src/cartservice/probe/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions src/cartservice/probe/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/golang/protobuf"
version = "1.1.0"

[[constraint]]
branch = "master"
name = "golang.org/x/net"

[[constraint]]
name = "google.golang.org/grpc"
version = "1.14.0"

[prune]
go-tests = true
unused-packages = true
4 changes: 1 addition & 3 deletions src/cartservice/probe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"os"
"time"

pb "./genproto"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe/genproto"

"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc"
)

Expand All @@ -38,7 +37,6 @@ func main() {
grpc.WithBlock(),
grpc.WithTimeout(time.Second*3),
grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
)
if err != nil {
log.Fatalf("probe failed: failed to connect: %+v", err)
Expand Down
1 change: 1 addition & 0 deletions src/checkoutservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
23 changes: 10 additions & 13 deletions src/checkoutservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
FROM golang:1.10-alpine as builder
RUN apk add --no-cache ca-certificates git
WORKDIR /go/src/checkoutservice
RUN apk add --no-cache ca-certificates git && \
wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
chmod +x /go/bin/dep

ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice
WORKDIR /go/src/$PROJECT

# restore dependencies
COPY Gopkg.* ./
RUN dep ensure --vendor-only -v

# get known dependencies
RUN go get -d github.com/google/uuid \
google.golang.org/grpc \
google.golang.org/grpc/codes \
google.golang.org/grpc/status \
go.opencensus.io/plugin/ocgrpc \
go.opencensus.io/exporter/stackdriver \
go.opencensus.io/trace \
cloud.google.com/go/profiler
COPY . .
# get remaining dependencies
RUN go get -d ./...
RUN go build -gcflags='-N -l' -o /checkoutservice .

FROM alpine as release
Expand Down
34 changes: 24 additions & 10 deletions src/checkoutservice/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/checkoutservice/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
name = "cloud.google.com/go"
version = "0.25.0"

[[constraint]]
name = "contrib.go.opencensus.io/exporter/stackdriver"
version = "0.5.0"

[[constraint]]
name = "github.com/golang/protobuf"
version = "1.1.0"
Expand All @@ -47,7 +51,7 @@

[[constraint]]
name = "google.golang.org/grpc"
version = "1.13.0"
version = "1.14.0"

[prune]
go-tests = true
Expand Down
5 changes: 5 additions & 0 deletions src/checkoutservice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# checkoutservice

Run the following command to restore dependencies to `vendor/` directory:

dep ensure --vendor-only
6 changes: 3 additions & 3 deletions src/checkoutservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import (
"time"

"cloud.google.com/go/profiler"
"contrib.go.opencensus.io/exporter/stackdriver"
"github.com/google/uuid"
"go.opencensus.io/exporter/stackdriver"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

pb "checkoutservice/genproto"
money "checkoutservice/money"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion src/checkoutservice/money/money.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package money
import (
"errors"

pb "checkoutservice/genproto"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion src/checkoutservice/money/money_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"reflect"
"testing"

pb "checkoutservice/genproto"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
)

func mmc(u int64, n int32, c string) pb.Money { return pb.Money{Units: u, Nanos: n, CurrencyCode: c} }
Expand Down
Loading

0 comments on commit 427f13f

Please sign in to comment.