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

Swarm mode modifications #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PabloRapidScale
Copy link

#72

  • Added some lines to handle the way that Docker Swarm handles container names and tags. It should be able to handle both standalone docker and docker swarm.
  • Added README section for swarm, to keep changes minimal the container should run in global mode so it looks up and backs up whatever local containers match the criteria.
  • Changed the way the backup is saved to use a timestamp as a prefix to created dated backups. This can be ripped out if single file is preferred.

@@ -51,6 +51,27 @@ services:
- INCLUDE_LOGS=true
```

#### Running in Docker Swarm
To run the backup service in Docker Swarm, you should configure it as a global service. This ensures that the backup process runs on each node in the Swarm and backs up all matching containers on the local node.
```yml
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: A lot of this YAML is duplicated from the above example. Perhaps it would be better to link out to the Docker documentation for making a service "global"?


duration = (datetime.now() - now).total_seconds()
print(f"Backup of {len(backed_up_services)} services complete in {duration:.2f} seconds.")
else:
Copy link
Owner

Choose a reason for hiding this comment

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

Question: What's the reason for the below duplication? Could the extra logic be handled in the existing single loop?

"""
Create a backup file name with a timestamp prefix and the container name.
"""
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
Copy link
Owner

Choose a reason for hiding this comment

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

Issue: This is a very big change. Backups are intentionally not timestamped. Please remove this.


print(f"Found {len(containers)} containers.")
def get_local_node_tasks() -> list:
docker_client = docker.from_env()
Copy link
Owner

Choose a reason for hiding this comment

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

Issue: This code creates a lot of extra connections to the docker API - could a client be passed around instead?


def get_local_node_id() -> str:
Copy link
Owner

Choose a reason for hiding this comment

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

Question: Does the new logic need to happen only in swarm mode? Could checking for the container config image name be done all the time instead? It feels like it's a purely additive change

Comment on lines +170 to +171
image_name = tag.split(":")[0].split("@")[0]
image_name = image_name.split("/")[-1]
Copy link
Owner

Choose a reason for hiding this comment

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

Question: Why are you removing resolve_repository_name here? Was it not working correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants