How frerich/auto_updater works
Project type and purpose
• This is an Elixir library (Mix application) named AutoUpdater.
• Its purpose is to automatically fetch and deploy new Mix releases (tarballs) on Linux or macOS.
• It provides an OTP application that watches for new releases and secrets, downloads updates from different storage backends, and installs/deploys them.
File structure
• Top-level files:
• mix.exs, mix.lock: Elixir project configuration and dependencies.
• lib/auto_updater: main application code.
• test/: unit tests for each module and storage adapter.
• lib/auto_updater/application.ex: defines the OTP supervision tree.
• lib/auto_updater/release_watcher.ex & secrets_watcher.ex: GenServers monitoring for new releases or secret changes.
• lib/auto_updater/storage/*.ex: behaviour and adapters (GitHub, S3, local).
• lib/auto_updater/secrets/*.ex: behaviour and adapters (encrypted JSON, local, AWS Secrets Manager).
• lib/auto_updater/deploy.ex & installation.ex: modules handling unpacking tarballs and performing the actual update on disk.
• Configuration and extensibility points: storage and secrets behaviours with multiple implementations.
README for additional insights
• Key detail: distribution as tar.gz Mix releases.
• Focus of the library: periodic polling or event-based watching of external storage, secure retrieval of secrets, controlled installation and deployment of updated software.
a. Main components
• OTP Application (Supervisor)
• ReleaseWatcher (GenServer)
• SecretsWatcher (GenServer)
• Storage Behaviour + Adapters
• Secrets Behaviour + Adapters
• Installation module
• Deploy module
• External Systems: GitHub, S3, Local FS, Secrets Manager
• Local disk (where new release tarballs and extracted files live)
b. Relationships and interactions
1. Supervisor starts watchers and core modules.
2. ReleaseWatcher polls or subscribes to Storage Adapter → asks for versions or tarball URLs.
3. Storage Adapter communicates with external storage (GitHub API, AWS S3 API, or local directory).
4. SecretsWatcher polls or subscribes to Secrets Adapter → fetches decryption keys or credentials.
5. On detection of new release:
– ReleaseWatcher emits an “update available” event.
– Installation module downloads the tarball via Storage Adapter, passes through Secrets module if encrypted.
– Installation module extracts the Mix release to a staging directory.
– Deploy module switches symlinks or moves directories to activate the new release.
6. Optional: Secrets module decrypts configuration, writes local secret files for the application.
c. Architectural patterns and principles
• OTP Supervision Tree for fault tolerance.
• Behaviour + Adapter pattern for pluggable storages and secrets backends.
• Event-driven watchers (polling or push) decoupled from installation/deployment.
• Single Responsibility: each module focuses on one concern (watching, storage, secrets, deployment).
d. Relevant technologies and frameworks
• Elixir/OTP (GenServer, Supervisor)
• Mix releases (tar.gz)
• HTTP/HTTPS APIs for GitHub and AWS S3
• JSON parsing and encryption libraries (for encrypted_json_file)
• File system operations