Skip to content

Commit

Permalink
fix: Decouple from complex entrypoint script
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynetik committed Oct 8, 2024
1 parent 3252513 commit 566074b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 59 deletions.
13 changes: 9 additions & 4 deletions .build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ WORKDIR /app

COPY . .

RUN echo 'export PS1="\e[01;32m\u\e[m:\e[01;34m\w\e[m\$ "' >> /home/bun/.bashrc

RUN bun install

RUN bun build --compile --minify --sourcemap ./workspace/data-proxy/src/index.ts --outfile dataproxy --target=bun-linux-arm64

# Expose the port the app runs on
EXPOSE 5384

# Entry script to handle conditional startup
COPY .build/docker/docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
RUN chmod +x dataproxy

COPY .build/docker/docker-entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]
ENTRYPOINT ["sh", "/app/entrypoint.sh"]
18 changes: 13 additions & 5 deletions .build/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ services:
dockerfile: .build/docker/Dockerfile
ports:
- "5384:5384"
### Provide the private key if available
# 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
### Provide the config file if available
volumes:
- type: bind
source: ../../config.json
target: /app/config.json
read_only: true
consistency: cached
- type: bind
source: ../../data-proxy-private-key.json
target: /app/data-proxy-private-key.json
read_only: true
consistency: cached
networks:
- proxy-network

Expand Down
56 changes: 6 additions & 50 deletions .build/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
#!/bin/bash
#!/bin/sh

# 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
if [ -f "/app/config.json" ] && [ -f "/app/data-proxy-private-key.json" ]; then
echo "Config and private key files found. Running with specific configuration."
exec ./dataproxy run --config /app/config.json --private-key-file /app/data-proxy-private-key.json "$@"
else
echo "config.json not found"
echo "Config or private key file not found. Running with default configuration."
exec ./dataproxy run "$@"
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

run_bun_command() {
if ! bun "$@"; then
echo "Failed to run: bun $*"
exit 1
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="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_bun_command start init
RUN_CMD="start run --config /app/config.json"
else
# Neither config.json nor private key is provided
echo "Running with --disable-proof"
run_bun_command start init
RUN_CMD="start run --disable-proof"
fi

# Execute the final command
run_bun_command $RUN_CMD

0 comments on commit 566074b

Please sign in to comment.