Add postgres to devcontainer / compose

This commit is contained in:
Willem van den Ende 2026-03-18 11:22:54 +00:00
parent 2d97353649
commit 7c3aac56ec
5 changed files with 45 additions and 6 deletions

View File

@ -1,10 +1,13 @@
{ {
"$schema": "https://containers.dev/implementors/json_schema/", "$schema": "https://containers.dev/implementors/json_schema/",
"build": { "dockerComposeFile": "docker-compose.yml",
"dockerfile": "Dockerfile" "service": "app",
"workspaceFolder": "/workspaces/firehose",
"remoteUser": "root",
"containerEnv": {
"DB_HOST": "db",
"HOME": "/home/vscode"
}, },
"remoteUser": "vscode",
"runArgs": [],
"features": { "features": {
"ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {}, "ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},

View File

@ -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:

View File

@ -4,7 +4,7 @@ import Config
config :firehose, Firehose.Repo, config :firehose, Firehose.Repo,
username: "postgres", username: "postgres",
password: "postgres", password: "postgres",
hostname: "localhost", hostname: System.get_env("DB_HOST") || "localhost",
database: "firehose_dev", database: "firehose_dev",
stacktrace: true, stacktrace: true,
show_sensitive_data_on_connection_error: true, show_sensitive_data_on_connection_error: true,

View File

@ -8,7 +8,7 @@ import Config
config :firehose, Firehose.Repo, config :firehose, Firehose.Repo,
username: "postgres", username: "postgres",
password: "postgres", password: "postgres",
hostname: "localhost", hostname: System.get_env("DB_HOST") || "localhost",
database: "firehose_test#{System.get_env("MIX_TEST_PARTITION")}", database: "firehose_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox, pool: Ecto.Adapters.SQL.Sandbox,
pool_size: System.schedulers_online() * 2 pool_size: System.schedulers_online() * 2

8
test.sh Executable file
View File

@ -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