- 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.
37 lines
993 B
Python
37 lines
993 B
Python
"""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}")
|