Skip to content

Commit

Permalink
Rebuild currency service Dockerfile with alpine (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm committed Jan 16, 2023
1 parent a1ffa72 commit 7216fd4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 65 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#677](https://github.com/open-telemetry/opentelemetry-demo/pull/677))
* Add custom metrics to ads service
([#678](https://github.com/open-telemetry/opentelemetry-demo/pull/678))
* Rebuild currency service Dockerfile with alpine
([#687](https://github.com/open-telemetry/opentelemetry-demo/pull/687))
8 changes: 4 additions & 4 deletions docs/services/currencyservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ function.
std::string span_name = "CurrencyService/Convert";
auto span =
get_tracer("currencyservice")->StartSpan(span_name,
{{SemanticConventions::RPC_SYSTEM, "grpc"},
{SemanticConventions::RPC_SERVICE, "CurrencyService"},
{SemanticConventions::RPC_METHOD, "Convert"},
{SemanticConventions::RPC_GRPC_STATUS_CODE, 0}},
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "CurrencyService"},
{SemanticConventions::kRpcMethod, "Convert"},
{SemanticConventions::kRpcGrpcStatusCode, 0}},
options);
auto scope = get_tracer("currencyservice")->WithActiveSpan(span);
```
Expand Down
2 changes: 1 addition & 1 deletion src/currencyservice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ add_executable(currencyservice src/server.cpp)
add_dependencies(currencyservice demo-proto)
target_link_libraries(
currencyservice demo-proto protobuf::libprotobuf
opentelemetry_trace opentelemetry_common opentelemetry_exporter_otlp_grpc opentelemetry_proto opentelemetry_otlp_recordable opentelemetry_resources gRPC::grpc++)
opentelemetry_trace opentelemetry_common opentelemetry_exporter_otlp_grpc opentelemetry_exporter_otlp_grpc_client opentelemetry_proto opentelemetry_otlp_recordable opentelemetry_resources gRPC::grpc++)

install(TARGETS currencyservice DESTINATION bin)
92 changes: 40 additions & 52 deletions src/currencyservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,47 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update
RUN apt-get -y upgrade && apt-get -y dist-upgrade
RUN apt-get install -qq -y --ignore-missing \
build-essential \
git \
make \
pkg-config \
protobuf-compiler \
libprotobuf-dev \
libcurl4-openssl-dev \
nlohmann-json3-dev \
cmake

# The following arguments would be passed from docker-compose.yml
ARG GRPC_VERSION=1.46.0
ARG OPENTELEMETRY_VERSION=1.5.0

# Install GRPC
RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v${GRPC_VERSION} \
https://github.com/grpc/grpc \
&& cd grpc \
&& mkdir -p cmake/build \
&& cd cmake/build \
&& cmake \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \
../.. \
&& make -j$(nproc || sysctl -n hw.ncpu || echo 1) \
&& make install \
&& cd ../../.. \
&& rm -rf grpc

# Install OpenTelemetry
# Copyright 2023 The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM alpine as builder

RUN apk update
RUN apk add git cmake make g++ grpc-dev re2-dev protobuf-dev c-ares-dev

ARG OPENTELEMETRY_CPP_VERSION=1.8.1

RUN git clone https://github.com/open-telemetry/opentelemetry-cpp \
&& cd opentelemetry-cpp/ \
&& git checkout tags/v${OPENTELEMETRY_VERSION} -b v${OPENTELEMETRY_VERSION} \
&& git submodule update --init --recursive \
&& mkdir build \
&& cd build \
&& cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_OTLP=ON \
&& make -j install && cd ../.. && rm -rf opentelemetry-cpp
&& cd opentelemetry-cpp/ \
&& git checkout tags/v${OPENTELEMETRY_CPP_VERSION} -b v${OPENTELEMETRY_CPP_VERSION} \
&& mkdir build \
&& cd build \
&& cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DWITH_OTLP=ON \
&& make -j$(nproc || sysctl -n hw.ncpu || echo 1) install && cd ../.. && rm -rf opentelemetry-cpp

COPY . /currencyservice

RUN cd /currencyservice \
&& mkdir -p build && cd build \
&& cmake .. && make -j install
&& cmake .. \
&& make -j$(nproc || sysctl -n hw.ncpu || echo 1) install

FROM alpine

WORKDIR /usr/src/app/

RUN apk update
RUN apk add grpc-dev re2-dev protobuf-dev c-ares-dev

COPY --from=builder /usr/local/bin/currencyservice ./

ENTRYPOINT /usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT}
EXPOSE ${CURRENCY_SERVICE_PORT}
ENTRYPOINT ./currencyservice ${CURRENCY_SERVICE_PORT}
16 changes: 8 additions & 8 deletions src/currencyservice/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class CurrencyService final : public hipstershop::CurrencyService::Service
std::string span_name = "CurrencyService/GetSupportedCurrencies";
auto span =
get_tracer("currencyservice")->StartSpan(span_name,
{{SemanticConventions::RPC_SYSTEM, "grpc"},
{SemanticConventions::RPC_SERVICE, "CurrencyService"},
{SemanticConventions::RPC_METHOD, "GetSupportedCurrencies"},
{SemanticConventions::RPC_GRPC_STATUS_CODE, 0}},
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "CurrencyService"},
{SemanticConventions::kRpcMethod, "GetSupportedCurrencies"},
{SemanticConventions::kRpcGrpcStatusCode, 0}},
options);
auto scope = get_tracer("currencyservice")->WithActiveSpan(span);

Expand Down Expand Up @@ -176,10 +176,10 @@ class CurrencyService final : public hipstershop::CurrencyService::Service
std::string span_name = "CurrencyService/Convert";
auto span =
get_tracer("currencyservice")->StartSpan(span_name,
{{SemanticConventions::RPC_SYSTEM, "grpc"},
{SemanticConventions::RPC_SERVICE, "CurrencyService"},
{SemanticConventions::RPC_METHOD, "Convert"},
{SemanticConventions::RPC_GRPC_STATUS_CODE, 0}},
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "CurrencyService"},
{SemanticConventions::kRpcMethod, "Convert"},
{SemanticConventions::kRpcGrpcStatusCode, 0}},
options);
auto scope = get_tracer("currencyservice")->WithActiveSpan(span);

Expand Down

0 comments on commit 7216fd4

Please sign in to comment.