Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat: dockerfile for building migration runner image (#9417)

Shailesh46c434e94689
diff --git a/docker-compose-development.yml b/docker-compose-development.yml
index 539bf47fd4..6bdda27c9e 100644
--- a/docker-compose-development.yml
+++ b/docker-compose-development.yml
@@ -46,8 +46,15 @@ services:
timeout: 5s
migration_runner:
- image: rust:latest
- command: "bash -c 'cargo install diesel_cli --no-default-features --features postgres && cargo install just && just migrate'"
+ image: debian:trixie-slim
+ pull_policy: always
+ command: >
+ bash -c "
+ apt-get update && apt-get install -y curl xz-utils &&
+ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/diesel-rs/diesel/releases/latest/download/diesel_cli-installer.sh | bash &&
+ curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin &&
+ export PATH="$${PATH}:$${HOME}/.cargo/bin" &&
+ just migrate"
working_dir: /app
networks:
- router_net
@@ -64,7 +71,7 @@ services:
FROM rust:latest
RUN apt-get update && \
apt-get install -y protobuf-compiler
- RUN rustup component add rustfmt clippy
+ RUN rustup component add rustfmt clippy
command: cargo run --bin router -- -f ./config/docker_compose.toml
working_dir: /app
ports:
diff --git a/docker-compose.yml b/docker-compose.yml
index 21979e91aa..e16dd74466 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -57,11 +57,14 @@ services:
timeout: 5s
migration_runner:
- image: rust:latest
+ image: debian:trixie-slim
+ pull_policy: always
command: >
bash -c "
- curl -fsSL https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash &&
- cargo binstall diesel_cli just --no-confirm &&
+ apt-get update && apt-get install -y curl xz-utils &&
+ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/diesel-rs/diesel/releases/latest/download/diesel_cli-installer.sh | bash &&
+ curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin &&
+ export PATH="$${PATH}:$${HOME}/.cargo/bin" &&
just migrate"
working_dir: /app
networks:
@@ -71,7 +74,7 @@ services:
environment:
# format -> postgresql://DB_USER:DB_PASSWORD@HOST:PORT/DATABASE_NAME
- DATABASE_URL=postgresql://db_user:db_pass@pg:5432/hyperswitch_db
-
+
mailhog:
image: mailhog/mailhog
networks:
@@ -215,12 +218,12 @@ services:
container_name: create-default-user
depends_on:
hyperswitch-server:
- condition: service_healthy
+ condition: service_healthy
hyperswitch-control-center:
condition: service_started
environment:
- HYPERSWITCH_SERVER_URL=http://hyperswitch-server:8080
- - HYPERSWITCH_CONTROL_CENTER_URL=http://hyperswitch-control-center:9000
+ - HYPERSWITCH_CONTROL_CENTER_URL=http://hyperswitch-control-center:9000
entrypoint:
[
"/bin/sh",
@@ -231,7 +234,7 @@ services:
- ./scripts/create_default_user.sh:/create_default_user.sh
networks:
- router_net
-
+
poststart-hook:
image: curlimages/curl-base:latest
container_name: poststart-hook
@@ -506,4 +509,4 @@ services:
- HYPERSWITCH_CLIENT_URL=http://localhost:9050
- HYPERSWITCH_SERVER_URL=http://localhost:8080
labels:
- logs: "promtail"
\ No newline at end of file
+ logs: "promtail"
diff --git a/docker/migration-runner.Dockerfile b/docker/migration-runner.Dockerfile
new file mode 100644
index 0000000000..e32fea8d68
--- /dev/null
+++ b/docker/migration-runner.Dockerfile
@@ -0,0 +1,37 @@
+# Migration Runner Dockerfile for Hyperswitch
+# This image contains migration files and diesel CLI for offline migration execution
+
+FROM debian:trixie-slim
+
+# Install necessary packages
+RUN apt-get update && apt-get install -y \
+ curl \
+ tar \
+ xz-utils \
+ && rm -rf /var/lib/apt/lists/*
+
+# Create the 'app' user and group
+RUN useradd --user-group --system --create-home --no-log-init app
+
+# Switch to the 'app' user
+USER app:app
+
+# Install diesel CLI
+RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/diesel-rs/diesel/releases/latest/download/diesel_cli-installer.sh | sh
+
+ENV PATH="/home/app/.cargo/bin:$PATH"
+
+# Set working directory
+WORKDIR /hyperswitch
+
+# Copy migration files and diesel config from the workspace
+COPY --chown=app:app ./migrations/ ./migrations/
+COPY --chown=app:app ./diesel.toml ./diesel.toml
+COPY --chown=app:app ./crates/diesel_models/src/schema.rs ./crates/diesel_models/src/schema.rs
+COPY --chown=app:app ./crates/diesel_models/drop_id.patch ./crates/diesel_models/drop_id.patch
+
+# Copy the migration runner script
+COPY --chown=app:app ./scripts/migration_runner_entrypoint.sh ./migration_runner_entrypoint.sh
+
+# Default command to run migrations
+CMD ["./migration_runner_entrypoint.sh"]
diff --git a/scripts/migration_runner_entrypoint.sh b/scripts/migration_runner_entrypoint.sh
new file mode 100755
index 0000000000..a1bde9fa62
--- /dev/null
+++ b/scripts/migration_runner_entrypoint.sh
@@ -0,0 +1,15 @@
+#! /usr/bin/env bash
+
+set -eo pipefail
+
+# Check if DATABASE_URL is provided, otherwise construct it from individual components
+if [[ -z "${DATABASE_URL:-}" ]]; then
+ if [[ -z "${POSTGRES_HOST:-}" || -z "${POSTGRES_USER:-}" || -z "${POSTGRES_PASSWORD:-}" || -z "${POSTGRES_DB:-}" ]]; then
+ echo 'Error: Either DATABASE_URL or all of POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB must be provided'
+ exit 1
+ fi
+ export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT:-5432}/${POSTGRES_DB}"
+fi
+
+# Run diesel migrations
+diesel migration run