Skip to content

Commit

Permalink
feat: Add ability to change image when running pmr
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbukachi authored and oakhan3 committed Nov 22, 2021
1 parent 3be758e commit c8679ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/pytest_mock_resources/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import enum
import subprocess # nosec

from pytest_mock_resources.config import get_env_config

postgres_image = get_env_config("postgres", "image") or "postgres:9.6.10-alpine"
mysql_image = get_env_config("mysql", "image") or "mysql:5.6"
mongo_image = get_env_config("mongo", "image") or "mongo:3.6"


@enum.unique
class FixtureBase(enum.Enum):
Expand All @@ -28,9 +34,9 @@ def command(self):
"POSTGRES_USER=user",
"-e",
"POSTGRES_PASSWORD=password",
"postgres:9.6.10-alpine",
postgres_image,
]
mongo_command = ["docker", "run", "-d", "--rm", "-p", "28017:27017", "mongo:3.6"]
mongo_command = ["docker", "run", "-d", "--rm", "-p", "28017:27017", mongo_image]
mysql_command = [
"docker",
"run",
Expand All @@ -42,7 +48,7 @@ def command(self):
"MYSQL_DATABASE=dev",
"-e",
"MYSQL_ROOT_PASSWORD=password",
"mysql:5.6",
mysql_image,
]
fixture_base_command_map = {
FixtureBase.MONGO: mongo_command,
Expand Down
7 changes: 5 additions & 2 deletions src/pytest_mock_resources/container/mongo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pytest

from pytest_mock_resources.compat import pymongo
from pytest_mock_resources.config import DockerContainerConfig, fallback
from pytest_mock_resources.config import DockerContainerConfig, fallback, get_env_config
from pytest_mock_resources.container.base import ContainerCheckFailed, get_container


mongo_image = get_env_config("mongo", "image") or "mongo:3.6"


class MongoConfig(DockerContainerConfig):
"""Define the configuration object for mongo.
Expand All @@ -25,7 +28,7 @@ class MongoConfig(DockerContainerConfig):

_fields = {"image", "host", "port", "ci_port", "root_database"}
_fields_defaults = {
"image": "mongo:3.6",
"image": mongo_image,
"port": 28017,
"ci_port": 27017,
"root_database": "dev-mongo",
Expand Down
7 changes: 5 additions & 2 deletions src/pytest_mock_resources/container/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import sqlalchemy
from pytest_mock_resources import compat

from pytest_mock_resources.config import DockerContainerConfig, fallback
from pytest_mock_resources.config import DockerContainerConfig, fallback, get_env_config
from pytest_mock_resources.container.base import ContainerCheckFailed, get_container


mysql_image = get_env_config("mysql", "image") or "mysql:5.6"


class MysqlConfig(DockerContainerConfig):
"""Define the configuration object for MySql.
Expand All @@ -29,7 +32,7 @@ class MysqlConfig(DockerContainerConfig):
name = "mysql"
_fields = {"image", "host", "port", "ci_port", "username", "password", "root_database"}
_fields_defaults = {
"image": "mysql:5.6",
"image": mysql_image,
"port": 3406,
"ci_port": 3306,
"username": "root",
Expand Down
7 changes: 5 additions & 2 deletions src/pytest_mock_resources/container/postgres.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pytest
import sqlalchemy

from pytest_mock_resources.config import DockerContainerConfig, fallback
from pytest_mock_resources.config import DockerContainerConfig, fallback, get_env_config
from pytest_mock_resources.container.base import ContainerCheckFailed, get_container


postgres_image = get_env_config("postgres", "image") or "postgres:9.6.10-alpine"


class PostgresConfig(DockerContainerConfig):
"""Define the configuration object for postgres.
Expand All @@ -28,7 +31,7 @@ class PostgresConfig(DockerContainerConfig):
name = "postgres"
_fields = {"image", "host", "port", "ci_port", "username", "password", "root_database"}
_fields_defaults = {
"image": "postgres:9.6.10-alpine",
"image": postgres_image,
"port": 5532,
"ci_port": 5432,
"username": "user",
Expand Down

0 comments on commit c8679ec

Please sign in to comment.