{ "info": { "author": "Darwin Monroy", "author_email": "contact@darwinmonroy.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Pytest", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Build Tools" ], "description": "Uses docker to spawn containers for services required during tests\n\n[![Build Status](https://travis-ci.org/dmonroy/docker-services.svg?branch=master)](https://travis-ci.org/dmonroy/docker-services)\n\n# Install\n\nThis project is available on pypi, so you can use _pip_ to install it:\n\n```\npip install docker-services\n```\n\nOr include it as a dependency on `setup.py` or a `requirements.txt` file, whatever you prefer.\n\n\n# Use it\n\n## 1. Configure your project services\n\nYou need to start listing all services that your project depends on and leverage on _docker-services_ to maintain the lifecycle of those services during test runs.\n\nThis must happen using either the `docker_services` config option on any pytest _.cfg/.ini_ file or on a `.services.yaml` file, the value for that option requires a yaml structure where top level members are the service names and their values can be either an empty value, image name or a or an object.\n\nDue to limitations of ini files, full support for yaml is not available on .cfg/.ini files, if you need complex config then usage of the `.services.yaml` file is encouraged.\n\nThis is a basic example for a project that depends on a `postgres` service:\n\n```\n[pytest]\ndocker_services=postgres:\n```\n\nThis is the same:\n\n```\n[pytest]\ndocker_services=\n postgres:\n```\n\nAnd this:\n\n```\n[pytest]\ndocker_services=\n postgres: postgres\n```\n\nAnd this too (on .services.yaml):\n\n```yaml\npostgres:\n image: postgres\n```\n\nAnd guess what?... this too!\n\n```yaml\ndatabase:\n name: postgres\n image: postgres\n```\n\nIf the projects depends different services, list all of them:\n\n```\n[pytest]\ndocker_services=\n postgres:\n redis:\n```\n\nWhen image name is not specified (and I bet you already noticed this) it falls back to use the service name as image name, but it is possible to specify the image name and version to use:\n\n```\n[pytest]\ndocker_services=\n postgres: postgres:10\n```\n\nAlso this way:\n\n```yaml\npostgres:\n image: postgres:10\n```\n\nNow the service name is `postgres` and image name is `postgres:10`.\n\nAnother option is to use a different name for the service, something like:\n\n```\n[pytest]\ndocker_services=\n db: postgres:10\n```\n\n```yaml\ndb:\n image: postgres:10\n```\n\nNow service name is `db` and image name is `postgres:10`.\n\nIf you don't want (or need) to set a specific image version, just ignore the version part like this:\n\n```\n[pytest]\ndocker_services=\n db: postgres\n```\n\nAlso you are able to use images from a private registry:\n\n```\n[pytest]\ndocker_services=\n db: my.registry.com/custom/postgres\n```\n\n### 1.1. Configure environment variables for your services\n\nYou may want to customize the behaviour of your services by setting environment variables, it is also possible by adding to the config (valid only when using the `.services.yaml` file).\n\n```yaml\ndb:\n image: postgres:10\n environment:\n POSTGRES_USERNAME: myuser\n POSTGRES_PASSWORD: $3cr3t\n POSTGRES_DB: mydb\n```\n\nUsing that config above the _db_ service is now initialized with `POSTGRES_USERNAME`, `POSTGRES_PASSWORD` and `POSTGRES_DB` environment variables.\n\nThose variables are also exposed to the actual session, so you can consume those values from within your app or tests too.\n\n### 1.2. Configure dynamic variables too\n\nAre you planning to configure a `DATABASE_URL` environment variable based on service's port number?... then don't wait and configure a variable template ;).\n\nTalking about the `DATABASE_URL` for postgres one usually expects something like `postgres://user:password@host:port/dbname`, and that can be achieved by replacing\n\n```yaml\npostgres:\n image: postgres:10\n environment:\n POSTGRES_USERNAME: myuser\n POSTGRES_PASSWORD: $3cr3t\n POSTGRES_DB: mydb\n _templates:\n POSTGRES_PORT: \"{env[POSTGRES_PORT_5432_TCP_PORT]}\"\n DATABASE_URL: \"postgres://myuser:$s3cr3t@localhost:{env[POSTGRES_PORT_5432_TCP_PORT]}/mydb\"\n```\n\nIt is also possible to use environment variables defined for the service, so you don't repeat the same:\n\n```\nDATABASE_URL: \"postgres://{env[POSTGRES_USERNAME]}:{env[POSTGRES_PASSWORD]}@localhost:{env[POSTGRES_PORT_5432_TCP_PORT]}/{env[POSTGRES_DB]}\"\n```\n\nThe parameters on the template are replaced using python's `.format()` method and at the moment only `env` parameter is passed and it references actually to the content of `os.environ`, so all environment variables are available.\n\n## 2. Run tests with docker-services enabled\n\n_docker-services_ adds the `--use-docker-services` command line option for _py.test_, when setting this option it enables service's spawning using docker, run it like this:\n\n```\npy.test --docker-services\n```\n\n## 3. Communicate with the services\n\nWe spawn our services because we need to communicate with them during test sessions, either to consume data from or publish data to. For that `docker_services` rely on service's exposed ports to create unique environment variables for each port and protocol exposed on each of the services.\n\nThe variable names follows the same conventions as in environment variables created from [links](https://docs.docker.com/network/links/#environment-variables), but for now we only create the `*_PORT` environment variables, assuming docker is running on local machine and ports exposed to localhost.\n\nSo, if we have a `postgres` service we expect to communicate using port 5432, now looking at the [Dockerfile](https://github.com/docker-library/postgres/blob/674466e0d47517f4e05ec2025ae996e71b26cae9/10/Dockerfile) we can confirm that it [exposes port 5432](https://github.com/docker-library/postgres/blob/674466e0d47517f4e05ec2025ae996e71b26cae9/10/Dockerfile#L132).\n\nPlease note that _docker_services_ creates environment variables for exposed ports only, if service's image doesn't expose any port then no `*_PORT` variable would be reated.\n\nFor the `postgres` service use case, variable name for port `5432` would be: `POSTGRES_PORT_5432_TCP_PORT`, this variable name is built using this template: `{service_name}_PORT_{port}_{protocol}_PORT`.\n\nAlso remember that environment variables configured for a service are also available within the context of the pytest session, this applies to both static and dynamic variables!\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dmonroy/docker-services", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "docker-services", "package_url": "https://pypi.org/project/docker-services/", "platform": "", "project_url": "https://pypi.org/project/docker-services/", "project_urls": { "Homepage": "https://github.com/dmonroy/docker-services" }, "release_url": "https://pypi.org/project/docker-services/0.3.2/", "requires_dist": [ "docker", "pytest", "pyyaml" ], "requires_python": "", "summary": "Uses docker to spawn containers for services required during tests", "version": "0.3.2" }, "last_serial": 5801689, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "c0f6c36968b3abeb6480eb0718778aa4", "sha256": "e556dfc7f274924e61cf2c2e98ce25acf22e2de1d1dc4eaa2a5892b916af5c39" }, "downloads": -1, "filename": "docker-services-0.0.0.tar.gz", "has_sig": false, "md5_digest": "c0f6c36968b3abeb6480eb0718778aa4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3523, "upload_time": "2018-02-05T06:37:46", "url": "https://files.pythonhosted.org/packages/66/ad/5b99113d4956431298f2093eca02aa92537b7fe8fa312040643981597689/docker-services-0.0.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "bde6c67e6fd62b5f5d2b8080e33f06e1", "sha256": "1efb5c61d9af0e80362bfde1f9d6a76c48dc62797e65586b25f00567d0b15950" }, "downloads": -1, "filename": "docker-services-0.1.1.tar.gz", "has_sig": false, "md5_digest": "bde6c67e6fd62b5f5d2b8080e33f06e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4626, "upload_time": "2018-02-05T06:40:48", "url": "https://files.pythonhosted.org/packages/18/52/6b97c400abe0e353134262486af9bd57769a288fa6345a7543a30288368f/docker-services-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3bcee9f659a1b6ff55bfa40211876b7e", "sha256": "ce6b8a5b22c8f519a70b814e293175fd6fbc82d7168a4e36272d57680c21d77e" }, "downloads": -1, "filename": "docker-services-0.2.0.tar.gz", "has_sig": false, "md5_digest": "3bcee9f659a1b6ff55bfa40211876b7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7633, "upload_time": "2018-02-11T23:19:49", "url": "https://files.pythonhosted.org/packages/7c/6d/daa563ab53fc0df8ef4d32f37b3f3760543af7329abf552a5939ebc56393/docker-services-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "00d71d488d0eabea1c208f2ea4a8c417", "sha256": "46827284fb8d15504ed98a56f2c35b0c76c9a99853619b05963cffdfe18b8917" }, "downloads": -1, "filename": "docker_services-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "00d71d488d0eabea1c208f2ea4a8c417", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 9315, "upload_time": "2018-02-12T02:38:42", "url": "https://files.pythonhosted.org/packages/7a/4f/f2734965d42cb258e65c1bdbd836ddc54c4c273a8ea14f6caf4cae1715d3/docker_services-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4eb550c96fa874b2eb2e9310f8db57b2", "sha256": "61c6a479e684e12e93dce3fe8785a3b157854e05c626747cd7514100321cfd12" }, "downloads": -1, "filename": "docker-services-0.2.1.tar.gz", "has_sig": false, "md5_digest": "4eb550c96fa874b2eb2e9310f8db57b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7685, "upload_time": "2018-02-12T02:38:49", "url": "https://files.pythonhosted.org/packages/70/a9/f5bd90a0fa22a537f8275a5c0da12784d9a3c9c99b912749ae88bd04877a/docker-services-0.2.1.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "2b13cd08b764f7e6cf2201d0879ff61f", "sha256": "8c9e3cf3fd9db33c376ae70d494da6edce40c63efec01b0d3759661518cd5e18" }, "downloads": -1, "filename": "docker_services-0.3.1-py2-none-any.whl", "has_sig": false, "md5_digest": "2b13cd08b764f7e6cf2201d0879ff61f", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7421, "upload_time": "2019-09-09T04:02:16", "url": "https://files.pythonhosted.org/packages/8b/48/bb29fbee0255ea1e6cdce2d82550329cc772edf247f9d4a710e7f6e0bfdd/docker_services-0.3.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "baf8dca19ed1bee6ed5cb675170951c8", "sha256": "cdb176a57c68bbfc4290dbc1407392aa76b171df49e1376896eb5168292f0496" }, "downloads": -1, "filename": "docker-services-0.3.1.tar.gz", "has_sig": false, "md5_digest": "baf8dca19ed1bee6ed5cb675170951c8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8161, "upload_time": "2019-09-09T04:02:17", "url": "https://files.pythonhosted.org/packages/ac/5a/9b26a9404f82a99ba9aff84ceb32f8a917f0cad5ea9b727d20b46692b143/docker-services-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "0e925126fe162887782356d263cdf323", "sha256": "4868f86eadf43d100242414acb6f6f37422c3d7244a71c454d7c674de35fffae" }, "downloads": -1, "filename": "docker_services-0.3.2-py2-none-any.whl", "has_sig": false, "md5_digest": "0e925126fe162887782356d263cdf323", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7422, "upload_time": "2019-09-09T04:38:45", "url": "https://files.pythonhosted.org/packages/7c/be/070406f26b925ccf1861510e46c76f0d2f363db91dbb42c1baac351b9546/docker_services-0.3.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a843275e3f4cd6b3c32d48014975c90", "sha256": "5f1fe8c4c6595722ebc20e4f83b8784d30800b7627b7e4da1af58ebb5d2f3974" }, "downloads": -1, "filename": "docker-services-0.3.2.tar.gz", "has_sig": false, "md5_digest": "3a843275e3f4cd6b3c32d48014975c90", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8162, "upload_time": "2019-09-09T04:38:48", "url": "https://files.pythonhosted.org/packages/c4/da/e57c19b03dfb8bb7ab39b3b439462cbe9327b493a0a8e3126bd9d83d5cc8/docker-services-0.3.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0e925126fe162887782356d263cdf323", "sha256": "4868f86eadf43d100242414acb6f6f37422c3d7244a71c454d7c674de35fffae" }, "downloads": -1, "filename": "docker_services-0.3.2-py2-none-any.whl", "has_sig": false, "md5_digest": "0e925126fe162887782356d263cdf323", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7422, "upload_time": "2019-09-09T04:38:45", "url": "https://files.pythonhosted.org/packages/7c/be/070406f26b925ccf1861510e46c76f0d2f363db91dbb42c1baac351b9546/docker_services-0.3.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a843275e3f4cd6b3c32d48014975c90", "sha256": "5f1fe8c4c6595722ebc20e4f83b8784d30800b7627b7e4da1af58ebb5d2f3974" }, "downloads": -1, "filename": "docker-services-0.3.2.tar.gz", "has_sig": false, "md5_digest": "3a843275e3f4cd6b3c32d48014975c90", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8162, "upload_time": "2019-09-09T04:38:48", "url": "https://files.pythonhosted.org/packages/c4/da/e57c19b03dfb8bb7ab39b3b439462cbe9327b493a0a8e3126bd9d83d5cc8/docker-services-0.3.2.tar.gz" } ] }