Log in
Linked Applications
Loading…
Spaces
Glossaries
Create
Create
Hit enter to search
Announcement Banner
Help
Online Help
Keyboard Shortcuts
Feed Builder
What’s new
Available Gadgets
About Confluence
Log in
Cash Collection Wiki
Pages
…
Cash Collection Wiki Home
Digital Mining
SolvExtract
MQTT
Deployment
Deployment
search
attachments
weblink
advanced
image-effects
image-attributes
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
Colour picker
More colours
Formatting
Strikethrough
Subscript
Superscript
Monospace
Clear formatting
Bullet list
Numbered list
Task list
Outdent
Indent
Align left
Align center
Align right
Page layout
Link
Table
Insert
Insert content
Files and images
Link
Markup
Horizontal rule
Task list
Date
Symbol
Insert macro
User mention
Jira Issue/Filter
Info
Add Lucidchart Diagram
draw.io Diagram
Embed draw.io Diagram
draw.io Board Diagram
Status
Gallery
Table of Contents
Google Drive Live Link
Embedded Google Drive Folder
Embedded Google Drive File
Google Drive Search Result
Other macros
Page layout
No layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard shortcuts help
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account.
This page is also being edited by
. Your changes will be merged with theirs when you save.
<h1>Deployment</h1><h3 style="text-align: left;">1. Project Overview</h3><p style="text-align: left;"><strong>Purpose and Scope:</strong><br />This deployment setup provisions a containerized MQTT server and subscriber application for Freeport FMI, supporting development, pre-production, and production environments. It orchestrates the Mosquitto MQTT broker and a Python-based subscriber (which bridges MQTT to Google Cloud Pub/Sub and BigQuery) using Docker and Supervisor, and deploys the stack to Google Cloud Platform (GCP) using flexible environment configurations.</p><p style="text-align: left;"><strong>Primary Use Cases:</strong></p><ul style="text-align: left;"><li>Reliable ingestion of sensor data via MQTT.</li><li>Forwarding of sensor data to cloud analytics and event processing pipelines.</li><li>Environment-specific deployments (DEV, PPRD, PRD) with tailored resources and credentials.</li></ul><p style="text-align: left;"><strong>Explicitly Not Handled:</strong></p><ul style="text-align: left;"><li>Automated scaling beyond a single instance per environment.</li><li>Secure, production-grade MQTT (no TLS/mTLS or authentication in current config).</li><li>Downstream analytics or visualization (handled elsewhere).</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">2. System Architecture</h3><p style="text-align: left;"><strong>Core Components and Responsibilities:</strong></p><ul style="text-align: left;"><li><strong>Docker Container:</strong><span> </span>Bundles Mosquitto broker, Python subscriber, and Supervisor for process management.</li><li><strong>Mosquitto Broker:</strong><span> </span>Handles MQTT connections and message routing.</li><li><strong>Python Subscriber:</strong><span> </span>Consumes MQTT messages, publishes to Pub/Sub, and writes to BigQuery.</li><li><strong>Supervisor:</strong><span> </span>Ensures both Mosquitto and the subscriber run reliably within the container.</li><li><strong>GCP Flexible Environment:</strong><span> </span>Hosts the container, manages networking, scaling, and health checks.</li></ul><p style="text-align: left;"><strong>Data and Control Flow:</strong></p><ol style="text-align: left;"><li>MQTT clients publish sensor data to Mosquitto broker (port 1883).</li><li>Python subscriber listens to MQTT topics, processes messages, and forwards them to Pub/Sub and BigQuery.</li><li>GCP manages container lifecycle, health checks, and network routing.</li></ol><p style="text-align: left;"><strong>External Services and Dependencies:</strong></p><ul style="text-align: left;"><li>Google Cloud Pub/Sub (for event streaming).</li><li>Google BigQuery (for data storage).</li><li>GCP VPC and IAM (for secure networking and service account access).</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">3. Core Concepts & Domain Logic</h3><p style="text-align: left;"><strong>Key Abstractions and Domain Terms:</strong></p><ul style="text-align: left;"><li><strong>Environment (DEV/PPRD/PRD):</strong><span> </span>Drives configuration, credentials, and resource allocation.</li><li><strong>Supervisor:</strong><span> </span>Manages multiple processes inside the container.</li><li><strong>Service Account:</strong><span> </span>Used for secure access to GCP APIs.</li></ul><p style="text-align: left;"><strong>Business/Technical Invariants:</strong></p><ul style="text-align: left;"><li>Each environment uses its own GCP project, service account, and VPC connector.</li><li>Only one instance runs per environment (no horizontal scaling).</li></ul><p style="text-align: left;"><strong>Mental Model:</strong></p><ul style="text-align: left;"><li>Each deployment is a self-contained MQTT ingestion node, tightly integrated with GCP services and isolated per environment.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">4. Codebase Structure</h3><p style="text-align: left;"><strong>High-level Layout:</strong></p><ul style="text-align: left;"><li><code class="undefined">mqtt_subscriber.py</code>: Python application for MQTT-to-cloud bridging.</li><li><code class="undefined">mosquitto.conf</code>: Mosquitto broker configuration.</li><li><code class="undefined">supervisord.conf</code>: Supervisor configuration for process management.</li><li><code class="undefined">requirements.txt</code>: Python dependencies.</li><li>Dockerfile: Container build instructions.</li><li>Environment-specific YAMLs (<code class="undefined">dev.yml</code>,<span> </span><code class="undefined">pprd.yml</code>,<span> </span><code class="undefined">prd.yml</code>): GCP deployment descriptors.</li><li>CI/CD YAML (<code class="undefined">project-ci.yml</code>): Pipeline and deployment automation.</li></ul><p style="text-align: left;"><strong>Responsibility Boundaries:</strong></p><ul style="text-align: left;"><li>Application logic (Python) vs. infrastructure (Docker, Mosquitto, Supervisor).</li><li>Environment-specific configuration is isolated in separate YAML files.</li></ul><p style="text-align: left;"><strong>What Changes Together:</strong></p><ul style="text-align: left;"><li>Application code and requirements.</li><li>Mosquitto and Supervisor configs.</li><li>Environment YAMLs and CI/CD pipeline.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">5. Configuration & Environment</h3><p style="text-align: left;"><strong>Environment Variables:</strong></p><ul style="text-align: left;"><li>Set in deployment YAMLs (e.g.,<span> </span><code class="undefined">APP_ENV</code>,<span> </span><code class="undefined">GCP_PROJECT_ID</code>,<span> </span><code class="undefined">MQTT_BROKER</code>, etc.).</li><li>Control application behavior and cloud integration.</li></ul><p style="text-align: left;"><strong>Configuration Files:</strong></p><ul style="text-align: left;"><li><code class="undefined">mosquitto.conf</code>: Broker settings.</li><li><code class="undefined">supervisord.conf</code>: Process management.</li><li><code class="undefined">requirements.txt</code>: Python dependencies.</li></ul><p style="text-align: left;"><strong>Differences Between Local, Staging, and Production:</strong></p><ul style="text-align: left;"><li>Each environment uses a different GCP project, service account, VPC connector, and resource allocation.</li><li>Production (<code class="undefined">prd.yml</code>) uses more CPU/memory than DEV/PPRD.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">6. Runtime Behavior</h3><p style="text-align: left;"><strong>Startup Sequence:</strong></p><ul style="text-align: left;"><li>Container starts, Supervisor launches Mosquitto and Python subscriber.</li><li>Mosquitto listens on port 1883.</li><li>Subscriber connects to broker and cloud services.</li></ul><p style="text-align: left;"><strong>Normal Execution Flow:</strong></p><ul style="text-align: left;"><li>MQTT messages are received, processed, and forwarded to cloud.</li><li>Supervisor restarts processes if they fail.</li></ul><p style="text-align: left;"><strong>Error Handling and Logging Strategy:</strong></p><ul style="text-align: left;"><li>Application logs to stdout (captured by GCP logging).</li><li>Mosquitto logs as configured.</li><li>Liveness/readiness checks ensure unhealthy containers are restarted.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">7. Deployment & Operations</h3><p style="text-align: left;"><strong>Build Process:</strong></p><ul style="text-align: left;"><li>Docker image is built from the Dockerfile (Python, Mosquitto, Supervisor, app code).</li></ul><p style="text-align: left;"><strong>Deployment Method:</strong></p><ul style="text-align: left;"><li>CI/CD pipeline (<code class="undefined">project-ci.yml</code>) deploys the container to GCP Flexible Environment using environment-specific YAMLs.</li><li>Each deployment uses a dedicated service account and VPC connector.</li></ul><p style="text-align: left;"><strong>Runtime Dependencies:</strong></p><ul style="text-align: left;"><li>GCP credentials (service account key or workload identity).</li><li>Network access to GCP APIs.</li></ul><p style="text-align: left;"><strong>Scaling and Rollback Considerations:</strong></p><ul style="text-align: left;"><li>Only one instance per environment (no auto-scaling).</li><li>Rollback by redeploying a previous image/tag.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">8. Extending the System</h3><p style="text-align: left;"><strong>Where and How to Add New Features:</strong></p><ul style="text-align: left;"><li>Update Python code for new message handling or cloud integrations.</li><li>Adjust Mosquitto or Supervisor configs as needed.</li><li>Add environment variables to YAMLs for new configuration options.</li></ul><p style="text-align: left;"><strong>Recommended Patterns:</strong></p><ul style="text-align: left;"><li>Use environment variables for all configuration.</li><li>Keep environment YAMLs in sync with code/config changes.</li><li>Test changes in DEV before promoting to PPRD/PRD.</li></ul><p style="text-align: left;"><strong>Anti-patterns and Risk Areas:</strong></p><ul style="text-align: left;"><li>Hardcoding secrets or credentials.</li><li>Making breaking changes to topic structure or message schema without coordination.</li><li>Running multiple instances without unique MQTT client IDs.</li></ul><p style="text-align: left;"><strong>Testing Strategy:</strong></p><ul style="text-align: left;"><li>Unit/integration tests for Python code.</li><li>Deploy to DEV and validate end-to-end message flow before promoting.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">9. Security & Compliance</h3><p style="text-align: left;"><strong>Authentication and Authorization:</strong></p><ul style="text-align: left;"><li>GCP access is secured via service accounts.</li><li>MQTT broker is not secured (no TLS or authentication) – must be addressed for production.</li></ul><p style="text-align: left;"><strong>Secrets Handling:</strong></p><ul style="text-align: left;"><li>No secrets in code; all sensitive data should be managed via environment or GCP Secret Manager.</li></ul><p style="text-align: left;"><strong>Data Sensitivity Considerations:</strong></p><ul style="text-align: left;"><li>Sensor data may be sensitive; ensure GCP IAM and network policies are enforced.</li></ul><hr style="text-align: left;" /><h3 style="text-align: left;">10. Common Pitfalls & Gotchas</h3><ul style="text-align: left;"><li><strong>No MQTT Security:</strong><span> </span>Broker is open on 1883 with no authentication/TLS; not suitable for production as-is.</li><li><strong>Single Instance:</strong><span> </span>No horizontal scaling; may be a bottleneck for high-throughput scenarios.</li><li><strong>Resource Limits:</strong><span> </span>Production uses more resources, but disk is fixed at 10GB; monitor for growth.</li><li><strong>Environment Drift:</strong><span> </span>YAMLs must be kept in sync with code/config changes.</li><li><strong>Supervisor:</strong><span> </span>If Supervisor or one of its managed processes fails to start, the container will not function correctly.</li><li><strong>Health Checks:</strong><span> </span>Liveness/readiness checks are critical for auto-recovery but may need tuning for startup delays.</li></ul>
Edit
Preview
Save
Close
{"serverDuration": 449, "requestCorrelationId": "9a700207d74df4b2"}