Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
postgres_version: ["18", "17", "17.6", "16", "16.10"]
postgres_version: ["latest", "18", "17", "17.6", "16", "16.10"]
fail-fast: false

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
postgres_version: ["18", "17", "17.6", "16", "16.10"]
platform: ["linux/amd64", "linux/arm64"]
postgres_version: ["latest", "18", "17", "17.6", "16", "16.10"]
platform: ["linux/amd64"]
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG POSTGRES_VERSION=17.5
ARG POSTGRES_VERSION=latest

# Builder stage: compile the Rust binary
FROM rust:slim AS builder
Expand Down
17 changes: 17 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ pub fn run(cmd: &str) {
panic!("Command failed: {}", cmd);
}
}

/// Run a shell command and return its stdout as a trimmed String.
/// Panics if the command fails to execute or returns a non-zero exit code.
pub fn run_output(cmd: &str) -> String {
let output = Command::new("sh")
.arg("-c")
.arg(cmd)
.output()
.expect("Failed to execute command");

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
panic!("Command failed: {}\nstderr: {}", cmd, stderr);
}

String::from_utf8_lossy(&output.stdout).trim().to_string()
}
22 changes: 20 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use crate::common::run;
use crate::common::{run, run_output};

mod common;
mod extensions;
Expand All @@ -14,7 +14,25 @@ async fn main() {
panic!("Insert PostgreSQL version as argument");
}

let pg_version = &args[1];
// If user passed "latest", detect the numeric version from the installed postgres binary.
// Otherwise use the provided version string (e.g. "15.3" or "15").
let mut pg_version = args[1].clone();
if pg_version.eq_ignore_ascii_case("latest") {
println!("🔎 Detecting PostgreSQL version from the base image (requested: latest)...");
// Try `postgres --version`. This requires that the base image already provides the postgres binary.
let ver_output = run_output("postgres --version");
// Typical output: "postgres (PostgreSQL) 15.3"
// We take the last whitespace-separated token as the numeric version.
let numeric_version = ver_output
.split_whitespace()
.last()
.expect("Failed to parse postgres --version output")
.to_string();

println!("ℹ️ Detected PostgreSQL version: {}", numeric_version);
pg_version = numeric_version;
}

let pg_major = pg_version.split(".").next().unwrap();

println!(
Expand Down
Loading