Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion examples/app/commerce/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ RUN chmod 0755 /usr/local/bin/commerce-entrypoint.sh && \
chown app:app /usr/local/bin/commerce-entrypoint.sh

USER app
EXPOSE 3002 3003 3004
EXPOSE 3000

# Configure the CSS strategy and port at runtime:
# docker run -e CSS_STRATEGY=module -e PORT=3000 ...
# docker run ... -- --css module --port 3000
#
# Cart cookies are signed with HMAC-SHA256. Pass CART_COOKIE_SECRET at runtime:
# docker run -e CART_COOKIE_SECRET=<your-secret> ...
# If unset, the server generates an ephemeral per-process key (carts do not
Expand Down
28 changes: 14 additions & 14 deletions examples/app/commerce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,35 @@ commerce/

## Docker

Build and run the commerce app as a container. Run all commands from the **repository root**.
Build and run the commerce app as a container. Each container runs a **single CSS strategy** — run one container per strategy. All commands are from the **repository root**.

```bash
# Build the image
docker build -t webui-commerce -f examples/app/commerce/Dockerfile .

# Override cargo-chef version if needed
docker build --build-arg CARGO_CHEF_VERSION=0.1.75 -t webui-commerce -f examples/app/commerce/Dockerfile .
```

# List images
docker images webui-commerce
### Running containers

# Inspect image metadata
docker inspect webui-commerce
Configure the CSS strategy via the `CSS_STRATEGY` environment variable (`link`, `module`, or `style`). The default is `link`. The server listens on port `3000` inside the container by default (override with `PORT`).

# Run the container:
# - host 443 -> container 3004 (--css link)
# - host 1443 -> container 3003 (--css module)
# - host 2443 -> container 3002 (--css style)
docker run -p 443:3004 -p 1443:3003 -p 2443:3002 webui-commerce
```bash
# One container per CSS strategy
docker run -d -p 3004:3000 -e CSS_STRATEGY=link webui-commerce
docker run -d -p 3003:3000 -e CSS_STRATEGY=module webui-commerce
docker run -d -p 3002:3000 -e CSS_STRATEGY=style webui-commerce
```

The container runs both commerce variants:
Or pass flags directly:

- `http://localhost` serves the `--css link` app on container port `3004`
- `http://localhost:1443` serves the `--css module` app on container port `3003`
```bash
docker run -d -p 3004:3000 webui-commerce --css link --port 3000
```

These ports are plain HTTP because the container starts `marketplace-api` with `--no-tls`.
Use a TLS-terminating proxy or ingress if you want external HTTPS on `443` and `1443`.
Use a TLS-terminating proxy or ingress for external HTTPS.

To tag with the project version:

Expand Down
75 changes: 19 additions & 56 deletions examples/app/commerce/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,25 @@

set -eu

cleanup() {
status=$?
trap - INT TERM EXIT

if [ -n "${PID_LINK:-}" ]; then
kill "${PID_LINK}" 2>/dev/null || true
fi
if [ -n "${PID_MODULE:-}" ]; then
kill "${PID_MODULE}" 2>/dev/null || true
fi
if [ -n "${PID_STYLE:-}" ]; then
kill "${PID_STYLE}" 2>/dev/null || true
fi

if [ -n "${PID_LINK:-}" ]; then
wait "${PID_LINK}" 2>/dev/null || true
fi
if [ -n "${PID_MODULE:-}" ]; then
wait "${PID_MODULE}" 2>/dev/null || true
fi
if [ -n "${PID_STYLE:-}" ]; then
wait "${PID_STYLE}" 2>/dev/null || true
fi

exit "${status}"
}

trap cleanup INT TERM EXIT

# Run both commerce variants in the same container:
# - 3004: link CSS strategy
# - 3003: module CSS strategy
marketplace-api --port 3004 --css link --no-tls &
PID_LINK=$!

marketplace-api --port 3003 --css module --no-tls &
PID_MODULE=$!

marketplace-api --port 3002 --css style --no-tls &
PID_STYLE=$!

status=0
while kill -0 "${PID_LINK}" 2>/dev/null && kill -0 "${PID_MODULE}" 2>/dev/null && kill -0 "${PID_STYLE}" 2>/dev/null; do
sleep 1
# Usage: commerce-entrypoint.sh [--css <link|module|style>] [--port <port>]
#
# Each container runs a single marketplace-api instance with one CSS strategy.
# Defaults: --css link --port 3000

CSS_STRATEGY="${CSS_STRATEGY:-link}"
PORT="${PORT:-3000}"

while [ $# -gt 0 ]; do
case "$1" in
--css) CSS_STRATEGY="$2"; shift 2 ;;
--port) PORT="$2"; shift 2 ;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done

if ! kill -0 "${PID_LINK}" 2>/dev/null; then
wait "${PID_LINK}" || status=$?
fi

if ! kill -0 "${PID_MODULE}" 2>/dev/null; then
wait "${PID_MODULE}" || status=$?
fi

if ! kill -0 "${PID_STYLE}" 2>/dev/null; then
wait "${PID_STYLE}" || status=$?
fi
case "${CSS_STRATEGY}" in
link|module|style) ;;
*) echo "Invalid CSS strategy: ${CSS_STRATEGY} (expected link, module, or style)" >&2; exit 1 ;;
esac

exit "${status}"
exec marketplace-api --port "${PORT}" --css "${CSS_STRATEGY}" --no-tls
2 changes: 1 addition & 1 deletion examples/app/commerce/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commerce",
"version": "1.2.1",
"version": "2.0.0",
"type": "module",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/app/commerce/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "marketplace-api"
version = "1.2.1"
version = "2.0.0"
edition = "2021"
publish = false

Expand Down
Loading