Skip to content
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

convert start.sh to powshell #298

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

xuweicheng
Copy link

@xuweicheng xuweicheng commented Mar 5, 2025

Make the current code base run in windows powershell.

Summary by CodeRabbit

  • New Features

    • Introduced an automated start-up script for Windows users that streamlines environment setup and service initialization.
  • Documentation

    • Enhanced setup instructions to include clear, Windows-specific guidance in addition to the existing Unix-based commands.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Warning

Rate limit exceeded

@xuweicheng has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4808029 and 1face33.

📒 Files selected for processing (1)
  • start.ps1 (1 hunks)

Walkthrough

This pull request adds a new PowerShell script (start.ps1) to automate the setup and initialization of the development environment on Windows. It also updates the README.md to include Windows-specific instructions alongside the existing Unix-based setup guide. The script handles environment variable loading, Docker Compose startup, PostgreSQL readiness checks, database migrations via Alembic, dependency installation, and finally launches the FastAPI application with Uvicorn and a Celery worker.

Changes

File(s) Change Summary
README.md Updated to include Windows-specific instructions using start.ps1 along with existing Unix (start.sh) instructions.
start.ps1 New PowerShell script that: loads environment variables, verifies Google Cloud credentials, starts Docker Compose, waits for PostgreSQL readiness, applies Alembic migrations, checks for a Python virtual environment, installs dependencies, and launches the FastAPI app with Uvicorn and a Celery worker.

Sequence Diagram(s)

sequenceDiagram
    participant S as start.ps1
    participant D as Docker Compose
    participant P as PostgreSQL
    participant M as Alembic
    participant V as Env/Deps Checker
    participant F as FastAPI (Uvicorn)
    participant C as Celery Worker

    S->>S: Load .env variables
    S->>D: Start Docker Compose
    loop Check PostgreSQL readiness
        S->>P: pg_isready check
        P-->>S: Ready/Not Ready
    end
    S->>M: Apply database migrations
    S->>V: Verify virtual environment & install dependencies
    S->>M: Reapply migrations if needed
    S->>F: Launch FastAPI application
    S->>C: Start Celery worker
    S->>S: Print success message
Loading

Suggested reviewers

  • dhirenmathur

Poem

I'm a rabbit hopping through lines of code,
Celebrating scripts that lighten the load.
With PowerShell tricks and a helpful guide,
Windows and Unix now walk side by side.
My whiskers twitch with code so neat—
A joyful leap in every beat!


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (5)
README.md (1)

164-167: Enhance Windows-specific setup instructions.

While you've added PowerShell execution instructions, Windows users will also need specific instructions for activating the virtual environment, which differs from the Unix command.

Consider adding these Windows-specific virtual environment activation instructions:

   **Windows**
    ```powershell
+   # Create a virtual environment (if not already created)
+   python -m venv venv
+   
+   # Activate the virtual environment
+   .\venv\Scripts\Activate.ps1
+   
+   # Install dependencies
+   pip install -r requirements.txt
+   
    ./start.ps1
    ```
start.ps1 (4)

49-51: Consider providing a way to terminate background processes.

The FastAPI application is started as a background process with no easy way to terminate it.

 # Start FastAPI application (using uvicorn instead of gunicorn for Windows compatibility)
 Write-Host "Starting momentum application..."
-Start-Process -NoNewWindow powershell -ArgumentList "uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload --log-level debug"
+$uvicornProcess = Start-Process -NoNewWindow -PassThru powershell -ArgumentList "uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload --log-level debug"
+Write-Host "Started uvicorn with PID: $($uvicornProcess.Id)"

Adding a comment at the end of the script to remind users how to stop the processes would also be helpful:

# To stop the background processes, you can run:
# Stop-Process -Id [PID]

53-55: Capture Celery worker process ID for easier management.

Similar to the FastAPI application, the Celery worker is started as a background process with no easy way to terminate it.

 # Start Celery worker
 Write-Host "Starting Celery worker"
-Start-Process -NoNewWindow powershell -ArgumentList "celery -A app.celery.celery_app worker --loglevel=debug -Q ${Env:CELERY_QUEUE_NAME}_process_repository -E --pool=solo"
+$celeryProcess = Start-Process -NoNewWindow -PassThru powershell -ArgumentList "celery -A app.celery.celery_app worker --loglevel=debug -Q ${Env:CELERY_QUEUE_NAME}_process_repository -E --pool=solo"
+Write-Host "Started Celery worker with PID: $($celeryProcess.Id)"

57-57: Add a PowerShell execution policy check.

PowerShell has an execution policy that might prevent scripts from running. It would be helpful to check this and provide guidance.

+# Check PowerShell execution policy
+$policy = Get-ExecutionPolicy
+if ($policy -eq "Restricted") {
+    Write-Host "Warning: PowerShell execution policy is set to Restricted"
+    Write-Host "You may need to run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser"
+}
+
 Write-Host "All services started successfully!"
+Write-Host "Press Ctrl+C to stop all services when done"

30-31: Clarify why migrations are applied twice.

Migrations seem to be applied twice: once after PostgreSQL is ready (implied by the log message) and again after installing dependencies. This could be confusing.

The script has messages suggesting migrations are applied after Postgres is ready, but the actual migration command appears only at line 47. Consider revising the messaging or explaining the two-phase migration approach:

-Write-Host "Postgres is up - applying database migrations"
+Write-Host "Postgres is up - continuing with setup"

Alternatively, if you need to validate database connectivity before continuing:

-Write-Host "Postgres is up - applying database migrations"
+Write-Host "Postgres is up - verifying database connectivity"
+docker exec potpie_postgres psql -U postgres -c "SELECT 1" > $null
+if ($LASTEXITCODE -ne 0) {
+    Write-Host "Error: Could not connect to Postgres database"
+    exit 1
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b239651 and 4808029.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • start.ps1 (1 hunks)

xuweicheng and others added 4 commits March 5, 2025 15:20
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Mar 5, 2025

@dhirenmathur dhirenmathur requested a review from nndn March 8, 2025 04:33
@dhirenmathur
Copy link
Contributor

Thank you @xuweicheng !
@nndn please try on your windows machine

@dhirenmathur
Copy link
Contributor

@kinshuksinghbist please provide an update here after testing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants