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

This commit is contained in:
Shailesh
2025-10-01 17:49:50 +05:30
committed by GitHub
parent 382fae1a1c
commit 46c434e946
4 changed files with 73 additions and 11 deletions

View File

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

View File

@@ -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"
logs: "promtail"

View File

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

View File

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