Skip to content

Commit 427f13f

Browse files
committed
go: use dep in builds, remove relative imports
Fixes GoogleCloudPlatform#11. Fixes GoogleCloudPlatform#12. Fixes GoogleCloudPlatform#13. Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent c7dd0cb commit 427f13f

36 files changed

+737
-125
lines changed

src/cartservice/Dockerfile

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# cartservice_probe
22
FROM golang:1.10 as builder
3-
WORKDIR /src/microservices-demo/cartservice/probe
4-
COPY probe/ .
5-
RUN go get -d ./...
3+
RUN wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
4+
chmod +x /go/bin/dep
5+
ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe
6+
WORKDIR /go/src/$PROJECT
7+
COPY probe/Gopkg.* ./
8+
RUN dep ensure --vendor-only -v
9+
COPY ./probe ./
610
RUN go build -o /cartservice_probe .
711

812
# cartservice

src/cartservice/probe/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

src/cartservice/probe/Gopkg.lock

+101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cartservice/probe/Gopkg.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/golang/protobuf"
30+
version = "1.1.0"
31+
32+
[[constraint]]
33+
branch = "master"
34+
name = "golang.org/x/net"
35+
36+
[[constraint]]
37+
name = "google.golang.org/grpc"
38+
version = "1.14.0"
39+
40+
[prune]
41+
go-tests = true
42+
unused-packages = true

src/cartservice/probe/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import (
2020
"os"
2121
"time"
2222

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

25-
"go.opencensus.io/plugin/ocgrpc"
2625
"google.golang.org/grpc"
2726
)
2827

@@ -38,7 +37,6 @@ func main() {
3837
grpc.WithBlock(),
3938
grpc.WithTimeout(time.Second*3),
4039
grpc.WithInsecure(),
41-
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
4240
)
4341
if err != nil {
4442
log.Fatalf("probe failed: failed to connect: %+v", err)

src/checkoutservice/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

src/checkoutservice/Dockerfile

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
FROM golang:1.10-alpine as builder
2-
RUN apk add --no-cache ca-certificates git
3-
WORKDIR /go/src/checkoutservice
2+
RUN apk add --no-cache ca-certificates git && \
3+
wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
4+
chmod +x /go/bin/dep
5+
6+
ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice
7+
WORKDIR /go/src/$PROJECT
8+
9+
# restore dependencies
10+
COPY Gopkg.* ./
11+
RUN dep ensure --vendor-only -v
412

5-
# get known dependencies
6-
RUN go get -d github.com/google/uuid \
7-
google.golang.org/grpc \
8-
google.golang.org/grpc/codes \
9-
google.golang.org/grpc/status \
10-
go.opencensus.io/plugin/ocgrpc \
11-
go.opencensus.io/exporter/stackdriver \
12-
go.opencensus.io/trace \
13-
cloud.google.com/go/profiler
1413
COPY . .
15-
# get remaining dependencies
16-
RUN go get -d ./...
1714
RUN go build -gcflags='-N -l' -o /checkoutservice .
1815

1916
FROM alpine as release

src/checkoutservice/Gopkg.lock

+24-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/checkoutservice/Gopkg.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
name = "cloud.google.com/go"
3030
version = "0.25.0"
3131

32+
[[constraint]]
33+
name = "contrib.go.opencensus.io/exporter/stackdriver"
34+
version = "0.5.0"
35+
3236
[[constraint]]
3337
name = "github.com/golang/protobuf"
3438
version = "1.1.0"
@@ -47,7 +51,7 @@
4751

4852
[[constraint]]
4953
name = "google.golang.org/grpc"
50-
version = "1.13.0"
54+
version = "1.14.0"
5155

5256
[prune]
5357
go-tests = true

src/checkoutservice/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# checkoutservice
2+
3+
Run the following command to restore dependencies to `vendor/` directory:
4+
5+
dep ensure --vendor-only

src/checkoutservice/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ import (
2323
"time"
2424

2525
"cloud.google.com/go/profiler"
26+
"contrib.go.opencensus.io/exporter/stackdriver"
2627
"github.com/google/uuid"
27-
"go.opencensus.io/exporter/stackdriver"
2828
"go.opencensus.io/plugin/ocgrpc"
2929
"go.opencensus.io/trace"
3030
"google.golang.org/grpc"
3131
"google.golang.org/grpc/codes"
3232
"google.golang.org/grpc/status"
3333

34-
pb "checkoutservice/genproto"
35-
money "checkoutservice/money"
34+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
35+
money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money"
3636
)
3737

3838
const (

src/checkoutservice/money/money.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package money
1717
import (
1818
"errors"
1919

20-
pb "checkoutservice/genproto"
20+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
2121
)
2222

2323
const (

src/checkoutservice/money/money_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"reflect"
2020
"testing"
2121

22-
pb "checkoutservice/genproto"
22+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
2323
)
2424

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

0 commit comments

Comments
 (0)