diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 731e74b..0a76dd0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,13 @@ { "$schema": "https://containers.dev/implementors/json_schema/", - "build": { - "dockerfile": "Dockerfile" + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/firehose", + "remoteUser": "root", + "containerEnv": { + "DB_HOST": "db", + "HOME": "/home/vscode" }, - "remoteUser": "vscode", - "runArgs": [], "features": { "ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/jsburckhardt/devcontainer-features/uv:1": {}, diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..5b3e22d --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,28 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ..:/workspaces/firehose:cached + command: sleep infinity + depends_on: + db: + condition: service_healthy + + db: + image: postgres:16 + restart: unless-stopped + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + volumes: + - pgdata:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + +volumes: + pgdata: diff --git a/app/config/dev.exs b/app/config/dev.exs index 1c0b8a2..2aa21f5 100644 --- a/app/config/dev.exs +++ b/app/config/dev.exs @@ -4,7 +4,7 @@ import Config config :firehose, Firehose.Repo, username: "postgres", password: "postgres", - hostname: "localhost", + hostname: System.get_env("DB_HOST") || "localhost", database: "firehose_dev", stacktrace: true, show_sensitive_data_on_connection_error: true, diff --git a/app/config/test.exs b/app/config/test.exs index 83a8cc7..ee30aa3 100644 --- a/app/config/test.exs +++ b/app/config/test.exs @@ -8,7 +8,7 @@ import Config config :firehose, Firehose.Repo, username: "postgres", password: "postgres", - hostname: "localhost", + hostname: System.get_env("DB_HOST") || "localhost", database: "firehose_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, pool_size: System.schedulers_online() * 2 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..f315783 --- /dev/null +++ b/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +export ELIXIR_ERL_OPTIONS="+fnu" +/home/vscode/.local/bin/mise trust /workspaces/firehose/mise.toml 2>/dev/null +eval "$(/home/vscode/.local/bin/mise activate bash)" +cd /workspaces/firehose/app +mix deps.get +mix test