|
| 1 | +# Publishing & Syncing Data (DVC) |
| 2 | + |
| 3 | +EPM **code** is public, but the **data** (input CSVs, results) is kept in a **private |
| 4 | +store** — not in this public repository. The repo only keeps tiny **pointers**; the real |
| 5 | +data lives in the store and is fetched on demand. |
| 6 | + |
| 7 | +This page explains, from scratch, how to **publish** your data and how to **get it back** |
| 8 | +on another machine or on the server. No prior knowledge of DVC is assumed. |
| 9 | + |
| 10 | +!!! note "Prototype" |
| 11 | + The store is currently a Cloudflare R2 bucket (test data). For confidential data, |
| 12 | + the production store will be the World Bank S3 — same workflow, different endpoint. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## The idea in one picture |
| 17 | + |
| 18 | +``` |
| 19 | +YOU (laptop) — you edit inputs/outputs in EPM |
| 20 | + │ |
| 21 | + │ one action (double-click Publish): |
| 22 | + │ ├─ git push → GitHub : code + .dvc pointers (no data) |
| 23 | + │ ├─ dvc push → STORE : the data (for runs) |
| 24 | + │ └─ publish → STORE : a readable copy (for EPM View) |
| 25 | + ▼ |
| 26 | + ┌──────────────── PRIVATE STORE (R2 / S3) ────────────────┐ |
| 27 | + └───────────────┬─────────────────────────┬──────────────┘ |
| 28 | + │ dvc pull │ gated read |
| 29 | + SERVER (run the model) EPM View (display) |
| 30 | +``` |
| 31 | + |
| 32 | +**What is DVC?** Think *"git for data"*. Git stays light because the data is replaced by a |
| 33 | +6-line pointer file (`*.dvc` = a hash + a path, **no values**). The real data lives in the |
| 34 | +store, moved with `dvc push` / `dvc pull`. |
| 35 | + |
| 36 | +The store keeps **two layouts** of the same data: a hash-addressed copy for DVC (runs), and |
| 37 | +a readable copy by path for EPM View (the browser can't speak DVC). Both are written by the |
| 38 | +same "publish" action — you don't manage this by hand. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## One-time setup (per machine) |
| 43 | + |
| 44 | +1. Install the dependencies (DVC is included): |
| 45 | + ```bash |
| 46 | + pip install -r requirements.txt |
| 47 | + ``` |
| 48 | +2. Add your store keys: copy `tools/.env.example` to `tools/.env` and paste the 4 values |
| 49 | + (ask the store admin). |
| 50 | + ``` |
| 51 | + tools/.env ← your keys (git-ignored — NEVER commit real keys) |
| 52 | + tools/.env.example ← template |
| 53 | + ``` |
| 54 | + |
| 55 | +That's it. The remote URL/endpoint is already in the repo (`.dvc/config`). |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Publish your data |
| 60 | + |
| 61 | +After you change inputs (or want to show results), **publish in one action**: |
| 62 | + |
| 63 | +=== "Windows" |
| 64 | + Double-click **`Publish.bat`** at the repo root. |
| 65 | + |
| 66 | +=== "Command line" |
| 67 | + ```bash |
| 68 | + powershell -File tools/publish.ps1 # Windows |
| 69 | + ``` |
| 70 | + |
| 71 | +This does everything: re-hash the data (`dvc add`) → commit + push the pointer → |
| 72 | +`dvc push` (data to the store, for the server) → upload readable copies (inputs + |
| 73 | +`epm/output_view/`) for EPM View. |
| 74 | + |
| 75 | +!!! tip "Showing results in EPM View" |
| 76 | + Copy the runs you want to display into |
| 77 | + `epm/output_view/<run>/<scenario>/output_csv/` **before** publishing (only `.csv` |
| 78 | + files are sent). `epm/output_view/` is a local staging folder (git-ignored). |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Get the data (another machine / the server) |
| 83 | + |
| 84 | +=== "Server (Linux)" |
| 85 | + ```bash |
| 86 | + bash tools/sync.sh |
| 87 | + ``` |
| 88 | +=== "Windows" |
| 89 | + Double-click **`Sync.bat`**. |
| 90 | + |
| 91 | +This runs `git pull` (code + pointers) then `dvc pull` (data from the store) — then you can |
| 92 | +run the model with up-to-date data. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Onboarding a new model (one-time per model) |
| 97 | + |
| 98 | +Moving a model's data out of git into the store (the "switch"): |
| 99 | + |
| 100 | +```bash |
| 101 | +dvc init # once per repo |
| 102 | +dvc remote add -d store s3://<bucket>/dvcstore |
| 103 | +dvc remote modify store endpointurl <endpoint> |
| 104 | +# in .gitignore: remove the whitelist of the data folder, add !epm/input/<data>.dvc |
| 105 | +git rm -r --cached epm/input/<data_folder> # untrack (files stay on disk) |
| 106 | +dvc add epm/input/<data_folder> # create the pointer |
| 107 | +``` |
| 108 | +Then publish (`Publish.bat`). After this, everyone just does *setup + publish/sync*. |
| 109 | + |
| 110 | +To make **EPM View** read this branch from the store, add the branch name to `R2_BRANCHES` |
| 111 | +in `src/utils/epmFetch.js` of the `epm-data-explorer` repo. |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Troubleshooting |
| 116 | + |
| 117 | +- **`Unable to locate credentials`** → keys not loaded. On the server, either |
| 118 | + `export AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=…`, or set them once with |
| 119 | + `dvc remote modify --local store access_key_id …` (stays in git-ignored `config.local`). |
| 120 | +- **`CERTIFICATE_VERIFY_FAILED` / SSL** → a corporate TLS proxy is intercepting the |
| 121 | + connection. Try off-VPN, or `pip install pip-system-certs` (makes Python trust the OS |
| 122 | + certificate store). The AWS server is not affected. |
| 123 | +- **`dvc` command not found** (server) → use `python -m dvc …`, or add `~/.local/bin` to |
| 124 | + your `PATH`. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Files (in `tools/`) |
| 129 | + |
| 130 | +| File | Role | |
| 131 | +|------|------| |
| 132 | +| `publish.ps1` | engine behind `Publish.bat` | |
| 133 | +| `sync.ps1` / `sync.sh` | get code + data (Windows / server) | |
| 134 | +| `upload_to_r2.py`, `upload_output_view_to_r2.py` | upload the readable copies | |
| 135 | +| `.env.example` | keys template (copy to `.env`, git-ignored) | |
0 commit comments