### GitHub Actions: Basic Turbo CDN Setup Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/ci_cd_usage.md This snippet shows a basic GitHub Actions workflow to install Turbo CDN and download dependencies like Node.js and Go. It includes steps for checking out code, installing Turbo CDN, downloading artifacts, setting up the environment by adding binaries to the PATH, and a placeholder for the project build command. ```yaml name: Build with Turbo CDN on: push: branches: [ main, develop ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Turbo CDN run: | curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz sudo mv turbo-cdn /usr/local/bin/ turbo-cdn --version - name: Download Dependencies with Turbo CDN run: | # Download Node.js turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz" "./deps/" # Download Go turbo-cdn dl "https://golang.org/dl/go1.21.5.linux-amd64.tar.gz" "./deps/" # Download Rust turbo-cdn dl "https://forge.rust-lang.org/infra/channel-releases.html" "./deps/" - name: Setup Dependencies run: | # Extract and setup downloaded dependencies cd deps tar -xf node-v20.10.0-linux-x64.tar.xz tar -xf go1.21.5.linux-amd64.tar.gz # Add to PATH echo "$PWD/node-v20.10.0-linux-x64/bin" >> $GITHUB_PATH echo "$PWD/go/bin" >> $GITHUB_PATH - name: Build Project run: | node --version go version # Your build commands here ``` -------------------------------- ### Download VS Code Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading the VS Code installer for Windows 64-bit using the Turbo CDN CLI. ```bash # Download VS Code turbo-cdn dl "https://github.com/microsoft/vscode/releases/download/1.85.0/VSCodeUserSetup-x64-1.85.0.exe" ``` -------------------------------- ### Download Git Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading the Git for Windows 64-bit installer using the Turbo CDN CLI. ```bash # Download Git turbo-cdn dl "https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/Git-2.43.0-64-bit.exe" ``` -------------------------------- ### Download Go Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading the Go programming language installer for Windows using the Turbo CDN CLI. ```bash # Download Go turbo-cdn dl "https://go.dev/dl/go1.21.5.windows-amd64.zip" ``` -------------------------------- ### Download Docker Desktop Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading the Docker Desktop installer for Windows (64-bit, main channel) using the Turbo CDN CLI. ```bash # Download Docker Desktop turbo-cdn dl "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe" ``` -------------------------------- ### Jenkinsfile: Setup and Download Dependencies with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/ci_cd_usage.md This Jenkinsfile defines a CI/CD pipeline that first installs Turbo CDN if not present, then downloads specified dependencies (ripgrep and fd) using Turbo CDN's 'dl' command into a cache directory. It also includes steps for extracting and verifying these tools. ```groovy pipeline { agent any environment { TURBO_CDN_CACHE_DIR = "${WORKSPACE}/.turbo-cdn-cache" } stages { stage('Setup Turbo CDN') { steps { script { if (!fileExists('/usr/local/bin/turbo-cdn')) { sh ''' curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz sudo mv turbo-cdn /usr/local/bin/ sudo chmod +x /usr/local/bin/turbo-cdn ''' } sh 'turbo-cdn --version' } } } stage('Download Dependencies') { steps { sh ''' mkdir -p $TURBO_CDN_CACHE_DIR echo "๐Ÿ“ฅ Downloading build dependencies..." turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz" "$TURBO_CDN_CACHE_DIR/" turbo-cdn dl "https://github.com/sharkdp/fd/releases/download/v8.7.0/fd-v8.7.0-x86_64-unknown-linux-gnu.tar.gz" "$TURBO_CDN_CACHE_DIR/" echo "โœ… Dependencies downloaded" ''' } } stage('Setup Tools') { steps { sh ''' cd $TURBO_CDN_CACHE_DIR # Extract tools for archive in *.tar.gz; do echo "๐Ÿ“ฆ Extracting: $archive" tar -xf "$archive" done # Verify tools find . -name "rg" -exec {} --version \; find . -name "fd" -exec {} --version \; ''' } } stage('Build') { steps { sh ''' echo "๐Ÿš€ Building project with optimized tools..." # Add your build commands here ''' } } stage('Test') { steps { sh ''' echo "๐Ÿงช Running tests..." # Add your test commands here ''' } } } post { always { archiveArtifacts artifacts: '.turbo-cdn-cache/**', allowEmptyArchive: true } cleanup { sh 'rm -rf $TURBO_CDN_CACHE_DIR' } } } ``` -------------------------------- ### Download Script for Docker with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/ci_cd_usage.md This bash script automates the setup of Turbo CDN within a Docker container. It installs Turbo CDN, creates a cache directory, and then uses Turbo CDN to download specified dependencies like VSCode, Docker Compose, and kubectl. ```bash #!/bin/bash # scripts/download-deps.sh set -e echo "๐Ÿš€ Setting up Turbo CDN in Docker..." # Install Turbo CDN curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz mv turbo-cdn /usr/local/bin/ chmod +x /usr/local/bin/turbo-cdn # Create cache directory mkdir -p $TURBO_CDN_CACHE_DIR # Download dependencies echo "๐Ÿ“ฅ Downloading dependencies with Turbo CDN..." DEPENDENCIES=( "https://github.com/microsoft/vscode/releases/download/1.85.0/VSCode-linux-x64.tar.gz" "https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64" "https://github.com/kubernetes/kubectl/releases/download/v1.29.0/kubectl-linux-amd64" ) for dep in "${DEPENDENCIES[@]}"; do echo "๐Ÿ“ฆ Downloading: $dep" turbo-cdn dl "$dep" "$TURBO_CDN_CACHE_DIR/" --verbose done echo "โœ… All dependencies downloaded to $TURBO_CDN_CACHE_DIR" ``` -------------------------------- ### vx Example: URL Optimization Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md An example of a vx integration demonstrating how to use AsyncTurboCdn to parse and optimize download URLs within a Rust struct. ```rust use turbo_cdn::async_api::AsyncTurboCdn; pub struct VxDownloader { cdn: AsyncTurboCdn, } impl VxDownloader { pub async fn new() -> Result> { let cdn = AsyncTurboCdn::new().await?; Ok(Self { cdn }) } pub async fn optimize_download_url(&self, url: &str) -> Result> { // Parse the URL to get information let parsed = self.cdn.parse_url_async(url).await?; println!("Detected: {} v{} from {:?}", parsed.repository, parsed.version, parsed.source_type ); // Get optimal URL for user's location let optimal_url = self.cdn.get_optimal_url_async(url).await?; Ok(optimal_url) } pub async fn download_with_optimization(&self, url: &str) -> Result> { let result = self.cdn.download_from_url_async(url, None).await?; Ok(result.path.to_string_lossy().to_string()) } } ``` -------------------------------- ### Get Help for Specific Command Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This command shows detailed help information, including usage and options, for a specific Turbo CDN command, such as 'download'. ```bash # Show help for specific command turbo-cdn download --help ``` -------------------------------- ### Get All Available Commands and Options Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This command displays a comprehensive list of all available commands and their options within the Turbo CDN CLI, useful for discovering functionality. ```bash # Show all available commands and options turbo-cdn --help ``` -------------------------------- ### Quick Functions for One-off Operations Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md Provides examples of using the quick functions for one-off asynchronous operations like optimizing URLs, parsing URLs, and downloading. ```rust use turbo_cdn::async_api::quick; // Quick URL optimization let optimal_url = quick::optimize_url(url).await?; // Quick URL parsing let parsed = quick::parse_url(url).await?; // Quick download let result = quick::download_url(url).await?; ``` -------------------------------- ### Turbo CDN Development Setup and Commands Source: https://github.com/loonghao/turbo-cdn/blob/main/README.md Provides essential commands for setting up the Turbo CDN project, including cloning the repository, building the project, running tests, executing examples, enabling logging, formatting code, and linting. ```Bash git clone https://github.com/loonghao/turbo-cdn.git cd turbo-cdn cargo build cargo test cargo run --example url_parsing_demo cargo run --example url_optimization RUST_LOG=turbo_cdn=debug cargo run cargo fmt cargo clippy ``` -------------------------------- ### Production Dockerfile with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md This Dockerfile sets up a production environment using Ubuntu 22.04. It installs system dependencies, installs Turbo CDN, and then uses a multi-stage build process. The downloader stage fetches Node.js, the builder stage installs Node.js and builds the application using npm, and the production stage copies the necessary artifacts and runs the application as a non-root user with a health check. ```dockerfile # Production-optimized Dockerfile with Turbo CDN FROM ubuntu:22.04 AS base # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # Install Turbo CDN RUN curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz && \ mv turbo-cdn /usr/local/bin/ && \ chmod +x /usr/local/bin/turbo-cdn # Download stage FROM base AS downloader WORKDIR /downloads # Download production dependencies RUN turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz" && \ tar -xf node-v20.10.0-linux-x64.tar.xz # Build stage FROM base AS builder # Copy Node.js from downloader COPY --from=downloader /downloads/node-v20.10.0-linux-x64 /opt/node ENV PATH="/opt/node/bin:$PATH" # Copy source and build WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . RUN npm run build # Production stage FROM ubuntu:22.04 AS production # Install minimal runtime dependencies RUN apt-get update && apt-get install -y \ ca-certificates \ && rm -rf /var/lib/apt/lists/* \ && groupadd -r appuser && useradd -r -g appuser appuser # Copy Node.js runtime COPY --from=builder /opt/node /opt/node ENV PATH="/opt/node/bin:$PATH" # Copy application WORKDIR /app COPY --from=builder /app/dist ./ COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./ # Set ownership RUN chown -R appuser:appuser /app # Switch to non-root user USER appuser # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3000/health || exit 1 EXPOSE 3000 CMD ["node", "dist/index.js"] ``` -------------------------------- ### Turbo CDN Development Setup (Bash) Source: https://github.com/loonghao/turbo-cdn/blob/main/README_zh.md This bash script outlines the steps for setting up the Turbo CDN development environment, including cloning the repository, installing dependencies, running tests, and formatting code. ```bash # Clone the repository git clone https://github.com/loonghao/turbo-cdn.git cd turbo-cdn # Install dependencies # Assuming Cargo is used for Rust projects # cargo build # Run tests # cargo test # Run with logs # RUST_LOG=turbo_cdn=debug cargo run # Format code # cargo fmt # Lint code # cargo clippy ``` -------------------------------- ### Bash: Setup Development Environment with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/batch_operations.md A bash script to set up a development environment by creating directories and downloading various tools, runtimes, and editors using `turbo-cdn dl` with specified destination paths. ```bash #!/bin/bash # setup_dev_env.sh - Complete development environment setup echo "๐Ÿ› ๏ธ Setting up development environment..." # Create directories mkdir -p ./downloads/{tools,runtimes,editors} # Download development tools echo "๐Ÿ“ฅ Downloading development tools..." turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip" "./downloads/tools/" turbo-cdn dl "https://github.com/sharkdp/fd/releases/download/v8.7.0/fd-v8.7.0-x86_64-pc-windows-msvc.zip" "./downloads/tools/" turbo-cdn dl "https://github.com/sharkdp/bat/releases/download/v0.24.0/bat-v0.24.0-x86_64-pc-windows-msvc.zip" "./downloads/tools/" # Download runtimes echo "๐Ÿ“ฅ Downloading runtimes..." turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-win-x64.zip" "./downloads/runtimes/" turbo-cdn dl "https://github.com/golang/go/releases/download/go1.21.5/go1.21.5.windows-amd64.zip" "./downloads/runtimes/" turbo-cdn dl "https://github.com/rust-lang/rust/releases/download/1.74.1/rust-1.74.1-x86_64-pc-windows-msvc.msi" "./downloads/runtimes/" # Download editors echo "๐Ÿ“ฅ Downloading editors..." turbo-cdn dl "https://github.com/microsoft/vscode/releases/download/1.85.0/VSCodeUserSetup-x64-1.85.0.exe" "./downloads/editors/" turbo-cdn dl "https://github.com/neovim/neovim/releases/download/v0.9.4/nvim-win64.zip" "./downloads/editors/" echo "โœ… Development environment setup completed!" ``` -------------------------------- ### AsyncTurboCdn Core Methods Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md Illustrates the core asynchronous methods of AsyncTurboCdn, including parsing URLs, getting optimal URLs, downloading, and extracting versions from filenames. ```rust // Parse URL information let parsed = cdn.parse_url_async(url).await?; println!("Repository: {}", parsed.repository); println!("Version: {}", parsed.version); println!("Filename: {}", parsed.filename); // Get optimal CDN URL let optimal_url = cdn.get_optimal_url_async(url).await?; // Download with optimization let result = cdn.download_from_url_async(url, None).await?; println!("Downloaded to: {}", result.path.display()); // Extract version from filename let version = cdn.extract_version_from_filename_async("app-v1.2.3.zip").await; ``` -------------------------------- ### Download File with Verbose Output Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Use the --verbose flag to get detailed information about the download process. This is helpful for debugging or understanding the steps involved. ```bash turbo-cdn dl "https://github.com/microsoft/vscode/releases/download/1.85.0/VSCode-linux-x64.tar.gz" --verbose ``` -------------------------------- ### Dockerfile: Basic Turbo CDN Integration Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md A simple Dockerfile that installs Turbo CDN and uses it to download Node.js dependencies, setting up the environment for an application. ```dockerfile FROM ubuntu:22.04 # Install Turbo CDN RUN apt-get update && apt-get install -y curl && \ curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz && \ mv turbo-cdn /usr/local/bin/ && \ chmod +x /usr/local/bin/turbo-cdn && \ rm -rf /var/lib/apt/lists/* # Download dependencies with Turbo CDN WORKDIR /tmp RUN turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz" && \ tar -xf node-v20.10.0-linux-x64.tar.xz && \ mv node-v20.10.0-linux-x64 /opt/node && \ rm node-v20.10.0-linux-x64.tar.xz # Setup PATH ENV PATH="/opt/node/bin:$PATH" # Verify installation RUN node --version && npm --version WORKDIR /app COPY . . # Install application dependencies RUN npm install EXPOSE 3000 CMD ["npm", "start"] ``` -------------------------------- ### Run Turbo CDN Rust Examples Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/README.md Instructions to run various Turbo CDN examples written in Rust using Cargo. This includes basic usage, async API, advanced configuration, and vx integration. ```bash cargo run --example basic_usage cargo run --example async_api cargo run --example advanced_config cargo run --example vx_integration ``` -------------------------------- ### Download Rust Crates (Source) Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading the source code for a Rust crate (serde) from crates.io using the Turbo CDN CLI. ```bash # Rust crates (source) turbo-cdn dl "https://crates.io/api/v1/crates/serde/1.0.193/download" ``` -------------------------------- ### Troubleshoot Network Timeout Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md If downloads are timing out, this example shows how to use the --verbose flag with the download command to get more insight into the issue. ```bash turbo-cdn dl "https://example.com/large-file.zip" --verbose ``` -------------------------------- ### Download Rust Tools Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading Rust-related tools, specifically the rust-analyzer, using the Turbo CDN CLI. ```bash # Download Rust tools turbo-cdn dl "https://github.com/rust-lang/rust-analyzer/releases/download/2023-12-04/rust-analyzer-x86_64-pc-windows-msvc.gz" ``` -------------------------------- ### Run Turbo CDN Rust Performance Examples Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/README.md Commands to execute performance-related examples for Turbo CDN written in Rust, specifically for benchmarks and monitoring. ```bash cargo run --example benchmarks cargo run --example monitoring ``` -------------------------------- ### Dockerfile for Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/ci_cd_usage.md This Dockerfile sets up an environment with Node.js, Go, and Ripgrep, utilizing Turbo CDN for downloading and caching dependencies. It configures the PATH environment variable and verifies the installations. ```Dockerfile FROM ubuntu:22.04 AS downloader RUN apt-get update && apt-get install -y curl # Download and install Node.js RUN curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz RUN mv turbo-cdn /usr/local/bin/ RUN chmod +x /usr/local/bin/turbo-cdn RUN curl -L https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz -o /downloads/node.tar.xz && \ tar -xf /downloads/node.tar.xz -C /downloads/ # Download and install Go RUN curl -L https://go.dev/dl/go1.21.5.linux-amd64.tar.gz -o /downloads/go.tar.gz && \ tar -xzf /downloads/go.tar.gz -C /downloads/ # Download and install Ripgrep RUN curl -L https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz -o /downloads/ripgrep.tar.gz && \ tar -xzf /downloads/ripgrep.tar.gz -C /downloads/ FROM ubuntu:22.04 # Copy downloaded and extracted tools COPY --from=downloader /downloads/node-v20.10.0-linux-x64 /opt/node COPY --from=downloader /downloads/go /opt/go COPY --from=downloader /downloads/ripgrep-14.1.1-x86_64-unknown-linux-musl/rg /usr/local/bin/ # Setup PATH ENV PATH="/opt/node/bin:/opt/go/bin:$PATH" # Verify installations RUN node --version && go version && rg --version # Your application setup WORKDIR /app COPY . . # Build commands RUN echo "๐Ÿš€ Building application with optimized dependencies..." ``` -------------------------------- ### Troubleshoot Permission Denied Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This example demonstrates how to resolve 'Permission Denied' errors by specifying a download directory that the user has write permissions for. ```bash # Download to a directory you own turbo-cdn dl "https://example.com/file.zip" "./my-downloads/file.zip" ``` -------------------------------- ### Dockerfile: Turbo CDN for Dependency Downloads Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/ci_cd_usage.md This Dockerfile utilizes a multi-stage build process. The first stage installs Turbo CDN and downloads various dependencies like Node.js, Go, and ripgrep using Turbo CDN. These downloaded artifacts are then extracted, making them available for subsequent stages or for use within the container. ```dockerfile # Multi-stage Dockerfile with Turbo CDN FROM ubuntu:22.04 AS downloader # Install Turbo CDN RUN apt-get update && apt-get install -y curl && \ curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz && \ mv turbo-cdn /usr/local/bin/ && \ chmod +x /usr/local/bin/turbo-cdn # Download dependencies with Turbo CDN WORKDIR /downloads RUN turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz" && \ turbo-cdn dl "https://golang.org/dl/go1.21.5.linux-amd64.tar.gz" && \ turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz" # Extract downloads RUN tar -xf node-v20.10.0-linux-x64.tar.xz && \ tar -xf go1.21.5.linux-amd64.tar.gz && \ tar -xf ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz # Production stage FROM ubuntu:22.04 AS production ``` -------------------------------- ### Installing Rust and Development Tools Source: https://github.com/loonghao/turbo-cdn/blob/main/CONTRIBUTING.md Steps to install the Rust programming language and essential development tools like cargo-watch, cargo-audit, and cargo-tarpaulin. ```bash # Install Rust (if not already installed) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Build the project cargo build # Run tests cargo test # Install development tools cargo install cargo-watch cargo install cargo-audit cargo install cargo-tarpaulin ``` -------------------------------- ### Dockerfile for Development Tools with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md A Dockerfile designed for development, installing Turbo CDN, downloading essential development tools like ripgrep, fd, and bat using Turbo CDN, and making them available in the PATH. ```dockerfile # Dockerfile.tools FROM ubuntu:22.04 # Install Turbo CDN and development tools RUN apt-get update && apt-get install -y curl git && \ curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz && \ mv turbo-cdn /usr/local/bin/ # Download development tools with Turbo CDN WORKDIR /tools RUN turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz" && \ turbo-cdn dl "https://github.com/sharkdp/fd/releases/download/v8.7.0/fd-v8.7.0-x86_64-unknown-linux-gnu.tar.gz" && \ turbo-cdn dl "https://github.com/sharkdp/bat/releases/download/v0.24.0/bat-v0.24.0-x86_64-unknown-linux-gnu.tar.gz" # Extract tools RUN for archive in *.tar.gz; do tar -xf "$archive"; done && \ find . -name "rg" -o -name "fd" -o -name "bat" | xargs -I {} cp {} /usr/local/bin/ # Verify tools RUN rg --version && fd --version && bat --version WORKDIR /workspace ``` -------------------------------- ### Download Node.js Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading a specific version of Node.js for Windows using the Turbo CDN CLI. ```bash # Download Node.js turbo-cdn dl "https://nodejs.org/dist/v20.10.0/node-v20.10.0-win-x64.zip" ``` -------------------------------- ### Docker Compose: Development Environment Setup Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md A Docker Compose configuration for a development environment that includes an application service, a downloader service using a custom Dockerfile, and a database service. It utilizes volumes for caching and dependency management with Turbo CDN. ```yaml # docker-compose.dev.yml version: '3.8' services: app: build: context: . dockerfile: Dockerfile.dev args: - TURBO_CDN_CACHE_DIR=/cache volumes: - .:/app - turbo-cdn-cache:/cache - node_modules:/app/node_modules ports: - "3000:3000" environment: - NODE_ENV=development - TURBO_CDN_CACHE_DIR=/cache depends_on: - downloader downloader: build: context: . dockerfile: Dockerfile.downloader volumes: - turbo-cdn-cache:/cache environment: - TURBO_CDN_CACHE_DIR=/cache database: image: postgres:15 environment: - POSTGRES_DB=myapp - POSTGRES_USER=user - POSTGRES_PASSWORD=password volumes: - postgres_data:/var/lib/postgresql/data volumes: turbo-cdn-cache: node_modules: postgres_data: ``` -------------------------------- ### GitHub Actions Workflow Permissions Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/RELEASE_PLZ_SETUP.md Configure repository settings to grant necessary permissions for GitHub Actions, including read/write access and the ability to create/approve pull requests. This ensures the release-plz workflow can operate correctly. ```YAML name: Release-plz Setup # ... other workflow configurations ... permissions: contents: read pull-requests: write actions: read # ... rest of the workflow ... ``` -------------------------------- ### Download Python Packages Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading a Python package (Django) source archive using the Turbo CDN CLI. ```bash # Python packages turbo-cdn dl "https://files.pythonhosted.org/packages/source/d/django/Django-4.2.7.tar.gz" ``` -------------------------------- ### Install Turbo CDN via Cargo Source: https://github.com/loonghao/turbo-cdn/blob/main/README.md Installs the Turbo CDN command-line tool from crates.io using the Cargo package manager. This is the recommended method for quick installation. ```Bash cargo install turbo-cdn ``` -------------------------------- ### Download npm Packages Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md Example of downloading a specific version of an npm package (React) using the Turbo CDN CLI. ```bash # npm packages turbo-cdn dl "https://registry.npmjs.org/react/-/react-18.2.0.tgz" ``` -------------------------------- ### Turbo CDN Rust API Basic Usage Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/README.md Provides an example of basic API usage in Rust for Turbo CDN. This involves initializing the client and performing URL optimization and downloads. ```rust ๐Ÿš€ Turbo CDN - Basic Usage Example ================================== ๐Ÿ“ก Initializing Turbo CDN client... โœ… Client initialized successfully! ๐Ÿ” Example 1: URL Optimization ------------------------------ Original URL: https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip โœ… Optimized URL: https://ghproxy.net/https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip ๐Ÿš€ CDN optimization available! ๐Ÿ“ฅ Example 2: Simple Download ----------------------------- Downloading: https://github.com/sharkdp/fd/releases/download/v8.7.0/fd-v8.7.0-x86_64-pc-windows-msvc.zip โœ… Download completed! ๐Ÿ“ Path: C:\Users\user\AppData\Local\Temp\fd-v8.7.0-x86_64-pc-windows-msvc.zip ๐Ÿ“Š Size: 1125481 bytes โšก Speed: 0.87 MB/s โฑ๏ธ Duration: 1.29s ``` -------------------------------- ### Basic Async Usage of turbo-cdn Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md Demonstrates the basic asynchronous usage of the AsyncTurboCdn client to optimize a given URL. ```rust use turbo_cdn::async_api::AsyncTurboCdn; #[tokio::main] async fn main() -> Result<(), Box> { // Create async client let cdn = AsyncTurboCdn::new().await?; // Optimize any URL let optimal_url = cdn.get_optimal_url_async( "https://github.com/oven-sh/bun/releases/download/bun-v1.2.9/bun-bun-v1.2.9.zip" ).await?; println!("Optimal URL: {}", optimal_url); Ok(()) } ``` -------------------------------- ### Rust Unit Test Example Source: https://github.com/loonghao/turbo-cdn/blob/main/CONTRIBUTING.md An example of a unit test in Rust using the tokio runtime. It demonstrates arranging dependencies, acting on a function, and asserting the expected outcome for a download operation. ```Rust #[cfg(test)] mod tests { use super::*; #[tokio::test] async fn test_download_success() { // Arrange let downloader = create_test_downloader().await; // Act let result = downloader.download("test/repo", "v1.0.0", "file.zip").await; // Assert assert!(result.is_ok()); } } ``` -------------------------------- ### Committing Changes with Signed-off-by Source: https://github.com/loonghao/turbo-cdn/blob/main/CONTRIBUTING.md Example of how to stage all changes, commit them with a descriptive message including a feature description, and add a 'Signed-off-by' trailer. ```bash git add . git commit -m "feat: add new download source support - Add support for custom CDN sources - Implement source validation - Add comprehensive tests - Update documentation Signed-off-by: Your Name " ``` -------------------------------- ### Get Optimal CDN URL Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This command finds and returns the best CDN URL for a given file without actually downloading it. It's useful for pre-checking or getting CDN-ready links. ```bash turbo-cdn optimize "https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-pc-windows-msvc.zip" ``` -------------------------------- ### Dockerfile: Downloader Service Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md A Dockerfile for a downloader service that installs Turbo CDN and a custom download script, setting the cache directory environment variable. ```dockerfile FROM ubuntu:22.04 # Install Turbo CDN RUN apt-get update && apt-get install -y curl && \ curl -L https://github.com/loonghao/turbo-cdn/releases/latest/download/turbo-cdn-x86_64-unknown-linux-gnu.tar.gz | tar xz && \ mv turbo-cdn /usr/local/bin/ && \ chmod +x /usr/local/bin/turbo-cdn # Copy download script COPY scripts/download-deps.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/download-deps.sh # Set cache directory ENV TURBO_CDN_CACHE_DIR=/cache # Run downloader CMD ["download-deps.sh"] ``` -------------------------------- ### Download Windows Executables Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/advanced_usage.md Examples of downloading Windows-specific executables and utilities using Turbo CDN, including the Windows Package Manager installer and PowerToys. ```bash # Windows development tools turbo-cdn dl "https://github.com/microsoft/winget-cli/releases/download/v1.6.2771/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" ``` ```bash # Windows utilities turbo-cdn dl "https://github.com/microsoft/PowerToys/releases/download/v0.76.2/PowerToysUserSetup-0.76.2-x64.exe" ``` -------------------------------- ### Turbo CDN CLI Basic Download Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/README.md Demonstrates the basic download command for Turbo CDN CLI. It takes a URL as input and downloads the file. ```bash turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip" ``` -------------------------------- ### Check Turbo CDN Version Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This command allows you to check the currently installed version of the Turbo CDN CLI. It's useful for ensuring you have the latest features or for compatibility checks. ```bash turbo-cdn version ``` ```bash # or turbo-cdn --version ``` -------------------------------- ### Add Cargo Registry Token Secret Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/RELEASE_PLZ_SETUP.md Store your crates.io registry token as a repository secret. This is necessary for publishing crates to crates.io via the release-plz workflow. ```Shell # In GitHub Repository Settings -> Secrets and variables -> Actions # Add secret: # CARGO_REGISTRY_TOKEN: ``` -------------------------------- ### Download File with CDN Optimization Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This command downloads a file from a given URL, automatically optimizing it for CDN delivery. It's the simplest way to get a file using Turbo CDN. ```bash turbo-cdn dl "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip" ``` -------------------------------- ### AsyncTurboCdn Creation Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md Shows how to create an AsyncTurboCdn client, both with default settings and with custom configurations like region, caching, and concurrent downloads. ```rust // Simple creation let cdn = AsyncTurboCdn::new().await?; // With custom configuration let cdn = AsyncTurboCdnBuilder::new() .with_region(Region::Global) .with_cache(true) .with_max_concurrent_downloads(8) .build() .await?; ``` -------------------------------- ### Add Personal Access Token (PAT) Secret Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/RELEASE_PLZ_SETUP.md Add your GitHub Personal Access Token (PAT) as a repository secret. This token is used for authentication if the GitHub App is not configured or as a fallback. ```Shell # In GitHub Repository Settings -> Secrets and variables -> Actions # Add secret: # RELEASE_PLZ_TOKEN: ``` -------------------------------- ### Add GitHub App Secrets to Repository Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/RELEASE_PLZ_SETUP.md Store your GitHub App ID and private key as repository secrets in GitHub Actions. This allows the workflow to authenticate securely using the GitHub App. ```Shell # In GitHub Repository Settings -> Secrets and variables -> Actions # Add secrets: # APP_ID: # APP_PRIVATE_KEY: ``` -------------------------------- ### Bash: Download Files from URL List Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/batch_operations.md A bash script that reads URLs from a file named `urls.txt` and downloads each one using `turbo-cdn dl`. It skips empty lines and lines starting with '#'. ```bash #!/bin/bash # download_from_list.sh while IFS= read -r url; do if [[ ! -z "$url" && ! "$url" =~ ^# ]]; then echo "๐Ÿ“ฅ Downloading: $url" turbo-cdn dl "$url" fi done < urls.txt ``` -------------------------------- ### Cloning and Setting Up Remote Repository Source: https://github.com/loonghao/turbo-cdn/blob/main/CONTRIBUTING.md Instructions for forking the Turbo CDN repository, cloning it locally, and adding the upstream remote for tracking changes. ```bash git clone https://github.com/YOUR_USERNAME/turbo-cdn.git cd turbo-cdn git remote add upstream https://github.com/loonghao/turbo-cdn.git ``` -------------------------------- ### Development Docker Compose Configuration Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md Sets up the development environment using Docker Compose, including the application service with volume mounts for code synchronization and debugging, and a tools service for development utilities. ```yaml # docker-compose.dev.yml version: '3.8' services: app: build: context: . dockerfile: Dockerfile.dev volumes: - .:/app - /app/node_modules - turbo-cdn-cache:/cache ports: - "3000:3000" - "9229:9229" # Debug port environment: - NODE_ENV=development - DEBUG=* command: npm run dev tools: build: context: . dockerfile: Dockerfile.tools volumes: - .:/workspace - turbo-cdn-cache:/cache working_dir: /workspace command: tail -f /dev/null volumes: turbo-cdn-cache: ``` -------------------------------- ### Check Multiple URLs for Optimization Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/cli/basic_download.md This demonstrates how to use the optimize command for different types of URLs, including GitHub releases, npm packages, and Python packages, to find their optimal CDN links. ```bash # GitHub release turbo-cdn optimize "https://github.com/sharkdp/fd/releases/download/v8.7.0/fd-v8.7.0-x86_64-pc-windows-msvc.zip" ``` ```bash # npm package turbo-cdn optimize "https://registry.npmjs.org/express/-/express-4.18.2.tgz" ``` ```bash # Python package turbo-cdn optimize "https://files.pythonhosted.org/packages/source/r/requests/requests-2.31.0.tar.gz" ``` -------------------------------- ### Batch URL Processing with Turbo CDN Source: https://github.com/loonghao/turbo-cdn/blob/main/docs/VX_INTEGRATION.md Processes a vector of URLs concurrently using the AsyncTurboCdn client. It spawns a tokio task for each URL to get the optimal URL asynchronously and collects the results, handling potential errors during processing or task execution. ```rust use turbo_cdn::async_api::AsyncTurboCdn; pub async fn process_urls(urls: Vec) -> Result, Box> { let cdn = AsyncTurboCdn::new().await?; // Process all URLs concurrently let tasks: Vec<_> = urls .into_iter() .map(|url| { let cdn = cdn.clone(); tokio::spawn(async move { cdn.get_optimal_url_async(&url).await }) }) .collect(); let results = futures::future::join_all(tasks).await; let mut optimized_urls = Vec::new(); for result in results { match result { Ok(Ok(url)) => optimized_urls.push(url), Ok(Err(e)) => eprintln!("URL optimization failed: {}", e), Err(e) => eprintln!("Task failed: {}", e), } } Ok(optimized_urls) } ``` -------------------------------- ### Bash Commands for Docker Build Performance Comparison Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/integration/docker_usage.md Compares the build time of Docker images using traditional methods versus Turbo CDN optimization. It executes Docker builds with timing and specifies different Dockerfile targets. ```bash # Traditional Docker build time docker build -t myapp:traditional . # Result: ~8-12 minutes # With Turbo CDN optimization time docker build -t myapp:turbo-cdn -f Dockerfile.turbo-cdn . ``` -------------------------------- ### Configure Downloads for Connection Speed (Rust) Source: https://github.com/loonghao/turbo-cdn/blob/main/examples/performance/tuning.md Provides Rust code examples for configuring Turbo CDN download options based on connection speed. It defines optimal `max_concurrent_chunks`, `chunk_size`, `enable_resume`, `timeout_override`, and `verify_integrity` for high, medium, and low-speed connections. ```rust use turbo_cdn::DownloadOptions; use std::time::Duration; // High-speed connections (100+ Mbps) let high_speed_config = DownloadOptions { max_concurrent_chunks: Some(16), chunk_size: Some(4 * 1024 * 1024), // 4MB enable_resume: true, timeout_override: Some(Duration::from_secs(300)), verify_integrity: false, // Skip for maximum speed ..Default::default() }; // Medium-speed connections (25-100 Mbps) let medium_speed_config = DownloadOptions { max_concurrent_chunks: Some(8), chunk_size: Some(2 * 1024 * 1024), // 2MB enable_resume: true, timeout_override: Some(Duration::from_secs(180)), verify_integrity: true, ..Default::default() }; // Low-speed connections (<25 Mbps) let low_speed_config = DownloadOptions { max_concurrent_chunks: Some(4), chunk_size: Some(1024 * 1024), // 1MB enable_resume: true, timeout_override: Some(Duration::from_secs(120)), verify_integrity: true, ..Default::default() }; ```