From cabfb7267d30b1cb2ccf5c7778477f0db3d4589d Mon Sep 17 00:00:00 2001 From: kaynetik Date: Fri, 4 Oct 2024 20:33:32 +0200 Subject: [PATCH] feat: Established an entrypoint script for DP runner This commit primarily focuses on enabling conditional logic for initialization via `bun start run `. --- Dockerfile | 7 ++++++- docker-compose.yml | 18 ++++++++++-------- docker-entrypoint.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 7cb1bed..1bee5a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,21 @@ FROM oven/bun:alpine WORKDIR /app + COPY . . RUN bun install -RUN bun init # Expose the port the app runs on EXPOSE 5384 + # Entry script to handle conditional startup COPY ./docker-entrypoint.sh ./docker-entrypoint.sh RUN chmod +x ./docker-entrypoint.sh +# Run init to generate the config.json and private key file +RUN bun start init + ENTRYPOINT ["sh", "./docker-entrypoint.sh"] + diff --git a/docker-compose.yml b/docker-compose.yml index 5f51bad..4951467 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,17 +3,19 @@ services: build: . ports: - "5384:5384" - environment: - # Provide the private key if available - SEDA_DATA_PROXY_PRIVATE_KEY: ${SEDA_DATA_PROXY_PRIVATE_KEY} - volumes: - # Mount config.json if it exists in the host folder - - ./config.json:/app/config.json:ro - # Mount a data proxy private key file if it exists in the host folder - - ./data-proxy-private-key.json:/app/data-proxy-private-key.json:ro + # environment: + # # Provide the private key if available + # SEDA_DATA_PROXY_PRIVATE_KEY: ${SEDA_DATA_PROXY_PRIVATE_KEY} + # + # volumes: + # # Mount config.json if it exists in the host folder + # - ./config.json:/app/config.json:ro + # # Mount a data proxy private key file + # - ./data-proxy-private-key.json:/app/data-proxy-private-key.json:ro networks: - proxy-network networks: proxy-network: driver: bridge + diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..ff394d5 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Initialize flags for config.json and private key +CONFIG_EXISTS=false +PK_EXISTS=false + +# Check if config.json exists +if [ -f /app/config.json ]; then + echo "config.json detected" + CONFIG_EXISTS=true +else + echo "config.json not found" +fi + +# Check if data-proxy-private-key.json exists +if [ -f /app/data-proxy-private-key.json ]; then + echo "data-proxy-private-key.json detected" + PK_EXISTS=true +elif [ -n "$SEDA_DATA_PROXY_PRIVATE_KEY" ]; then + # If private key file does not exist, check if the private key is provided via environment variable + echo "Private key provided via environment variable" + echo "$SEDA_DATA_PROXY_PRIVATE_KEY" >/app/data-proxy-private-key.json + PK_EXISTS=true +else + echo "No private key provided" +fi + +# Determine the command to run based on the presence of config.json and private key +if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then + # Both config.json and private key are provided + echo "Running with config and private key" + RUN_CMD="bun start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json" +elif [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = false ]; then + # Only config.json is provided + echo "Running with config only" + RUN_CMD="bun start run --config /app/config.json" +else + bun init + # Neither config.json nor private key is provided + echo "Running with --disable-proof" + RUN_CMD="bun start run --disable-proof" +fi + +# Execute the final command +exec $RUN_CMD