Skip to content

Commit

Permalink
Merge branch 'master' into replace_setup_py
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldemarmiesse authored Sep 29, 2023
2 parents e840f07 + 1dbaae8 commit 484d7cb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python_on_whales/components/compose/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DependencyCondition(BaseModel):

class ComposeServiceBuild(BaseModel):
context: Optional[Path] = None
dockerfile: Optional[Path] = None
args: Optional[Dict[str, Any]] = None
labels: Optional[Dict[str, Any]] = None


class ComposeServicePort(BaseModel):
Expand Down
25 changes: 25 additions & 0 deletions tests/python_on_whales/components/test-build-args.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.7"

services:
my_service:
build:
context: my_service_build
dockerfile: docker/somefile.dockerfile
args:
python_version: "3.78"
python_version_1: "3.78"
labels:
com.example.description: "Accounting webapp"
com.example.department: "Finance"
image: "some_random_image"
command: ping -c 7 www.google.com
ports:
- "5000:5000"
volumes:
- /tmp:/tmp
- dodo:/dodo
environment:
- DATADOG_HOST=something

volumes:
dodo: {}
41 changes: 41 additions & 0 deletions tests/python_on_whales/components/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,44 @@ def test_docker_compose_run_build():
== docker.image.list("some_random_image")[0].repo_tags[0].split(":latest")[0]
)
docker.image.remove("some_random_image", force=True)


def test_build_args():
compose_file = (
PROJECT_ROOT / "tests/python_on_whales/components/test-build-args.yml"
)
docker = DockerClient(compose_files=[compose_file])
config = docker.compose.config()

assert (
config.services["my_service"].build.context
== (compose_file.parent / "my_service_build").absolute()
)
assert config.services["my_service"].build.dockerfile == Path(
"docker/somefile.dockerfile"
)
assert config.services["my_service"].build.args == {
"python_version": "3.78",
"python_version_1": "3.78",
}
assert config.services["my_service"].build.labels == {
"com.example.description": "Accounting webapp",
"com.example.department": "Finance",
}
assert config.services["my_service"].image == "some_random_image"
assert config.services["my_service"].command == [
"ping",
"-c",
"7",
"www.google.com",
]

assert config.services["my_service"].ports[0].published == 5000
assert config.services["my_service"].ports[0].target == 5000

assert config.services["my_service"].volumes[0].source == "/tmp"
assert config.services["my_service"].volumes[0].target == "/tmp"
assert config.services["my_service"].volumes[1].source == "dodo"
assert config.services["my_service"].volumes[1].target == "/dodo"

assert config.services["my_service"].environment == {"DATADOG_HOST": "something"}

0 comments on commit 484d7cb

Please sign in to comment.