Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions ushadow/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ FROM python:3.12-slim AS builder

WORKDIR /app

# Install uv for fast Python package management
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

# Install build dependencies for Python packages (gcc, python3-dev, libyaml-dev)
# Install build dependencies for Python packages (gcc, python3-dev, libyaml-dev, curl for uv install)
RUN apt-get update && apt-get install -y \
gcc \
python3-dev \
libyaml-dev \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install uv for fast Python package management
# Using official installation script (recommended method)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
ln -s /root/.local/bin/uv /usr/local/bin/uv && \
ln -s /root/.local/bin/uvx /usr/local/bin/uvx

# Copy dependency files first for better layer caching
COPY pyproject.toml uv.lock ./

Expand All @@ -32,10 +36,7 @@ FROM python:3.12-slim

WORKDIR /app

# Install uv for running the app
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

# Install only runtime dependencies (curl for healthcheck, docker-cli for volume cleanup, tailscale)
# Install runtime dependencies (curl for healthcheck and uv install, docker-cli for volume cleanup, tailscale)
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
Expand All @@ -49,6 +50,12 @@ RUN apt-get update && apt-get install -y \
&& curl -fsSL https://tailscale.com/install.sh | sh \
&& rm -rf /var/lib/apt/lists/*

# Install uv for running the app
# Using official installation script (recommended method)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
ln -s /root/.local/bin/uv /usr/local/bin/uv && \
ln -s /root/.local/bin/uvx /usr/local/bin/uvx

# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv

Expand Down
2 changes: 1 addition & 1 deletion ushadow/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# Telemetry configuration
TELEMETRY_ENDPOINT = os.environ.get(
"TELEMETRY_ENDPOINT",
"https://ushadow-telemetry.your-subdomain.workers.dev"
"https://ushadow-telemetry.stu-6b7.workers.dev"
)


Expand Down
28 changes: 23 additions & 5 deletions ushadow/backend/src/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TelemetryClient:

def __init__(
self,
endpoint: str = "https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint: str = "https://ushadow-telemetry.stu-6b7.workers.dev",
app_version: str = "unknown",
config_dir: Optional[Path] = None,
):
Expand All @@ -43,6 +43,16 @@ def __init__(
self.machine_id = self._get_or_create_machine_id()
self.os_info = self._get_os_info()

def is_telemetry_disabled(self) -> bool:
"""
Check if telemetry has been disabled by the user.

Returns:
True if telemetry is disabled, False otherwise
"""
telemetry_disabled_file = self.config_dir / "telemetry_disabled"
return telemetry_disabled_file.exists()

def _get_or_create_machine_id(self) -> str:
"""
Get or create a stable machine identifier.
Expand Down Expand Up @@ -122,8 +132,12 @@ def send_ping(self, timeout: int = 5) -> bool:
timeout: Request timeout in seconds

Returns:
True if ping succeeded, False otherwise
True if ping succeeded, False otherwise (including if telemetry is disabled)
"""
# Check if telemetry is disabled
if self.is_telemetry_disabled():
return False

try:
data = {
'machine_id': self.machine_id,
Expand Down Expand Up @@ -157,8 +171,12 @@ def send_install_event(self, install_method: str = "unknown", timeout: int = 5)
timeout: Request timeout in seconds

Returns:
True if event sent successfully, False otherwise
True if event sent successfully, False otherwise (including if telemetry is disabled)
"""
# Check if telemetry is disabled
if self.is_telemetry_disabled():
return False

try:
data = {
'machine_id': self.machine_id,
Expand All @@ -185,7 +203,7 @@ def send_install_event(self, install_method: str = "unknown", timeout: int = 5)

# Convenience function for simple usage
def send_telemetry_ping(
endpoint: str = "https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint: str = "https://ushadow-telemetry.stu-6b7.workers.dev",
app_version: str = "unknown"
) -> bool:
"""
Expand All @@ -205,7 +223,7 @@ def send_telemetry_ping(
if __name__ == "__main__":
# Example usage
client = TelemetryClient(
endpoint="https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint="https://ushadow-telemetry.stu-6b7.workers.dev",
app_version="0.2.4"
)

Expand Down
14 changes: 14 additions & 0 deletions ushadow/backend/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions ushadow/manager/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TelemetryClient:

def __init__(
self,
endpoint: str = "https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint: str = "https://ushadow-telemetry.stu-6b7.workers.dev",
app_version: str = "unknown",
config_dir: Optional[Path] = None,
):
Expand All @@ -43,6 +43,16 @@ def __init__(
self.machine_id = self._get_or_create_machine_id()
self.os_info = self._get_os_info()

def is_telemetry_disabled(self) -> bool:
"""
Check if telemetry has been disabled by the user.

Returns:
True if telemetry is disabled, False otherwise
"""
telemetry_disabled_file = self.config_dir / "telemetry_disabled"
return telemetry_disabled_file.exists()

def _get_or_create_machine_id(self) -> str:
"""
Get or create a stable machine identifier.
Expand Down Expand Up @@ -122,8 +132,12 @@ def send_ping(self, timeout: int = 5) -> bool:
timeout: Request timeout in seconds

Returns:
True if ping succeeded, False otherwise
True if ping succeeded, False otherwise (including if telemetry is disabled)
"""
# Check if telemetry is disabled
if self.is_telemetry_disabled():
return False

try:
data = {
'machine_id': self.machine_id,
Expand Down Expand Up @@ -157,8 +171,12 @@ def send_install_event(self, install_method: str = "unknown", timeout: int = 5)
timeout: Request timeout in seconds

Returns:
True if event sent successfully, False otherwise
True if event sent successfully, False otherwise (including if telemetry is disabled)
"""
# Check if telemetry is disabled
if self.is_telemetry_disabled():
return False

try:
data = {
'machine_id': self.machine_id,
Expand All @@ -185,7 +203,7 @@ def send_install_event(self, install_method: str = "unknown", timeout: int = 5)

# Convenience function for simple usage
def send_telemetry_ping(
endpoint: str = "https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint: str = "https://ushadow-telemetry.stu-6b7.workers.dev",
app_version: str = "unknown"
) -> bool:
"""
Expand All @@ -205,7 +223,7 @@ def send_telemetry_ping(
if __name__ == "__main__":
# Example usage
client = TelemetryClient(
endpoint="https://ushadow-telemetry.your-subdomain.workers.dev",
endpoint="https://ushadow-telemetry.stu-6b7.workers.dev",
app_version="0.2.4"
)

Expand Down
Loading