File size: 2,510 Bytes
bc63d7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Agent.md

This file documents tricks, ongoing deployment best practices, and API configurations for deploying Matomo to Hugging Face Spaces.

## 1. Deployment Configuration

### Target Space
- **Profile:** `Leon4gr45`  
- **Space:** `matomo`  
- **Full Identifier:** `Leon4gr45/matomo`  
- **Frontend Port:** `7860` (mandatory for all Hugging Face Spaces)

### Deployment Method
- **Docker SDK:** Configured with custom Dockerfile to containerize Matomo with light-weight PHP server capabilities.

### HF Token
- Loaded from environment variable `HF_TOKEN`.
- Never hardcode the token.

### Required Files
- `Dockerfile` (exposes port 7860 and serves the app)
- `README.md` with YAML frontmatter pointing to `sdk: docker` and `app_port: 7860`
- `.hfignore` to prevent uploading massive unnecessary logs or cache files
- `Agent.md` (this file)

---

## 2. API Exposure and Documentation

### Mandatory Endpoints
Every deployment exposes:

- **`/health`**  
  - **Method:** GET  
  - **Purpose:** Health check returning HTTP 200 when ready.  
  - **Response Example:**
    ```json
    {
      "status": "healthy",
      "app": "matomo"
    }
    ```

- **`/api-docs`**  
  - **Method:** GET  
  - **Purpose:** Documents all available API endpoints.  
  - **Response Example:**
    ```json
    {
      "openapi": "3.0.0",
      "info": {
        "title": "Matomo Hugging Face API",
        "version": "1.0.0"
      },
      "paths": {
        "/health": {
          "get": {
            "summary": "Health check",
            "responses": {
              "200": {
                "description": "App is healthy"
              }
            }
          }
        },
        "/api-docs": {
          "get": {
            "summary": "API Documentation",
            "responses": {
              "200": {
                "description": "API Schema"
              }
            }
          }
        }
      }
    }
    ```

---

## 3. Deployment Workflow

### Precondition
Ensure the space is empty of files not belonging to the project. Use the hub CLI to delete them first if any.

### Standard Deployment Command
To deploy any local modifications, execute:
```bash
hf upload Leon4gr45/matomo --repo-type=space
```

### Logs Monitoring
Build logs (SSE):
```bash
curl -N -H "Authorization: Bearer <HF_TOKEN>" "https://huggingface.co/api/spaces/Leon4gr45/matomo/logs/build"
```

Run logs (SSE):
```bash
curl -N -H "Authorization: Bearer <HF_TOKEN>" "https://huggingface.co/api/spaces/Leon4gr45/matomo/logs/run"
```