Skip to content

Add scripts to download data for offline use - #120

Merged
bubacoder merged 1 commit into
mainfrom
feature/offline-data
Apr 13, 2025
Merged

Add scripts to download data for offline use#120
bubacoder merged 1 commit into
mainfrom
feature/offline-data

Conversation

@bubacoder

@bubacoder bubacoder commented Apr 13, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Introduced an offline data download capability, making it easier to fetch updated content for offline use.
    • Added a dedicated script that automatically retrieves the latest zim files for offline access.
  • Chores

    • Streamlined storage configurations for a more consistent setup.
    • Enhanced host resolution with an automatic symbolic link for easier access.

@coderabbitai

coderabbitai Bot commented Apr 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new task named get-offline-data in the Taskfile.yaml, which downloads data files for offline use. It loads two environment variable files and executes scripts for downloading resources. The environment variable definitions in a sample .env file have been updated to use a consolidated path structure. Additionally, a symbolic link creation command has been added in a configuration script, a new script for downloading Kiwix zim files has been introduced with strict error handling, and a comment has been added to the Ollama download script. A minor formatting update was also made in a common Docker script.

Changes

File(s) Change Summary
Taskfile.yaml Added new get-offline-data task with a description, loading dotenv files, and executing two offline data scripts.
config-example/…/myhost/.env Updated storage variable definitions to use ${STORAGE_LOCAL_MEDIA} instead of ${STORAGE_LOCAL}/media.
config-example/…/myhost/apply.sh Added a command to create a symbolic link named localhost in the parent directory of HOST_CONFIG_DIR.
docker/common.sh Inserted an empty line within the docker_command function for layout separation.
scripts/get-offline-data-kiwix.sh Added a new Bash script with strict error handling to validate inputs, extract the latest zim file information, and download offline Kiwix data.
scripts/get-offline-data-ollama.sh Added a comment (# Large Language Models - https://ollama.com/search) before calling the ollama_pull function.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant T as Taskfile (get-offline-data)
    participant O as ollama Script
    participant K as kiwix Script

    U->>T: Run get-offline-data task
    T->>T: Load dotenv configs (docker/.env, localhost/.env)
    T->>O: Execute get-offline-data-ollama.sh
    T->>K: Execute get-offline-data-kiwix.sh with $STORAGE_KIWIX argument
Loading
sequenceDiagram
    participant S as get-offline-data-kiwix.sh
    participant W as Web (wget)
    participant FS as Filesystem

    S->>S: Validate target directory parameter
    S->>W: Fetch HTML content from provided URL
    W-->>S: Return HTML content
    S->>S: Extract filenames and determine latest zim file
    alt File exists locally
        S->>S: Log "No download needed"
    else File missing
        S->>W: Download the latest zim file
        W-->>S: Transfer file
        S->>S: Log download success or failure
    end
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 84415b7 and 67512fd.

📒 Files selected for processing (6)
  • Taskfile.yaml (1 hunks)
  • config-example/docker/myhost/.env (1 hunks)
  • config-example/docker/myhost/apply.sh (1 hunks)
  • docker/common.sh (1 hunks)
  • scripts/get-offline-data-kiwix.sh (1 hunks)
  • scripts/get-offline-data-ollama.sh (1 hunks)

🪧 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
scripts/get-offline-data-ollama.sh (1)

22-25: Clarify LLM Section Comment
The addition of the # LLM comment helps demarcate the section where language models are being pulled. Consider expanding the comment (e.g., "LLM - Pulling language models for offline processing") if further context may assist future maintainers.

config-example/docker/myhost/apply.sh (1)

10-12: Verify Symlink Creation for 'localhost'
The newly added commands create a symbolic link named localhost in the parent directory of HOST_CONFIG_DIR that points to $(hostname)/. Please verify that using a trailing slash in the target ($(hostname)/) meets your deployment needs and does not cause unexpected path resolution issues.

scripts/get-offline-data-kiwix.sh (2)

28-42: HTML Fetch and File Extraction Logic
The function fetches HTML content with wget and uses a regex to extract filenames matching ${PATTERN}_[0-9]{4}-[0-9]{2}\.zim. This works well if file names include only a year and month. If a day component might be present in filenames, consider updating the regex accordingly.


59-66: Robustness in File Downloading
When downloading, the command wget -q --show-progress "$URL$LATEST_FILE" concatenates the URL and filename directly. This assumes that $URL ends with a trailing slash. To improve robustness, consider ensuring that the URL ends with a slash or appending one if missing.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84415b7 and dfaa6d3.

📒 Files selected for processing (6)
  • Taskfile.yaml (1 hunks)
  • config-example/docker/myhost/.env (1 hunks)
  • config-example/docker/myhost/apply.sh (1 hunks)
  • docker/common.sh (1 hunks)
  • scripts/get-offline-data-kiwix.sh (1 hunks)
  • scripts/get-offline-data-ollama.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: check
🔇 Additional comments (9)
docker/common.sh (1)

61-62: Improved Readability in docker_command Function
Inserting an empty line to separate output sections improves readability. This formatting tweak is a minor but useful enhancement.

Taskfile.yaml (1)

125-133: New Offline Data Task Added
The new get-offline-data task is correctly defined with the appropriate dotenv files and command invocations for the offline scripts. Ensure that the STORAGE_KIWIX environment variable is set as expected so that the scripts/get-offline-data-kiwix.sh script functions properly.

scripts/get-offline-data-kiwix.sh (6)

1-9: Initial Parameter and Environment Validation
The script sets strict error handling with set -euo pipefail and validates that a target directory is provided. Clear error messages guide the user if the required parameter is missing.


12-16: Directory Existence Check
The validation to confirm that the provided target directory exists is effective and prevents unintended operation in an invalid directory.


24-27: Definition of kiwix_pull Function
The kiwix_pull function encapsulates the download logic neatly. Defining this functionality as a separate function aids maintainability and clarity.


44-49: Determining the Latest File
Sorting the list in reverse order and picking the first entry is an effective and simple method to select the latest file—provided file naming remains consistent.


53-57: Local File Check to Prevent Redundant Downloads
The script correctly checks if the latest file already exists locally before attempting a download, thereby avoiding unnecessary network usage.


69-71: Invocation of Kiwix Pull Operations
The calls to kiwix_pull with different URL and pattern pairs are structured clearly. Confirm that these URLs and regex patterns remain valid and meet your download requirements in the long term.

config-example/docker/myhost/.env (1)

7-11: Consolidated Storage Variable Update

The updated storage path variables (lines 8–11) now reference ${STORAGE_LOCAL_MEDIA} rather than hardcoding parts of the path. This centralization improves consistency and simplifies future updates to storage locations. Please ensure that any scripts or task configurations (e.g., in Taskfile.yaml) referencing these variables are also updated accordingly.

@bubacoder
bubacoder force-pushed the feature/offline-data branch from dfaa6d3 to 67512fd Compare April 13, 2025 15:11
@bubacoder
bubacoder merged commit 986fa2e into main Apr 13, 2025
@bubacoder
bubacoder deleted the feature/offline-data branch April 13, 2025 15:21
@coderabbitai coderabbitai Bot mentioned this pull request Jul 24, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 26, 2026
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.

1 participant