I have my sample postgres/django pipeline looked like this.
It seems curl do not wait django from ready before go ahead and result issues. I suppose I made some mistake somewhere?
import sys
import anyio
import dagger
async def main():
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
postgres = (
client.container().from_("postgres:14.7-alpine")
.with_env_variable('POSTGRES_PASSWORD', 'postgres')
.with_exposed_port(5432)
.with_exec([])
)
src = client.host().directory(".", exclude=['.venv'])
django = (
client.container().from_("python:3.10.6-slim-buster")
.with_service_binding('postgres', postgres)
# mount cloned repository into image
.with_mounted_directory("/app", src)
# set current working directory for next commands
.with_workdir("/app")
# install test dependencies
.with_exec('pip install -r requirements.txt'.split(' '))
.with_exec('python manage.py migrate'.split(' '))
.with_exec('python manage.py runserver 0.0.0.0:8000'.split(' '))
.with_exposed_port(8000)
)
curl = (
client.container()
.from_("alpine")
.with_service_binding("django", django)
.with_exec(["wget", "-O-", "http://django:8000/api/blog"])
)
await curl.exit_code()
# execute
version = await curl.stdout()
print(f"Hello from Dagger and {version}")
if __name__ == "__main__":
anyio.run(main)