Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ src/*/*/Dockerfile
./src/shipping/target
###################################

###################################
# cart
./src/cart/.build/
###################################
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AD_DOCKERFILE=./src/ad/Dockerfile
# Cart Service
CART_PORT=7070
CART_ADDR=cart:${CART_PORT}
CART_DOCKERFILE=./src/cart/src/Dockerfile
CART_DOCKERFILE=./src/cart/Dockerfile

# Checkout Service
CHECKOUT_PORT=5050
Expand Down Expand Up @@ -147,8 +147,9 @@ KAFKA_ADDR=${KAFKA_HOST}:${KAFKA_PORT}
KAFKA_DOCKERFILE=./src/kafka/Dockerfile

# Valkey
VALKEY_HOST=valkey-cart
VALKEY_PORT=6379
VALKEY_ADDR=valkey-cart:${VALKEY_PORT}
VALKEY_ADDR=${VALKEY_HOST}:${VALKEY_PORT}

# ********************
# Telemetry Components
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ obj/
.gradle/
.idea/
build/
.build/
node_modules/
coverage
.next/
Expand All @@ -42,7 +43,6 @@ test/tracetesting/tracetesting-vars.yaml

# Ignore copied/generated protobuf files
/src/accounting/src/protos/
/src/cart/src/protos/
/src/fraud-detection/src/main/proto
/src/payment/demo.proto
/src/shipping/proto/
Expand Down
1 change: 0 additions & 1 deletion docker-compose.minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ services:
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=cart
- ASPNETCORE_URLS=http://*:${CART_PORT}
depends_on:
valkey-cart:
condition: service_started
Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ services:
environment:
- CART_PORT
- FLAGD_HOST
- FLAGD_PORT
- VALKEY_ADDR
- OTEL_EXPORTER_OTLP_ENDPOINT
- FLAGD_OFREP_PORT
- VALKEY_HOST
- VALKEY_PORT
- OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTEL_COLLECTOR_HOST}:${OTEL_COLLECTOR_PORT_HTTP}
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=cart
- ASPNETCORE_URLS=http://*:${CART_PORT}
- OTEL_LOG_LEVEL=debug
depends_on:
valkey-cart:
condition: service_started
Expand Down
16 changes: 15 additions & 1 deletion docker-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,24 @@ gen_proto_ts() {
/build/pb/demo.proto'
}

gen_proto_swift() {
echo "Generating Swift protobuf files for $1"
docker build -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
docker run --rm -e SERVICE=$1 -v $(pwd):/build "$1-genproto" /bin/sh -c '
mkdir -p /build/src/$SERVICE/Sources/CTL/Generated && \
protoc -I /build/pb \
--plugin="$(swift build --show-bin-path)/protoc-gen-swift" \
--plugin="$(swift build --show-bin-path)/protoc-gen-grpc-swift-2" \
--swift_out="/build/src/$SERVICE/Sources/CTL/Generated" \
--grpc-swift-2_opt=Client=false \
--grpc-swift-2_out="/build/src/$SERVICE/Sources/CTL/Generated" \
/build/pb/demo.proto'
}

if [ -z "$1" ]; then
#gen_proto_dotnet accounting
#gen_proto_java ad
#gen_proto_dotnet cart
gen_proto_swift cart
gen_proto_go checkout
gen_proto_cpp currency
#gen_proto_ruby email
Expand Down
3 changes: 3 additions & 0 deletions src/cart/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/.build/
**/.swiftpm/
Dockerfile*
1 change: 1 addition & 0 deletions src/cart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.swiftpm/
11 changes: 0 additions & 11 deletions src/cart/Directory.Build.props

This file was deleted.

75 changes: 75 additions & 0 deletions src/cart/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ================================
# Build image
# ================================
FROM swift:6.1-noble AS build

# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev \
&& rm -rf /var/lib/apt/lists/*

# Set up a build area
WORKDIR /build

# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./src/cart/Package.* ./
RUN swift package resolve

# Copy entire repo into container
COPY ./src/cart .

# Build the application, with optimizations, with static linking, and using jemalloc
RUN swift build -c release \
--product "cart" \
--static-swift-stdlib \
-Xlinker -ljemalloc

# Switch to the staging area
WORKDIR /staging

# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/cart" ./

# Copy static swift backtracer binary to staging area
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./

# ================================
# Run image
# ================================
FROM ubuntu:noble

# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
libjemalloc2 \
ca-certificates \
tzdata \
&& rm -r /var/lib/apt/lists/*

# Create a cart user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app cart

# Switch to the new home directory
WORKDIR /app

# Copy built executable and any staged resources from builder
COPY --from=build --chown=cart:cart /staging /app

# Provide configuration needed by the built-in crash reporter and some sensible default behaviors.
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=./swift-backtrace-static

# Ensure all further commands run as the cart user
USER cart:cart

# Let Docker bind to the cart port
EXPOSE ${CART_PORT}

# Start the cart service when the image is run
ENTRYPOINT ["./cart"]
8 changes: 0 additions & 8 deletions src/cart/NuGet.config

This file was deleted.

Loading