Skip to content

Commit

Permalink
feat: Established an entrypoint script for DP runner
Browse files Browse the repository at this point in the history
This commit primarily focuses on enabling conditional logic for
initialization via `bun start run <COND>`.
  • Loading branch information
kaynetik committed Oct 4, 2024
1 parent af820e6 commit cabfb72
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

18 changes: 10 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

45 changes: 45 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cabfb72

Please sign in to comment.