Skip to content

Commit 2fd13cc

Browse files
committed
ci: 👷 add support for docker image publish
1 parent 0360654 commit 2fd13cc

5 files changed

Lines changed: 239 additions & 13 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '**.md'
9+
- 'docs/**'
10+
- 'LICENSE'
11+
- '.gitignore'
12+
workflow_dispatch: # Allow manual trigger
13+
14+
env:
15+
DOCKERHUB_USERNAME: amd989
16+
IMAGE_NAME: amd989/xbee2mqtt
17+
18+
jobs:
19+
build-and-push:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
with:
29+
platforms: all
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to Docker Hub
35+
uses: docker/login-action@v3
36+
with:
37+
username: ${{ env.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels)
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
type=sha,prefix={{branch}}-
48+
type=ref,event=branch
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
file: ./Dockerfile
57+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386
58+
push: true
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
62+
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
63+
64+
- name: Update Docker Hub description
65+
uses: peter-evans/dockerhub-description@v4
66+
with:
67+
username: ${{ env.DOCKERHUB_USERNAME }}
68+
password: ${{ secrets.DOCKERHUB_TOKEN }}
69+
repository: ${{ env.IMAGE_NAME }}
70+
short-description: "XBee to MQTT gateway - Python 3 daemon for bridging XBee ZigBee radios to MQTT brokers"
71+
readme-filepath: ./README.md
72+
continue-on-error: true
73+
74+
- name: Image digest
75+
run: echo "Image pushed with digest ${{ steps.meta.outputs.digest }}"

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# xbee2mqtt
22

3+
[![Docker Pulls](https://img.shields.io/docker/pulls/amd989/xbee2mqtt)](https://hub.docker.com/r/amd989/xbee2mqtt)
4+
[![Docker Image Size](https://img.shields.io/docker/image-size/amd989/xbee2mqtt/latest)](https://hub.docker.com/r/amd989/xbee2mqtt)
5+
[![Build Status](https://img.shields.io/github/actions/workflow/status/amd989/xbee2mqtt/docker-build.yml?branch=master)](https://github.com/amd989/xbee2mqtt/actions)
6+
37
A Python 3 daemon that bridges XBee ZigBee radios to MQTT brokers. It monitors a coordinator XBee connected to a serial port, translates radio messages to MQTT topics, and enables remote control of XBee digital I/O pins through MQTT commands.
48

59
From version 0.3 it also supports setting digital pins LOW or HIGH on remote radios.
@@ -10,7 +14,26 @@ From version 0.3 it also supports setting digital pins LOW or HIGH on remote rad
1014

1115
## Quick Start with Docker (Recommended)
1216

13-
The easiest way to run xbee2mqtt is using Docker. Works on any Linux system including Raspberry Pi!
17+
The easiest way to run xbee2mqtt is using Docker. Pre-built images available for all major architectures!
18+
19+
### Using Docker Hub (Recommended)
20+
21+
```bash
22+
# Pull the latest image (automatically selects your architecture)
23+
docker pull amd989/xbee2mqtt:latest
24+
25+
# Or use docker-compose (see docker-compose.yml)
26+
docker-compose up -d
27+
```
28+
29+
**Supported architectures:**
30+
- `linux/amd64` - x86 64-bit (PCs, servers, cloud)
31+
- `linux/arm64` - ARM 64-bit (Raspberry Pi 3/4/5 with 64-bit OS)
32+
- `linux/arm/v7` - ARM 32-bit v7 (Raspberry Pi 2/3/4 with 32-bit OS)
33+
- `linux/arm/v6` - ARM 32-bit v6 (Raspberry Pi Zero, Pi 1)
34+
- `linux/386` - x86 32-bit
35+
36+
### Quick Setup
1437

1538
```bash
1639
# 1. Copy and configure

docker-compose.dev.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3.8'
2+
3+
services:
4+
xbee2mqtt:
5+
build: .
6+
container_name: xbee2mqtt-dev
7+
restart: unless-stopped
8+
9+
# Serial device access - update to match your XBee device
10+
# Common options:
11+
# USB-to-Serial adapter: /dev/ttyUSB0
12+
# Raspberry Pi GPIO UART: /dev/ttyAMA0 or /dev/serial0
13+
# Raspberry Pi USB: /dev/ttyUSB0
14+
devices:
15+
- /dev/ttyUSB0:/dev/ttyUSB0
16+
# For Raspberry Pi GPIO UART, uncomment:
17+
# - /dev/ttyAMA0:/dev/ttyAMA0
18+
# - /dev/serial0:/dev/serial0
19+
20+
# Privileged mode for serial port access (alternative to devices)
21+
# Only use if device mapping doesn't work
22+
# privileged: true
23+
24+
volumes:
25+
# Mount config directory
26+
- ./config:/app/config:ro
27+
# Mount var directory for logs and PID file
28+
- ./var:/app/var
29+
30+
environment:
31+
# Optional: Override logging level (10=DEBUG, 20=INFO, 30=WARNING, 40=ERROR)
32+
- LOGGING_LEVEL=20
33+
34+
# Network mode for MQTT connectivity
35+
# Use 'host' if MQTT broker is on localhost
36+
# Or use 'bridge' (default) and specify broker IP in config
37+
network_mode: bridge
38+
39+
logging:
40+
driver: "json-file"
41+
options:
42+
max-size: "10m"
43+
max-file: "3"

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.8'
22

33
services:
44
xbee2mqtt:
5-
build: .
5+
image: amd989/xbee2mqtt:latest
66
container_name: xbee2mqtt
77
restart: unless-stopped
88

docs/README.docker.md

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ This guide explains how to run xbee2mqtt in a Docker container for consistent de
99
- XBee coordinator radio connected via USB (typically `/dev/ttyUSB0`)
1010
- MQTT broker accessible (can be on same host or remote)
1111

12+
## Docker Hub vs Local Build
13+
14+
There are two ways to run xbee2mqtt with Docker:
15+
16+
### Option 1: Docker Hub (Recommended)
17+
18+
Pull pre-built multi-architecture images from Docker Hub:
19+
20+
```bash
21+
docker pull amd989/xbee2mqtt:latest
22+
```
23+
24+
**Advantages:**
25+
- ✅ No build time - instant deployment
26+
- ✅ Automatically selects correct architecture (amd64, arm64, arm/v7, arm/v6, 386)
27+
- ✅ Always up-to-date with latest stable release
28+
- ✅ Verified builds from CI/CD pipeline
29+
30+
**Use this if:** You want to run the stable version without modifying code.
31+
32+
The default `docker-compose.yml` uses Docker Hub images.
33+
34+
### Option 2: Local Build
35+
36+
Build the Docker image locally from source:
37+
38+
```bash
39+
docker-compose -f docker-compose.dev.yml up --build
40+
```
41+
42+
**Advantages:**
43+
- ✅ Test local code changes
44+
- ✅ Development and debugging
45+
- ✅ Custom modifications
46+
47+
**Use this if:** You're developing or need to modify the code.
48+
49+
The `docker-compose.dev.yml` file is configured for local builds.
50+
1251
## Quick Start
1352

1453
### 1. Configure the Application
@@ -51,6 +90,7 @@ Update `docker-compose.yml` with your device path. The default is `/dev/ttyUSB0`
5190

5291
### 3. Start with Docker Compose
5392

93+
**Using Docker Hub image (recommended):**
5494
```bash
5595
# Start in background
5696
docker-compose up -d
@@ -62,37 +102,63 @@ docker-compose logs -f
62102
docker-compose down
63103
```
64104

105+
**Using local build (for development):**
106+
```bash
107+
# Build and start
108+
docker-compose -f docker-compose.dev.yml up -d
109+
110+
# View logs
111+
docker-compose -f docker-compose.dev.yml logs -f
112+
113+
# Stop
114+
docker-compose -f docker-compose.dev.yml down
115+
```
116+
65117
## Manual Docker Commands
66118

67119
If you prefer not to use Docker Compose:
68120

69-
### Build the Image
121+
### Using Docker Hub Image
70122

71123
```bash
72-
docker build -t xbee2mqtt .
124+
# Pull the image
125+
docker pull amd989/xbee2mqtt:latest
126+
127+
# Run the container
128+
docker run -d \
129+
--name xbee2mqtt \
130+
--restart unless-stopped \
131+
--device=/dev/ttyUSB0:/dev/ttyUSB0 \
132+
-v $(pwd)/config:/app/config:ro \
133+
-v $(pwd)/var:/app/var \
134+
amd989/xbee2mqtt:latest
73135
```
74136

75-
### Run the Container
137+
### Local Build
76138

77139
```bash
140+
# Build the image
141+
docker build -t xbee2mqtt-local .
142+
143+
# Run the container
78144
docker run -d \
79145
--name xbee2mqtt \
80146
--restart unless-stopped \
81147
--device=/dev/ttyUSB0:/dev/ttyUSB0 \
82148
-v $(pwd)/config:/app/config:ro \
83149
-v $(pwd)/var:/app/var \
84-
xbee2mqtt
150+
xbee2mqtt-local
85151
```
86152

87-
**Windows (PowerShell):**
153+
**Windows (PowerShell) with Docker Hub:**
88154
```powershell
89155
docker run -d `
90156
--name xbee2mqtt `
91157
--restart unless-stopped `
92158
--device=/dev/ttyUSB0:/dev/ttyUSB0 `
93159
-v ${PWD}/config:/app/config:ro `
94160
-v ${PWD}/var:/app/var `
95-
xbee2mqtt
161+
amd989/xbee2mqtt:latest
96162
```
97163

98164
### Manage the Container
@@ -289,7 +355,7 @@ services:
289355
- ./mosquitto/data:/mosquitto/data
290356
291357
xbee2mqtt:
292-
build: .
358+
image: amd989/xbee2mqtt:latest
293359
container_name: xbee2mqtt
294360
restart: unless-stopped
295361
depends_on:
@@ -303,6 +369,8 @@ services:
303369

304370
Set MQTT host to `mosquitto` in your config file.
305371

372+
**For local development**, use `build: .` instead of `image: amd989/xbee2mqtt:latest`.
373+
306374
## Testing the Migration
307375

308376
After the Python 2 to Python 3 migration, you should verify everything works:
@@ -409,14 +477,31 @@ If you encounter Python errors:
409477

410478
## Updating
411479

412-
To update to a new version:
480+
### Updating Docker Hub Image
481+
482+
To update to the latest version from Docker Hub:
483+
484+
```bash
485+
# Pull latest image
486+
docker pull amd989/xbee2mqtt:latest
487+
488+
# Restart with new image
489+
docker-compose down
490+
docker-compose up -d
491+
```
492+
493+
The latest image is automatically built from the master branch via GitHub Actions.
494+
495+
### Updating Local Build
496+
497+
To update with local changes:
413498

414499
```bash
415500
# Pull latest code
416501
git pull
417502
418503
# Rebuild and restart
419-
docker-compose down
420-
docker-compose build --no-cache
421-
docker-compose up -d
504+
docker-compose -f docker-compose.dev.yml down
505+
docker-compose -f docker-compose.dev.yml build --no-cache
506+
docker-compose -f docker-compose.dev.yml up -d
422507
```

0 commit comments

Comments
 (0)