Skip to content

Add Support for Custom Dev Container Initialization (#1441) - #3549

Draft
ljluestc wants to merge 2 commits into
ariga:masterfrom
ljluestc:custom_dev_1441
Draft

Add Support for Custom Dev Container Initialization (#1441)#3549
ljluestc wants to merge 2 commits into
ariga:masterfrom
ljluestc:custom_dev_1441

Conversation

@ljluestc

Copy link
Copy Markdown

Add Support for Custom Dev Container Initialization (#1441)

Description

This PR resolves Issue #1441 by adding a --dev-init flag to the Atlas CLI, enabling users to customize development database containers (e.g., Docker-based PostgreSQL instances) before database initialization. The feature supports use cases such as creating directories for PostgreSQL tablespaces and copying files (e.g., for PGXN extensions) into the container.

Changes

  • CLI Update: Introduced the --dev-init flag to atlas schema apply, atlas migrate diff, and atlas migrate apply commands when using a Docker-based --dev-url (e.g., docker://postgres/15/test). The flag accepts a file path to a shell script (e.g., file://init-dev.sh).
  • Dev Container Logic: Updated Docker container initialization in atlas/sql/postgres to:
    • Mount the user-provided script to /docker-entrypoint-initdb.d/init-dev.sh.
    • Mount an optional directory (via --dev-files) for copying files (e.g., extension files) to /tmp/extensions.
    • Execute the script during container startup, before database initialization.
  • Validation: Added checks for script existence and executability, with descriptive error messages.
  • Documentation: Updated docs/cli-reference.md to document --dev-init and --dev-files flags, including examples.
  • Example Script: Included a sample init-dev.sh in the documentation for creating tablespace directories and copying extension files.

Example Usage

atlas migrate diff "my_migration" \
  --dir "file://migrations" \
  --to "file://schema.hcl" \
  --dev-url "docker://postgres/15/test" \
  --dev-init "file://init-dev.sh" \
  --dev-files "file://extensions"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manipulate the dev containers

1 participant