Skip to content

Commit ecc696f

Browse files
committed
Fixing image build failure accounting service
1 parent 5fbb125 commit ecc696f

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/accountingservice/Dockerfile

+19-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33

44

55
FROM registry.ddbuild.io/images/mirror/golang:1.22-alpine AS builder
6-
WORKDIR /usr/src/app/
76

8-
COPY ./src/accountingservice/ ./
9-
RUN go build -o /go/bin/accountingservice/
7+
WORKDIR /usr/src/app
8+
9+
RUN apk update \
10+
&& apk add --no-cache make protobuf-dev
11+
12+
13+
RUN --mount=type=cache,target=/go/pkg/mod/ \
14+
--mount=type=bind,source=./src/accountingservice/go.sum,target=go.sum \
15+
--mount=type=bind,source=./src/accountingservice/go.mod,target=go.mod \
16+
--mount=type=bind,source=./src/accountingservice/tools.go,target=tools.go \
17+
go mod download \
18+
&& go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly
1019

11-
# -----------------------------------------------------------------------------
20+
RUN --mount=type=cache,target=/go/pkg/mod/ \
21+
--mount=type=cache,target=/root/.cache/go-build \
22+
--mount=type=bind,rw,source=./src/accountingservice,target=. \
23+
--mount=type=bind,rw,source=./pb,target=./pb \
24+
protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \
25+
&& go build -ldflags "-s -w" -o /go/bin/accountingservice/ ./
1226

1327
FROM alpine
1428

1529
WORKDIR /usr/src/app/
1630

1731
COPY --from=builder /go/bin/accountingservice/ ./
1832

19-
ENTRYPOINT [ "./accountingservice" ]
33+
ENTRYPOINT [ "./accountingservice" ]

src/accountingservice/go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ require (
99
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
1010
go.opentelemetry.io/otel/sdk v1.27.0
1111
go.opentelemetry.io/otel/trace v1.27.0
12-
google.golang.org/grpc v1.64.0
1312
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0
1413
google.golang.org/protobuf v1.34.1
14+
1515
)
1616

1717
require (
@@ -22,7 +22,6 @@ require (
2222
github.com/eapache/queue v1.1.0 // indirect
2323
github.com/go-logr/logr v1.4.2 // indirect
2424
github.com/go-logr/stdr v1.2.2 // indirect
25-
github.com/golang/protobuf v1.5.3 // indirect
2625
github.com/golang/snappy v0.0.4 // indirect
2726
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
2827
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -45,4 +44,5 @@ require (
4544
golang.org/x/text v0.15.0 // indirect
4645
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
4746
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
48-
)
47+
google.golang.org/grpc v1.64.0 // indirect
48+
)

src/accountingservice/kafka/consumer.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package kafka
44

55
import (
66
"context"
7+
78
pb "github.com/open-telemetry/opentelemetry-demo/src/accountingservice/genproto/oteldemo"
89

910
"github.com/IBM/sarama"

src/productcatalogservice/Dockerfile

+5-17
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,10 @@ FROM registry.ddbuild.io/images/mirror/golang:1.22-alpine AS builder
66

77
WORKDIR /usr/src/app/
88

9-
RUN apk update \
10-
&& apk add --no-cache make protobuf-dev
11-
12-
RUN --mount=type=cache,target=/go/pkg/mod/ \
13-
--mount=type=bind,source=./src/productcatalogservice/go.sum,target=go.sum \
14-
--mount=type=bind,source=./src/productcatalogservice/go.mod,target=go.mod \
15-
--mount=type=bind,source=./src/productcatalogservice/tools.go,target=tools.go \
16-
go mod download \
17-
&& go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly
18-
19-
RUN --mount=type=cache,target=/go/pkg/mod/ \
20-
--mount=type=cache,target=/root/.cache/go-build \
21-
--mount=type=bind,rw,source=./src/productcatalogservice,target=. \
22-
--mount=type=bind,rw,source=./pb,target=./pb \
23-
protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \
24-
&& go build -ldflags "-s -w" -o /go/bin/productcatalogservice/ ./
9+
RUN apk add build-base protobuf-dev protoc
10+
11+
COPY ./src/productcatalogservice/ ./
12+
RUN go build -o /go/bin/productcatalogservice/
2513

2614
# -----------------------------------------------------------------------------
2715

@@ -33,4 +21,4 @@ COPY ./src/productcatalogservice/products/ ./products/
3321
COPY --from=builder /go/bin/productcatalogservice/ ./
3422

3523
EXPOSE ${PRODUCT_SERVICE_PORT}
36-
ENTRYPOINT [ "./productcatalogservice" ]
24+
ENTRYPOINT [ "./productcatalogservice" ]

0 commit comments

Comments
 (0)