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

Adding Dockerfile and docker compose files. #56

Merged

Conversation

renan-souza
Copy link
Collaborator

To make it work with docker compose, I had to enable custom hostnames and ports
for nats through environment vars. For this, I created a conf.py file in
zambeze to centralize configuration code, such as pulling environment variables.

#55

To make it work with docker compose, I had to enable custom hostnames and ports
 for nats through environment vars. For this, I created a conf.py file in
 zambeze to centralize configuration code, such as pulling environment variables.

#55
Attempt to fix GitHub action
@JoshuaSBrown
Copy link
Collaborator

Ok, I fixed the GitHub action.

Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown left a comment

Choose a reason for hiding this comment

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

Minor suggestions and questions nothing to stop merge. Feel free to merge when you are ready.

Comment on lines 10 to 11
$> docker build -t zambeze/zambeze -f deployment/Dockerfile .
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, I didn't realize that "$>" was used to indicate a prompt I will use that from now on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps only the $ sign would be enough.

Comment on lines 16 to 17
from .conf import HOST, NATS_HOST, NATS_PORT

Copy link
Collaborator

Choose a reason for hiding this comment

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

Host is unused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I was unsure whether we should use it for ZMQ host. Now I think we should. See response: #56 (comment)

zambeze/conf.py Outdated
Comment on lines 1 to 5
import os

HOST = os.getenv('HOST', "127.0.0.1")
NATS_HOST = os.getenv('NATS_HOST', "127.0.0.1")
NATS_PORT = int(os.getenv('NATS_PORT', 4222))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is conf.py the typical file name for a config file in Python? I don't know.

Copy link
Collaborator Author

@renan-souza renan-souza Oct 28, 2022

Choose a reason for hiding this comment

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

Unfortunately there isn't a clear convention in Python. I've been using conf.py with my dev colleagues within all projects I develop, but after a quick search on other GitHub repos, we can see folks using config.py ; constants.py; and even configs.py. I'm fine with either file name. I just think it's nice to keep all global configuration constants, particularly the ones that come from env vars, in a single Python file.

Comment on lines +80 to +81
self.__set_default("host", NATS_HOST, self.settings["nats"])
self.__set_default("port", NATS_PORT, self.settings["nats"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a lot clearer, no more magick numbers nice!

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should do this with all of the ports and IP addresses.

self.__set_default("host", "127.0.0.1", self.settings["nats"])
self.__set_default("port", 4222, self.settings["nats"])
self.__set_default("host", NATS_HOST, self.settings["nats"])
self.__set_default("port", NATS_PORT, self.settings["nats"])
self.__set_default("host", "127.0.0.1", self.settings["zmq"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to use HOST here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I meant NATS_HOST for line 80. For line 82, I think HOST is right. I just wasn't sure whether the zmq will always run on the same host as the agent. I so, then yes we should use HOST in line 82 and never have something like ZEROMQ_HOST as an env var.

Comment on lines +1 to +10
version: '3.8'
services:
nats:
container_name: nats
image: nats
command: -V
ports:
- 4222:4222
- 6222:6222
- 8222:8222
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm asking cause I don't know, where does this container come from? Is this provided by nats registry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is exactly right. See: https://hub.docker.com/_/nats



```shell
$> docker build -t zambeze/zambeze -f deployment/Dockerfile .
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question, do you think it is best to place this in a deployment folder or a different folder name i.e. like development, compose or something else, this is not really a problem, just brainstorming. Deployment to me makes me think of production.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again it's been a convention within my former colleagues to always place Dockerfiles, compose files, k8s files, etc etc under a folder called deployment. I'm not sure whether there's a different convention and we can definitely change/create our own.

@JoshuaSBrown
Copy link
Collaborator

@par-hermes format

@JoshuaSBrown
Copy link
Collaborator

If the checks are failing because of formatting I would just ignore them, and merge anyway specifically if you have already run the auto formatted. Stupid formatting errors that are not auto fixable are a waste of time for the most part.

@JoshuaSBrown JoshuaSBrown added the developer-tools Tools to assist with development label Oct 28, 2022
@JoshuaSBrown JoshuaSBrown linked an issue Oct 28, 2022 that may be closed by this pull request
@renan-souza
Copy link
Collaborator Author

If the checks are failing because of formatting I would just ignore them, and merge anyway specifically if you have already run the auto formatted. Stupid formatting errors that are not auto fixable are a waste of time for the most part.

Please teach me later how to identify formatting build failures and how to fix them. I'm just not used to adding them in CI/CD pipelines, but think it's a good idea to keep them.

- Using HOST env var for zmq, and created a ZMQ_PORT var.
- Improved README.md for the container execution to provide the steps to run the simple example and expected results.
- Made few other code improvements based on @JoshuaSBrown's feedback on this PR: #56

Issue: #55
@renan-souza renan-souza merged commit 9045829 into JoshuaSBrown-fix-image-magick-example Oct 29, 2022
@renan-souza renan-souza deleted the renan-docker-compose branch November 11, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-tools Tools to assist with development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a Docker compose & Dockerfile for Zambeze
2 participants