Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker and container registry support #1132

Merged
merged 11 commits into from
Oct 22, 2022
Merged

Conversation

serroba
Copy link
Contributor

@serroba serroba commented Oct 21, 2022

What?

This PR adds support to create docker images locally against the current working environment
Additionally, this PR is adding the required scripts to automatically create docker images and publish them to public repositories -Docker Hub and GitHub Container Registry (ghcr), as a package.

When publishing to Docker Hub, in this PR, we are publishing images built for linux/amd64 and linux/arm64. Additional platform can be easily expanded if there is more need for that.

Why?

This can greatly accelerate the exploration of this library. As an external user, the ability to interact with the library and potentially spin up servers and play with the clients can drastically reduce the need to learn the more lower level aspects of the library. This also makes very easy the ability to import the library in a larger project using docker-compose.

Additionally, this is a continuation of the conversation I had with @janiversen a few weeks ago: 4b57def#r86307726

Testing/Proof

I tested this against my own fork. I tried several times until I got it working.

The GH actions can be seen here:

https://github.com/serroba/pymodbus/actions

Of particular interest:

Container Images Registries

Docker Hub

To test proper integration with Docker Hub, I created my own repository with the equivalent of this project. The images can be seen on: https://hub.docker.com/repository/docker/serroba/pymodbus

GitHub Container Registry

To test this, the integration is native, so no need to do anything outside this PR here: https://github.com/serroba/pymodbus/pkgs/container/pymodbus

Examples and usage with Docker Compose:

I have forked an existent public repository https://github.com/huntabyte/tig-stack and the now created image using this PR

Example:

  pymodbus-server:
    container_name: pymodbus-server
    image: serroba/pymodbus:v3.0.0dev5
    command: ["./examples/server_sync.py"]

Things are working as expected:
image

Also, we can just things directly in the container:

docker run -it serroba/pymodbus:v3.0.0dev5 examples/server_sync.py

image

Or enter the REPL using the images:

docker run -it serroba/pymodbus:v3.0.0dev5 pymodbus.server run --modbus-server tcp --framer socket --unit-id 1 --unit-id 4 --random 2

image

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without having actually tried it but only reviewed it, it looks good.

However you need to add documentation, so that users know it exist.

If I looked right you need me to add a user/password to secrets (if my powers allow it) anything else?

@janiversen
Copy link
Collaborator

Added DOCKER_USERNAME / DOCKER_PASSWORD to secrets. Username is janiversen (which you need for documentation).

Can you make the action so I e.g. can create docker images with some of the examples ?

Dockerfile Show resolved Hide resolved
@serroba
Copy link
Contributor Author

serroba commented Oct 22, 2022

@janiversen the only thing required was the creation of those credentials. Thank you for adding them to the secrets. Nothing else is required on your end.

WRT documentation, one thing is updating the readme, which I'm happy to do.

Added DOCKER_USERNAME / DOCKER_PASSWORD to secrets. Username is janiversen (which you need for documentation).

I'm not sure what you mean here. Do you mean adding comments to the YML files where those values are used?

Can you make the action so I e.g. can create docker images with some of the examples ?

I don't understand what you mean. Can you please clarify. Thanks

@janiversen
Copy link
Collaborator

You need to document in the README that there are a docker image available, where and how to use it.

@janiversen
Copy link
Collaborator

janiversen commented Oct 22, 2022

I was thinking of having e.g, docker images with: a standard server, a repl server and a forwarder.

However I am unsure how a user could effectively configure these images.

@serroba
Copy link
Contributor Author

serroba commented Oct 22, 2022

Users can create a docker compose file and add a command instruction. That allows to use the same image with a user-selected command

The example I showed is this:

pymodbus-server:
    container_name: pymodbus-server
    image: serroba/pymodbus:v3.0.0dev5
    command: ["./examples/server_sync.py"]

in this case, the container is spin up and we run the sync server. A different person could add the REPL in place instead.

@janiversen
Copy link
Collaborator

your example of compose is good, but that is what needs to be documented.

README.rst Show resolved Hide resolved
pymodbus/repl/client/README.md Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@janiversen
Copy link
Collaborator

CI does not like your text:

../README.rst:252: ERROR: Unexpected indentation.
[628](https://github.com/riptideio/pymodbus/actions/runs/3303097490/jobs/5450746414#step:5:629)
../README.rst:250: WARNING: Inline literal start-string without end-string.
[629](https://github.com/riptideio/pymodbus/actions/runs/3303097490/jobs/5450746414#step:5:630)
../README.rst:250: WARNING: Inline interpreted text or phrase reference start-string without end-string.
[630](https://github.com/riptideio/pymodbus/actions/runs/3303097490/jobs/5450746414#step:5:631)
../README.rst:255: WARNING: Block quote ends without a blank line; unexpected unindent.
[631](https://github.com/riptideio/pymodbus/actions/runs/3303097490/jobs/5450746414#step:5:632)
../README.rst:255: WARNING: Inline literal start-string without end-string.
[632](https://github.com/riptideio/pymodbus/actions/runs/3303097490/jobs/5450746414#step:5:633)
../README.rst:255: WARNING: Inline interpreted text or phrase reference start-string without end-string.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

README.rst Show resolved Hide resolved
pymodbus/repl/client/README.md Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@janiversen janiversen merged commit 5db9e85 into pymodbus-dev:dev Oct 22, 2022
@serroba
Copy link
Contributor Author

serroba commented Oct 22, 2022

Thank you @janiversen

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants