Skip to content

Commit

Permalink
Replace postgres seed with DbContainer solution
Browse files Browse the repository at this point in the history
Issue currently is the tests for postgres fail:
The container exits on postgres (not mysql, for identical both
entrypoint and command...) with error:

    sh: 8: source: not found
    sh: 8: _main: not found

I'm still tracking it down, because it's weird that /bin/sh says
"source" does not exist (but not with mysql) but the _main should be
available from the sourced entrypoint script.
  • Loading branch information
Jb DOYON committed Jun 2, 2024
1 parent 9dfc358 commit b9a45ad
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions modules/postgres/testcontainers/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import tarfile
from io import BytesIO
from pathlib import Path
from time import sleep
from typing import Optional

Expand Down Expand Up @@ -68,6 +65,9 @@ class PostgresContainer(DbContainer):
"""

seed_mountpoint: str = "/docker-entrypoint-initdb.d/"
startup_command: str = "source /usr/local/bin/docker-entrypoint.sh; _main "

def __init__(
self,
image: str = "postgres:latest",
Expand All @@ -87,6 +87,8 @@ def __init__(
self.port = port
self.driver = f"+{driver}" if driver else ""
self.seed = seed
if self.seed is not None:
super().override_command_for_seed(self.startup_command)

self.with_exposed_ports(self.port)

Expand Down Expand Up @@ -126,14 +128,3 @@ def _connect(self) -> None:
count += 1

raise RuntimeError("Postgres could not get into a ready state")

def _transfer_seed(self) -> None:
if self.seed is None:
return
src_path = Path(self.seed)
dest_path = "/docker-entrypoint-initdb.d/"
with BytesIO() as archive, tarfile.TarFile(fileobj=archive, mode="w") as tar:
for filename in src_path.iterdir():
tar.add(filename.absolute(), arcname=filename.relative_to(src_path))
archive.seek(0)
self.get_wrapped_container().put_archive(dest_path, archive)

0 comments on commit b9a45ad

Please sign in to comment.