Store and serve firmware from database#11
Open
aveao wants to merge 8 commits intopebble-dev:masterfrom
Open
Conversation
Firmwares now live in a `firmwares` table keyed by (hardware, kind, version) rather than being read from config.json at import time. /cohort?select=fw returns the latest row per kind ordered by timestamp, so multiple versions per (hardware, kind) are allowed and rollbacks work by submitting an older version with a newer timestamp. config.json stays in-repo only as seed data for the new `flask import_json` CLI command; future edits go through `flask submit_firmware HARDWARE KIND VERSION URL SHA256 [--timestamp] [--notes]`. Follows the pattern in pebble-dev/rebble-lp#8 minus S3 (firmware blobs stay on the CDN) and rws-common (deferred). Deployments now need DATABASE_URL set and `flask db upgrade` run before serving; see README.
`docker compose up --build` now brings up Postgres plus the app container (built from the existing Dockerfile), auto-runs `flask db upgrade` on app start, and exposes the API on localhost:5000. Source is bind-mounted so serve_debug.py's reloader picks up edits; the image's .venv is preserved via an anonymous volume so the bind-mount doesn't shadow it. import_json still has to be run once after first bring-up (documented in README); subsequent schema changes re-apply automatically on container restart.
…y flag /cohort?select=fw used to return normal + recovery for the given hardware; now it returns only normal. Clients that need the recovery firmware can pass &includeRecovery=true — only the literal string `true` is recognized. generate_fw now accepts a kinds tuple and runs one DB query per kind, so unused kinds never hit the DB. The HTTP wrapper parses the query param and picks the kinds; 400 is still returned when none of the requested kinds have a row for the hardware.
api.py now only holds HTTP concerns (routes, generate_fw, optional_auth). cli.py holds import_json, submit_firmware, the shared _upsert_firmware helper, and VALID_FW_KINDS, with its own init_app that registers the click commands. cohorts/__init__.py calls both init_api and init_cli.
…sent mobilePlatform, mobileVersion, mobileHardware, and pebbleAppVersion are now all optional on /cohort?select=fw. Whichever of them are present on the request get attached to the beeline trace (previously only mobilePlatform and pebbleAppVersion ever did, and all four were required). hardware stays required as the lookup key.
457aeaf to
b309a28
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plus CLI commands, README, docker-compose (for local runs).