|
1 | 1 | # Copyright The OpenTelemetry Authors |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | - |
5 | | -FROM golang:1.22-alpine AS builder |
6 | | - |
7 | | -WORKDIR /usr/src/app |
8 | | - |
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/accountingservice/go.sum,target=go.sum \ |
14 | | - --mount=type=bind,source=./src/accountingservice/go.mod,target=go.mod \ |
15 | | - --mount=type=bind,source=./src/accountingservice/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/accountingservice,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/accountingservice/ ./ |
25 | | - |
26 | | -FROM alpine |
27 | | - |
28 | | -WORKDIR /usr/src/app/ |
29 | | - |
30 | | -COPY --from=builder /go/bin/accountingservice/ ./ |
31 | | - |
32 | | -ENTRYPOINT [ "./accountingservice" ] |
| 4 | +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base |
| 5 | +USER app |
| 6 | +WORKDIR /app |
| 7 | + |
| 8 | +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build |
| 9 | +ARG BUILD_CONFIGURATION=Release |
| 10 | +WORKDIR /src |
| 11 | +COPY ["/src/accountingservice/", "AccountingService/"] |
| 12 | +COPY ["/pb/demo.proto", "AccountingService/proto/"] |
| 13 | +RUN dotnet restore "./AccountingService/AccountingService.csproj" |
| 14 | +WORKDIR "/src/AccountingService" |
| 15 | + |
| 16 | +RUN dotnet build "./AccountingService.csproj" -c $BUILD_CONFIGURATION -o /app/build |
| 17 | + |
| 18 | +FROM build AS publish |
| 19 | +ARG BUILD_CONFIGURATION=Release |
| 20 | +RUN dotnet publish "./AccountingService.csproj" --use-current-runtime -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false |
| 21 | + |
| 22 | +FROM base AS final |
| 23 | +WORKDIR /app |
| 24 | +COPY --from=publish /app/publish . |
| 25 | + |
| 26 | +USER root |
| 27 | +RUN mkdir -p "/var/log/opentelemetry/dotnet" |
| 28 | +RUN chown app "/var/log/opentelemetry/dotnet" |
| 29 | +USER app |
| 30 | + |
| 31 | +ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"] |
0 commit comments