Add initial implementation of Docker Compose manager and example usage

- Introduced DockerComposeManager class for programmatically creating and managing Docker Compose YAML files.
- Added example script demonstrating usage of DockerComposeManager.
- Created tests for service creation, modification, and removal.
- Included project metadata in pyproject.toml and added linting instructions in copilot-instructions.md.
This commit is contained in:
2025-06-18 03:45:48 +02:00
parent 49e72e82a0
commit 63160d682f
7 changed files with 252 additions and 0 deletions

36
example/basic_example.py Normal file
View File

@ -0,0 +1,36 @@
"""Example usage of DockerComposeManager to generate a docker-compose.yaml file."""
from compose import DockerComposeManager
if __name__ == "__main__":
# Path to the compose file to generate
compose_path = "docker-compose.yaml"
# Create a DockerComposeManager instance
manager = DockerComposeManager(compose_path)
# Add a simple web service
manager.create_service(
name="web",
image="nginx:alpine",
ports=["8080:80"],
environment={"NGINX_HOST": "localhost"},
)
# Add a database service
manager.create_service(
name="db",
image="postgres:15-alpine",
environment={
"POSTGRES_USER": "user",
"POSTGRES_PASSWORD": "password",
"POSTGRES_DB": "exampledb",
},
ports=["5432:5432"],
volumes=["db_data:/var/lib/postgresql/data"],
)
# Save the compose file
manager.save()
print(f"docker-compose.yaml generated at {compose_path}")