-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve setup.sh script with better error handling and user feedback #6758
base: preview
Are you sure you want to change the base?
Conversation
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant S as setup.sh
participant FS as File System
U->>S: Execute setup.sh
S->>S: Print header with color-coded messages
S->>FS: For each service, check if env file exists
FS-->>S: Return file exists or error
S->>S: Call copy_env_file() for file copying
S->>FS: Attempt copying file with verification
S->>S: Generate Django SECRET_KEY (if needed)
S->>U: Display setup summary and next steps
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
setup.sh (1)
59-75
: Django SECRET_KEY Generation with Enhanced Error Handling
The SECRET_KEY generation using/dev/urandom
,tr
, andhead
is effective and includes proper error handling with detailed messages.
A good-to-have improvement would be to ensure idempotency—if the script is re-run, appending a new SECRET_KEY might lead to duplicate entries inapiserver/.env
. Consider checking whether a SECRET_KEY already exists before appending it. For example:- echo -e "SECRET_KEY=\"$SECRET_KEY\"" >> ./apiserver/.env - echo -e "${GREEN}✓${NC} Added SECRET_KEY to apiserver/.env" + if grep -q "^SECRET_KEY=" ./apiserver/.env; then + echo -e "${YELLOW}SECRET_KEY already exists in ./apiserver/.env, skipping generation.${NC}" + else + echo -e "SECRET_KEY=\"$SECRET_KEY\"" >> ./apiserver/.env + echo -e "${GREEN}✓${NC} Added SECRET_KEY to apiserver/.env" + fi
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
setup.sh
(1 hunks)
🔇 Additional comments (6)
setup.sh (6)
3-6
: Informative Header & Script Introduction
The introductory comments clearly explain the purpose of the script and reference the project repository. This provides good context for contributors.
7-13
: Well-defined Output Colors
The definition of color variables (GREEN, BLUE, YELLOW, RED, BOLD, NC) is clear and helps in producing a friendly, color-coded CLI output for user feedback.
15-19
: Clear & Aesthetic Header Printing
The header printed with bold and blue colors uses visual separators effectively. It enhances readability and provides a welcoming introduction to the setup process.
21-39
: Robust File Copy Functionality
Thecopy_env_file
function is well encapsulated with proper error checking. It verifies the source file’s presence and provides clear, color-coded feedback for both success and failure cases.
Consider capturing the exit code of thecp
command in a variable for slightly improved clarity, though checking$?
immediately is acceptable.
41-57
: Environment Configuration & Scalable File Copy Loop
Exporting locale settings (LC_ALL, LC_CTYPE) aids macOS compatibility, and the echo message sets an appropriate context.
The loop over theservices
array for copying.env.example
files is scalable and avoids code duplication. The use of an empty string in the array to handle the root directory is a neat trick.
77-89
: Comprehensive Setup Summary and Guidance
The summary section effectively communicates the overall setup status and next steps for the user. It smartly uses conditionals to display success messages and exits with an error code if issues occurred. This clear guidance enhances the user experience.
Description
This PR enhances the
setup.sh
script to provide better feedback during the environment setup process. The current script runs silently without any output, making it difficult for new contributors to know if the setup completed successfully or troubleshoot any issues that might occur. The improved script includes color-coded output messages, proper error handling, and verification of all created environment files to make the onboarding process smoother.Type of Change
Effects
Before:
After:
Test Scenarios
References
Fixes #[6757]