This directory contains the devcontainer configuration for the dm package development environment.
devcontainer.json- Main devcontainer configurationdocker-compose.yml- Docker Compose file defining the development servicestest-postgres.R- Script to test PostgreSQL connectivity
- Image:
postgres:latest(latest PostgreSQL version) - Container:
devcontainer-postgres - Port: 5432
- Database: test
- User: compose
- Password: YourStrong!Passw0rd
- Image:
mariadb:latest(latest MariaDB version) - Container:
devcontainer-mariadb - Port: 3306
- Database: test
- User: compose
- Password: YourStrong!Passw0rd
- Image:
mcr.microsoft.com/mssql/server:2022-latest(SQL Server 2022 Express) - Container:
devcontainer-mssql - Port: 1433
- Database: test (created automatically)
- User: SA
- Password: YourStrong!Passw0rd
- Socket connections enabled via shared volume (
/var/run/postgresql) - Network connections available on standard ports (5432 for PostgreSQL, 3306 for MariaDB, 1433 for SQL Server)
- Environment variables pre-configured for easy R connections
- Health checks ensure databases are ready before starting dev environment
- Service-specific host environment variables for targeted testing
- Open the project in VS Code
- When prompted, reopen in devcontainer (or use Command Palette > "Dev Containers: Reopen in Container")
- All database services (PostgreSQL, MariaDB, SQL Server) will start automatically
- Test connectivity by running:
Rscript .devcontainer/test-postgres.R
# Test with PostgreSQL (default)
DM_TEST_SRC=postgres R -e 'testthat::test_local()'
# Test with MariaDB
DM_TEST_SRC=maria R -e 'testthat::test_local()'
# Test with SQL Server (requires ODBC drivers)
DM_TEST_SRC=mssql R -e 'testthat::test_local()'
# Test with data frames (no database)
DM_TEST_SRC=df R -e 'testthat::test_local()'The devcontainer environment supports multiple connection methods:
# Using environment variables (recommended)
con <- DBI::dbConnect(RPostgres::Postgres())
# Using explicit parameters
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = "postgres",
port = 5432,
user = "compose",
password = "YourStrong!Passw0rd",
dbname = "test"
)
# Using socket connection (if available)
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = "/var/run/postgresql",
user = "compose",
dbname = "test"
)# Using explicit parameters
con <- DBI::dbConnect(
RMariaDB::MariaDB(),
host = "mariadb",
port = 3306,
username = "compose",
password = "YourStrong!Passw0rd",
dbname = "test"
)# Using explicit parameters (requires ODBC drivers)
con <- DBI::dbConnect(
odbc::odbc(),
driver = "ODBC Driver 18 for SQL Server",
server = "mssql",
database = "test",
uid = "SA",
pwd = "YourStrong!Passw0rd",
port = 1433,
TrustServerCertificate = "yes"
)The following environment variables are set in the devcontainer:
PGHOST=postgresPGPORT=5432PGUSER=composePGPASSWORD=YourStrong!Passw0rdPGDATABASE=testPGSOCKET=/var/run/postgresql
MYSQL_HOST=mariadbMYSQL_PORT=3306MYSQL_USER=composeMYSQL_PASSWORD=YourStrong!Passw0rdMYSQL_DATABASE=test
MSSQL_HOST=mssqlMSSQL_PORT=1433MSSQL_USER=SAMSSQL_PASSWORD=YourStrong!Passw0rdMSSQL_DATABASE=test
DM_TEST_POSTGRES_HOST=postgres(service-specific, takes precedence)DM_TEST_MARIA_HOST=mariadb(service-specific, takes precedence)DM_TEST_MSSQL_HOST=mssql(service-specific, takes precedence)
- Database not starting: Check if ports 5432 (PostgreSQL) or 3306 (MariaDB) are already in use on your host
- Connection failures: Run the test script to diagnose connection issues
- Permission issues: The PostgreSQL socket directory is configured with 0777 permissions
- Container conflicts: Ensure no other database containers are running with the same names
- Environment variables not updated: Use
devcontainer up --workspace-folder . --remove-existing-containerto recreate containers
- Database data is persisted in Docker volumes (
postgres-data,mariadb-data) - Socket connections are available for PostgreSQL through the shared
postgres-socketvolume - PostgreSQL includes
pg_stat_statementsextension for performance monitoring - All PostgreSQL SQL statements are logged for development debugging
- MariaDB is configured with health checks to ensure availability before tests run
- Service-specific environment variables allow targeted testing of individual database backends