Skip to content

Commit 3186aa8

Browse files
committed
changes in proto file
added server tests added client tests added dockerfile for building services added docker-compose file changes in db schema added makefile
1 parent e5c4a46 commit 3186aa8

25 files changed

+430
-27693
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
.data
1616

1717
server/vendor
18-
client/vendor
18+
server/coverage.html
19+
20+
client/vendor
21+
client/coverage.html

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: srv cli
2+
3+
srv:
4+
cd server && \
5+
docker build -t ivchms:server .
6+
7+
cli:
8+
cd client && \
9+
docker build -t ivchms:client .
10+
11+
clean:
12+
docker rmi ivchms:server
13+
docker rmi ivchms:client

api/v1/testms.pb.go

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

api/v1/testms.proto

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ message Coordinates {
1414
}
1515

1616
message SaveRequest {
17-
string name = 1;
18-
string city = 2;
19-
string country = 3;
20-
Coordinates coords = 4;
17+
string id = 1;
18+
string name = 2;
19+
string city = 3;
20+
string country = 4;
21+
Coordinates coords = 5;
2122
}
2223

2324
message SaveResponse {
2425
string name = 1;
2526
}
2627

2728
message GetRequest {
28-
string name = 1;
29+
string id = 1;
2930
}
3031

3132
message GetResponse {
32-
string name = 1;
33-
string city = 2;
34-
string country = 3;
35-
Coordinates coords = 4;
33+
string id = 1;
34+
string name = 2;
35+
string city = 3;
36+
string country = 4;
37+
Coordinates coords = 5;
3638
}

client/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build app in a stock Go builder container
2+
FROM golang:1.11.4-alpine3.8 as builder
3+
4+
RUN apk add --no-cache make gcc musl-dev linux-headers git
5+
6+
COPY . /go/src/testms
7+
WORKDIR /go/src/testms
8+
9+
RUN go get github.com/tools/godep && godep restore
10+
RUN go test ./...
11+
RUN cd cmd && go build -o testapp
12+
13+
## Pull binaries into a second stage deploy alpine container
14+
FROM alpine:latest
15+
RUN apk add --no-cache ca-certificates
16+
17+
COPY --from=builder /go/src/testms/cmd/testapp /testms/
18+
19+
WORKDIR /testms
20+
21+
RUN chmod +x testapp
22+
23+
CMD ["./testapp"]

client/cmd/.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GRPC_PORT=8081
1+
GRPC_HOST=server
22
HTTP_PORT=8080
33
CLIENT_TIMEOUT=5 #in seconds
4-
FILEPATH=../../ports.json
4+
FILEPATH=/testms/data.json

client/cmd/.env.dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
GRPC_HOST=localhost
2+
GRPC_PORT=8081
3+
HTTP_PORT=8080
4+
CLIENT_TIMEOUT=5 #in seconds
5+
FILEPATH=../../data.json

client/cmd/main.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ import (
1919
)
2020

2121
const (
22+
defaultGRPCHost = "localhost"
2223
defaultGRPCPort = "8081"
2324
defaultHTTPPort = "8080"
2425
defaultClientTimeout = "15"
2526
defaultFilePath = "../../ports.json"
2627
)
2728

2829
func init() {
29-
if err := godotenv.Load(".env"); err != nil {
30-
log.Fatal("unable to load env file")
30+
if err := godotenv.Load("/run/secrets/client_env"); err != nil {
31+
if err := godotenv.Load(".env.dist"); err != nil {
32+
log.Fatal("unable to load env file")
33+
}
3134
}
3235
}
3336

@@ -84,7 +87,10 @@ func initDeps() (api.PortDomainServiceClient, time.Duration, chan api.SaveReques
8487

8588
timeout := time.Duration(int64(intT)) * time.Second
8689

87-
conn, err := grpc.Dial(":"+getenv("GRPC_POPRT", defaultGRPCPort), grpc.WithInsecure())
90+
conn, err := grpc.Dial(fmt.Sprintf("%s:%s",
91+
getenv("GRPC_HOST", defaultGRPCHost),
92+
getenv("GRPC_PORT", defaultGRPCPort)),
93+
grpc.WithInsecure())
8894
if err != nil {
8995
return nil, 0, nil, "", err
9096
}

0 commit comments

Comments
 (0)