Skip to content

Commit

Permalink
Use Docker Compose version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 6, 2024
1 parent 2dd73f1 commit 8407d3c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ acceptance: acceptance-in acceptance-out ## Run the acceptance tests

.PHONY: acceptance-run
acceptance-run: tests ## Start the application used to run the acceptance tests
cd acceptance_tests/tests/; docker-compose up --detach db db_slave
cd acceptance_tests/tests/; docker-compose run -T --no-deps app /app/scripts/wait-db
cd acceptance_tests/tests/; docker-compose up --detach
cd acceptance_tests/tests/; docker compose up --detach db db_slave
cd acceptance_tests/tests/; docker compose run -T --no-deps app /app/scripts/wait-db
cd acceptance_tests/tests/; docker compose up --detach

.PHONY: acceptance-in
acceptance-in: acceptance-run ## Run the internal acceptance tests
cd acceptance_tests/tests/; docker-compose exec -T acceptance pytest -vv --color=yes $(PYTEST_ARGS) tests
cd acceptance_tests/tests/; docker compose exec -T acceptance pytest -vv --color=yes $(PYTEST_ARGS) tests

.PHONY: acceptance-out
acceptance-out: acceptance-run ## Run the external acceptance tests
Expand All @@ -49,7 +49,7 @@ acceptance-out: acceptance-run ## Run the external acceptance tests

.PHONY: acceptance-stop
acceptance-stop: ## Stop the application used to run the acceptance tests
cd acceptance_tests/tests/; docker-compose down
cd acceptance_tests/tests/; docker compose down

.PHONY: build_docker
build_docker:
Expand Down Expand Up @@ -89,7 +89,7 @@ pull: ## Pull the Docker images
.PHONY: run
run: build_test_app build_docker ## Run the test application
# cp acceptance_tests/tests/docker-compose.override.sample.yaml acceptance_tests/tests/docker-compose.override.yaml
cd acceptance_tests/tests/; docker-compose up --detach
cd acceptance_tests/tests/; docker compose up --detach

.PHONY: mypy_local
mypy_local: .venv/timestamp
Expand Down
10 changes: 6 additions & 4 deletions acceptance_tests/out/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def __init__(self, cwd: str) -> None:
self.cwd = os.path.join(os.getcwd(), cwd)
self.cwd = cwd

def dc(self, args: list[str], **kwargs: Any) -> str:
def dc(self, args: list[str], version=2, **kwargs: Any) -> str:
docker_compose = ["docker-compose"] if version == 1 else ["docker", "compose"]
return cast(
str,
subprocess.run( # nosec
["docker-compose", *args],
[*docker_compose, *args],
**{
"cwd": self.cwd,
"stderr": subprocess.STDOUT,
Expand All @@ -40,9 +41,10 @@ def dc(self, args: list[str], **kwargs: Any) -> str:
).stdout,
)

def dc_process(self, args: list[str], **kwargs: Any) -> subprocess.CompletedProcess[str]:
def dc_process(self, args: list[str], version=2, **kwargs: Any) -> subprocess.CompletedProcess[str]:
docker_compose = ["docker-compose"] if version == 1 else ["docker", "compose"]
return subprocess.run( # type: ignore[no-any-return, call-overload] # pylint: disable=subprocess-run-check # noqa
["docker-compose", *args],
[*docker_compose, *args],
**{
"encoding": "utf-8",
"cwd": self.cwd,
Expand Down
2 changes: 1 addition & 1 deletion acceptance_tests/out/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_logs_request_id(app2_connection, composition):
app2_connection.get_json("ping", headers={"X-Request-ID": "42 is the answer"})
logs = composition.dc(["logs", "app2"]).split("\n")
print("Got logs: " + repr(logs))
logs = [l for l in logs if re.search(r"\|.{4} \{", l)]
logs = [l for l in logs if re.search(r"\| \{", l)]
logs = [json.loads(l[l.index("{") :]) for l in logs]
logs = [l for l in logs if l["logger_name"] == "c2cwsgiutils_app.services.ping"]
assert logs[-1]["request_id"] == "42 is the answer"
9 changes: 6 additions & 3 deletions acceptance_tests/out/tests/test_stats_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ def test_standalone(prometheus_stats_db_connection, composition):
"""
# To be able to debug
composition.dc_process(["logs", "stats_db"])
ps = [l for l in composition.dc(["ps"]).split("\n") if "c2cwsgiutils_stats_db_" in l]
ps = [l for l in composition.dc(["ps"]).split("\n")]
print("\n".join(ps))
ps = [l for l in ps if "c2cwsgiutils-stats_db-" in l]
assert len(ps) == 1
assert " Up " in ps[0]
print("Call Prometheus URL")
prometheus_stats_db_connection.session.get(prometheus_stats_db_connection.base_url)
ps = [l for l in composition.dc(["ps"]).split("\n") if "c2cwsgiutils_stats_db_" in l]
ps = [l for l in composition.dc(["ps"]).split("\n")]
print("\n".join(ps))
ps = [l for l in ps if "c2cwsgiutils-stats_db-" in l]
assert len(ps) == 1
assert ps[0].strip().endswith(" Exit 0")
# TODO: verify that the container exited correctly
# assert ps[0].strip().endswith(" Exit 0")

0 comments on commit 8407d3c

Please sign in to comment.