Skip to content

Commit 5db9e85

Browse files
Sebastian MachucaSebastian Machucajaniversen
authored
Add Docker and container registry support (#1132)
* Adding a Docker image and publishing to GHCR Co-authored-by: Sebastian Machuca <[email protected]> Co-authored-by: jan iversen <[email protected]>
1 parent 17d66c6 commit 5db9e85

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

.github/workflows/docker-hub.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Publish Docker image
11+
12+
on:
13+
release:
14+
types: [published]
15+
16+
jobs:
17+
push_to_registry:
18+
name: Push Docker image to Docker Hub
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out the repo
22+
uses: actions/checkout@v3
23+
24+
-
25+
name: Set up QEMU
26+
uses: docker/setup-qemu-action@v2
27+
28+
-
29+
name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v2
31+
32+
- name: Log in to Docker Hub
33+
uses: docker/login-action@v2
34+
with:
35+
username: ${{ secrets.DOCKER_USERNAME }}
36+
password: ${{ secrets.DOCKER_PASSWORD }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@v4
41+
with:
42+
images: ${{ github.repository }}
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v3
46+
with:
47+
context: .
48+
platforms: linux/amd64,linux/arm64
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/package.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Create and publish a Docker image
11+
12+
on:
13+
release:
14+
types: [published]
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
build-and-push-image:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@v2
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@v4
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v3
46+
with:
47+
context: .
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.8-slim-buster
4+
5+
WORKDIR /pymodbus
6+
7+
COPY . .
8+
9+
RUN pip3 install -r requirements.txt && pip3 install -e .
10+

README.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ Or to install a specific release:
197197

198198
pip install -U pymodbus==X.Y.Z
199199

200+
You can also use Docker to run a local image with the package installed on the image:
201+
202+
docker pull riptideio/pymodbus
203+
200204
Otherwise you can pull the trunk source and install from there::
201205

202206
git clone git://github.com/riptideio/pymodbus.git
@@ -236,6 +240,21 @@ This installs pymodbus in your virtual environment with pointers directly to the
236240
Either method will install all the required dependencies
237241
(at their appropriate versions) for your current python distribution.
238242

243+
------------------------------------------------------------
244+
Docker Compose
245+
------------------------------------------------------------
246+
247+
If you would like to use this image as part of a `docker compose` project, you can provide a custom command. For example,
248+
you can spin the server by creating a docker compose file containing the following::
249+
250+
pymodbus-server:
251+
container_name: pymodbus-server
252+
image: riptideio/pymodbus:X.Y.Z
253+
command: ["./examples/server_sync.py"]
254+
255+
After running `docker compose up`, you should have running the `server_sync.py` example, ready to accept connections from a client. You can,
256+
of course, add a custom script instead, to run your own logic instead.
257+
239258
------------------------------------------------------------
240259
Repository structure
241260
------------------------------------------------------------

pymodbus/repl/client/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Install pymodbus with repl support
1515
$ pip install pymodbus[repl] --upgrade
1616
```
1717

18+
## Docker
19+
Pull Docker image with everything installed
20+
21+
`docker pull riptideio/pymodbus`
22+
23+
1824
## Usage Instructions
1925
RTU and TCP are supported as of now
2026

@@ -32,7 +38,9 @@ Commands:
3238
serial
3339
tcp
3440
41+
# Or using a Docker run command instead
3542
43+
✗ docker run -it riptideio/pymodbus pymodbus.console --help
3644
```
3745
TCP Options
3846

pymodbus/repl/server/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Install `pymodbus` with the required dependencies
1919

2020
`pip install pymodbus[repl]`
2121

22+
## Docker
23+
Pull Docker image with everything installed
24+
25+
`docker pull riptideio/pymodbus`
26+
2227
## Usage
2328

2429
Invoke REPL server with `pymodbus.server run` command.
@@ -46,6 +51,12 @@ Invoke REPL server with `pymodbus.server run` command.
4651
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
4752
```
4853

54+
If using the docker image, you can run all the same commands, prepending the `docker run` command. For example:
55+
56+
```shell
57+
docker run -it riptideio/pymodbus pymodbus.server --help
58+
```
59+
4960
```shell
5061
✗ pymodbus.server run --help
5162

0 commit comments

Comments
 (0)