Skip to content

Commit

Permalink
refactor: Improve entrypoint 🐳
Browse files Browse the repository at this point in the history
- Implement dynamic configuration handling in entrypoint script
- Add support for three startup scenarios:
  1. Both config.json and private key available
  2. Only config.json available
  3. Neither config.json nor private key available
- Introduce automatic `bun start init` execution when needed
- Improve error handling and logging in the entrypoint script
  • Loading branch information
kaynetik committed Oct 7, 2024
1 parent cabfb72 commit a669650
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ RUN bun install
# 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: 13 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@ 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="bun start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json"
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_CMD="bun start run --config /app/config.json"
run_bun_command start init
RUN_CMD="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"
run_bun_command start init
RUN_CMD="start run --disable-proof"
fi

# Execute the final command
exec $RUN_CMD
run_bun_command $RUN_CMD

0 comments on commit a669650

Please sign in to comment.