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:
0
example/__init__.py
Normal file
0
example/__init__.py
Normal file
36
example/basic_example.py
Normal file
36
example/basic_example.py
Normal 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}")
|
Reference in New Issue
Block a user