From 59ff12cc9cb104d5a5306862687af694729a586a Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 2 Aug 2022 09:21:41 -0700 Subject: [PATCH 1/2] no extra port env vars --- docker-compose.yml | 10 +++++----- .../src/main/java/hipstershop/AdService.java | 2 +- src/cartservice/src/Dockerfile | 1 - src/currencyservice/Dockerfile | 2 +- src/featureflagservice/README.md | 2 +- src/featureflagservice/config/runtime.exs | 4 ++-- src/paymentservice/Dockerfile | 1 - src/paymentservice/index.js | 11 +++++++---- src/shippingservice/Dockerfile | 3 +-- src/shippingservice/src/main.rs | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d4dfb150ed..05877fb944 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -126,7 +126,7 @@ services: ports: - "${CURRENCY_SERVICE_PORT}" environment: - - PORT=${CURRENCY_SERVICE_PORT} + - CURRENCY_SERVICE_PORT - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - OTEL_RESOURCE_ATTRIBUTES=service.name=currencyservice depends_on: @@ -143,7 +143,7 @@ services: - "${EMAIL_SERVICE_PORT}" environment: - APP_ENV=production - - PORT=${EMAIL_SERVICE_PORT} + - EMAIL_SERVICE_PORT - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otelcol:4318/v1/traces - OTEL_RESOURCE_ATTRIBUTES=service.name=emailservice depends_on: @@ -246,7 +246,7 @@ services: ports: - "${SHIPPING_SERVICE_PORT}" environment: - - PORT=${SHIPPING_SERVICE_PORT} + - SHIPPING_SERVICE_PORT - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - OTEL_RESOURCE_ATTRIBUTES=service.name=shippingservice depends_on: @@ -263,8 +263,8 @@ services: - "${FEATURE_FLAG_SERVICE_PORT}:${FEATURE_FLAG_SERVICE_PORT}" - "${FEATURE_FLAG_GRPC_SERVICE_PORT}" environment: - - PORT=${FEATURE_FLAG_SERVICE_PORT} - - GRPC_PORT=${FEATURE_FLAG_GRPC_SERVICE_PORT} + - FEATURE_FLAG_SERVICE_PORT + - FEATURE_FLAG_GRPC_SERVICE_PORT - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - OTEL_RESOURCE_ATTRIBUTES=service.name=featureflagservice - DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs diff --git a/src/adservice/src/main/java/hipstershop/AdService.java b/src/adservice/src/main/java/hipstershop/AdService.java index b0b9fe0f96..c449713461 100644 --- a/src/adservice/src/main/java/hipstershop/AdService.java +++ b/src/adservice/src/main/java/hipstershop/AdService.java @@ -58,7 +58,7 @@ public final class AdService { private static final AdService service = new AdService(); private void start() throws IOException { - int port = Integer.parseInt(System.getenv().getOrDefault("AD_SERVICE_PORT", "9555")); + int port = Integer.parseInt(System.getenv("AD_SERVICE_PORT")); healthMgr = new HealthStatusManager(); server = diff --git a/src/cartservice/src/Dockerfile b/src/cartservice/src/Dockerfile index 22c309a3b4..b76af3a281 100644 --- a/src/cartservice/src/Dockerfile +++ b/src/cartservice/src/Dockerfile @@ -32,5 +32,4 @@ WORKDIR /usr/src/app/ COPY --from=builder /cartservice/ ./ EXPOSE ${CART_SERVICE_PORT} - ENTRYPOINT [ "./cartservice" ] diff --git a/src/currencyservice/Dockerfile b/src/currencyservice/Dockerfile index af18848e19..5257a2ac28 100644 --- a/src/currencyservice/Dockerfile +++ b/src/currencyservice/Dockerfile @@ -56,4 +56,4 @@ RUN cd /currencyservice \ && mkdir -p build && cd build \ && cmake .. && make -j install -ENTRYPOINT currencyservice ${PORT} ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT} ${OTEL_RESOURCE_ATTRIBUTES} +ENTRYPOINT currencyservice ${CURRENCY_SERVICE_PORT} ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT} ${OTEL_RESOURCE_ATTRIBUTES} diff --git a/src/featureflagservice/README.md b/src/featureflagservice/README.md index cd7816279d..ad373ed5e5 100644 --- a/src/featureflagservice/README.md +++ b/src/featureflagservice/README.md @@ -22,7 +22,7 @@ docker compose up And run the Release: ``` shell -PHX_SERVER=1 PORT=4000 GRPC_PORT=4001 _build/prod/rel/featureflagservice/bin/featureflagservice start_iex +PHX_SERVER=1 FEATURE_FLAG_SERVICE_PORT=4000 FEATURE_FLAG_GRPC_SERVICE_PORT=4001 _build/prod/rel/featureflagservice/bin/featureflagservice start_iex ``` ## Instrumentation diff --git a/src/featureflagservice/config/runtime.exs b/src/featureflagservice/config/runtime.exs index 844f8b96e0..9b6dab5cff 100644 --- a/src/featureflagservice/config/runtime.exs +++ b/src/featureflagservice/config/runtime.exs @@ -4,7 +4,7 @@ if System.get_env("PHX_SERVER") do config :featureflagservice, FeatureflagserviceWeb.Endpoint, server: true end -grpc_port = String.to_integer(System.get_env("GRPC_PORT") || "4001") +grpc_port = String.to_integer(System.get_env("FEATURE_FLAG_GRPC_SERVICE_PORT")) config :grpcbox, servers: [ @@ -51,7 +51,7 @@ if config_env() == :prod do """ host = System.get_env("PHX_HOST") || "localhost" - port = String.to_integer(System.get_env("PORT") || "4000") + port = String.to_integer(System.get_env("FEATURE_FLAG_SERVICE_PORT")) config :featureflagservice, FeatureflagserviceWeb.Endpoint, url: [host: host, port: 443, scheme: "https"], diff --git a/src/paymentservice/Dockerfile b/src/paymentservice/Dockerfile index f603e6640b..6c03e62579 100644 --- a/src/paymentservice/Dockerfile +++ b/src/paymentservice/Dockerfile @@ -33,5 +33,4 @@ COPY ./src/paymentservice/ ./ COPY ./pb/demo.proto ./ EXPOSE ${PAYMENT_SERVICE_PORT} - ENTRYPOINT [ "node", "--require", "./tracing.js", "./index.js" ] diff --git a/src/paymentservice/index.js b/src/paymentservice/index.js index a6bf8f8853..755fdc07e3 100644 --- a/src/paymentservice/index.js +++ b/src/paymentservice/index.js @@ -55,7 +55,6 @@ async function closeGracefully(signal) { // Main const logger = pino() -const port = process.env['PAYMENT_SERVICE_PORT'] const hipsterShopPackage = grpc.loadPackageDefinition(protoLoader.loadSync('demo.proto')) const server = new grpc.Server() @@ -65,9 +64,13 @@ server.addService(health.service, new health.Implementation({ server.addService(hipsterShopPackage.hipstershop.PaymentService.service, { charge: chargeServiceHandler }) -server.bindAsync(`0.0.0.0:${port}`, grpc.ServerCredentials.createInsecure(), () => { - logger.info(`PaymentService gRPC server started on port ${port}`) - server.start() +server.bindAsync(`0.0.0.0:${process.env['PAYMENT_SERVICE_PORT']}`, grpc.ServerCredentials.createInsecure(), (err, port) => { + if (err) { + return logger.error(err) + } + + logger.info(`PaymentService gRPC server started on port ${port}`) + server.start() } ) diff --git a/src/shippingservice/Dockerfile b/src/shippingservice/Dockerfile index bf6f5fa102..e198fee9b6 100644 --- a/src/shippingservice/Dockerfile +++ b/src/shippingservice/Dockerfile @@ -16,7 +16,6 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.4.7 && \ chmod +x /bin/grpc_health_probe WORKDIR /app COPY --from=builder /app/target/release/shippingservice /shippingservice -ENV PORT=50051 -EXPOSE 50051 +EXPOSE ${SHIPPING_SERVICE_PORT} ENTRYPOINT ["/shippingservice"] diff --git a/src/shippingservice/src/main.rs b/src/shippingservice/src/main.rs index b7b954145f..34fe03741f 100644 --- a/src/shippingservice/src/main.rs +++ b/src/shippingservice/src/main.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box> { init_logger()?; init_tracer()?; info!("OTel pipeline created"); - let port = env::var("PORT").unwrap_or_else(|_| "50051".to_string()); + let port = env::var("SHIPPING_SERVICE_PORT").expect("$SHIPPING_SERVICE_PORT is not set"); let addr = format!("0.0.0.0:{}", port).parse()?; info!("listening on {}", addr); let shipper = ShippingServer::default(); From a9b6dc3fe23aeb209c02136871b72b8a91930733 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 2 Aug 2022 15:34:24 -0700 Subject: [PATCH 2/2] emailservice port undo --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 05877fb944..287525ed56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -143,7 +143,7 @@ services: - "${EMAIL_SERVICE_PORT}" environment: - APP_ENV=production - - EMAIL_SERVICE_PORT + - PORT=${EMAIL_SERVICE_PORT} - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otelcol:4318/v1/traces - OTEL_RESOURCE_ATTRIBUTES=service.name=emailservice depends_on: