Skip to content

Commit e823b92

Browse files
authored
CI(build-tools): Remove libpq from build image (#8206)
## Problem We use `build-tools` image as a base image to build other images, and it has a pretty old `libpq-dev` installed (v13; it wasn't that old until I removed system Postgres 14 from `build-tools` image in #6540) ## Summary of changes - Remove `libpq-dev` from `build-tools` image - Set `LD_LIBRARY_PATH` for tests (for different Postgres binaries that we use, like psql and pgbench) - Set `PQ_LIB_DIR` to build Storage Controller - Set `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` in the Storage Controller where it calls Postgres binaries
1 parent aea5cfe commit e823b92

File tree

9 files changed

+56
-11
lines changed

9 files changed

+56
-11
lines changed

.github/actions/run-python-test-set/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ runs:
114114
export PLATFORM=${PLATFORM:-github-actions-selfhosted}
115115
export POSTGRES_DISTRIB_DIR=${POSTGRES_DISTRIB_DIR:-/tmp/neon/pg_install}
116116
export DEFAULT_PG_VERSION=${PG_VERSION#v}
117+
export LD_LIBRARY_PATH=${POSTGRES_DISTRIB_DIR}/v${DEFAULT_PG_VERSION}/lib
117118
118119
if [ "${BUILD_TYPE}" = "remote" ]; then
119120
export REMOTE_ENV=1

.github/workflows/benchmarking.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ jobs:
379379

380380
- name: Add Postgres binaries to PATH
381381
run: |
382+
LD_LIBRARY_PATH="${POSTGRES_DISTRIB_DIR}/v${DEFAULT_PG_VERSION}/lib"
383+
export LD_LIBRARY_PATH
384+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
385+
382386
${POSTGRES_DISTRIB_DIR}/v${DEFAULT_PG_VERSION}/bin/pgbench --version
383387
echo "${POSTGRES_DISTRIB_DIR}/v${DEFAULT_PG_VERSION}/bin" >> $GITHUB_PATH
384388

.github/workflows/build-build-tools-image.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
tags: neondatabase/build-tools:${{ inputs.image-tag }}-${{ matrix.arch }}
8383

8484
- name: Remove custom docker config directory
85+
if: always()
8586
run: |
8687
rm -rf /tmp/.docker-custom
8788

.github/workflows/build_and_test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ jobs:
335335

336336
- name: Run cargo build
337337
run: |
338+
PQ_LIB_DIR=$(pwd)/pg_install/v16/lib
339+
export PQ_LIB_DIR
338340
${cov_prefix} mold -run cargo build $CARGO_FLAGS $CARGO_FEATURES --bins --tests
339341
340342
# Do install *before* running rust tests because they might recompile the
@@ -383,6 +385,11 @@ jobs:
383385
env:
384386
NEXTEST_RETRIES: 3
385387
run: |
388+
PQ_LIB_DIR=$(pwd)/pg_install/v16/lib
389+
export PQ_LIB_DIR
390+
LD_LIBRARY_PATH=$(pwd)/pg_install/v16/lib
391+
export LD_LIBRARY_PATH
392+
386393
#nextest does not yet support running doctests
387394
cargo test --doc $CARGO_FLAGS $CARGO_FEATURES
388395

.github/workflows/neon_extra_builds.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,19 @@ jobs:
232232

233233
- name: Run cargo build
234234
run: |
235+
PQ_LIB_DIR=$(pwd)/pg_install/v16/lib
236+
export PQ_LIB_DIR
235237
mold -run cargo build --locked $CARGO_FLAGS $CARGO_FEATURES --bins --tests -j$(nproc)
236238
237239
- name: Run cargo test
238240
env:
239241
NEXTEST_RETRIES: 3
240242
run: |
243+
PQ_LIB_DIR=$(pwd)/pg_install/v16/lib
244+
export PQ_LIB_DIR
245+
LD_LIBRARY_PATH=$(pwd)/pg_install/v16/lib
246+
export LD_LIBRARY_PATH
247+
241248
cargo nextest run $CARGO_FEATURES -j$(nproc)
242249
243250
# Run separate tests for real S3

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ ARG CACHEPOT_BUCKET=neon-github-dev
4242
COPY --from=pg-build /home/nonroot/pg_install/v14/include/postgresql/server pg_install/v14/include/postgresql/server
4343
COPY --from=pg-build /home/nonroot/pg_install/v15/include/postgresql/server pg_install/v15/include/postgresql/server
4444
COPY --from=pg-build /home/nonroot/pg_install/v16/include/postgresql/server pg_install/v16/include/postgresql/server
45+
COPY --from=pg-build /home/nonroot/pg_install/v16/lib pg_install/v16/lib
4546
COPY --chown=nonroot . .
4647

4748
# Show build caching stats to check if it was used in the end.
4849
# Has to be the part of the same RUN since cachepot daemon is killed in the end of this RUN, losing the compilation stats.
4950
RUN set -e \
50-
&& RUSTFLAGS="-Clinker=clang -Clink-arg=-fuse-ld=mold -Clink-arg=-Wl,--no-rosegment" cargo build \
51+
&& PQ_LIB_DIR=$(pwd)/pg_install/v16/lib RUSTFLAGS="-Clinker=clang -Clink-arg=-fuse-ld=mold -Clink-arg=-Wl,--no-rosegment" cargo build \
5152
--bin pg_sni_router \
5253
--bin pageserver \
5354
--bin pagectl \

Dockerfile.build-tools

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ RUN set -e \
2626
liblzma-dev \
2727
libncurses5-dev \
2828
libncursesw5-dev \
29-
libpq-dev \
3029
libreadline-dev \
3130
libseccomp-dev \
3231
libsqlite3-dev \

control_plane/src/local_env.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,16 @@ impl LocalEnv {
325325
}
326326
}
327327

328+
pub fn pg_dir(&self, pg_version: u32, dir_name: &str) -> anyhow::Result<PathBuf> {
329+
Ok(self.pg_distrib_dir(pg_version)?.join(dir_name))
330+
}
331+
328332
pub fn pg_bin_dir(&self, pg_version: u32) -> anyhow::Result<PathBuf> {
329-
Ok(self.pg_distrib_dir(pg_version)?.join("bin"))
333+
self.pg_dir(pg_version, "bin")
330334
}
335+
331336
pub fn pg_lib_dir(&self, pg_version: u32) -> anyhow::Result<PathBuf> {
332-
Ok(self.pg_distrib_dir(pg_version)?.join("lib"))
337+
self.pg_dir(pg_version, "lib")
333338
}
334339

335340
pub fn pageserver_bin(&self) -> PathBuf {

control_plane/src/storage_controller.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,37 @@ impl StorageController {
155155
.expect("non-Unicode path")
156156
}
157157

158-
/// Find the directory containing postgres binaries, such as `initdb` and `pg_ctl`
158+
/// Find the directory containing postgres subdirectories, such `bin` and `lib`
159159
///
160160
/// This usually uses STORAGE_CONTROLLER_POSTGRES_VERSION of postgres, but will fall back
161161
/// to other versions if that one isn't found. Some automated tests create circumstances
162162
/// where only one version is available in pg_distrib_dir, such as `test_remote_extensions`.
163-
pub async fn get_pg_bin_dir(&self) -> anyhow::Result<Utf8PathBuf> {
163+
async fn get_pg_dir(&self, dir_name: &str) -> anyhow::Result<Utf8PathBuf> {
164164
let prefer_versions = [STORAGE_CONTROLLER_POSTGRES_VERSION, 15, 14];
165165

166166
for v in prefer_versions {
167-
let path = Utf8PathBuf::from_path_buf(self.env.pg_bin_dir(v)?).unwrap();
167+
let path = Utf8PathBuf::from_path_buf(self.env.pg_dir(v, dir_name)?).unwrap();
168168
if tokio::fs::try_exists(&path).await? {
169169
return Ok(path);
170170
}
171171
}
172172

173173
// Fall through
174174
anyhow::bail!(
175-
"Postgres binaries not found in {}",
176-
self.env.pg_distrib_dir.display()
175+
"Postgres directory '{}' not found in {}",
176+
dir_name,
177+
self.env.pg_distrib_dir.display(),
177178
);
178179
}
179180

181+
pub async fn get_pg_bin_dir(&self) -> anyhow::Result<Utf8PathBuf> {
182+
self.get_pg_dir("bin").await
183+
}
184+
185+
pub async fn get_pg_lib_dir(&self) -> anyhow::Result<Utf8PathBuf> {
186+
self.get_pg_dir("lib").await
187+
}
188+
180189
/// Readiness check for our postgres process
181190
async fn pg_isready(&self, pg_bin_dir: &Utf8Path) -> anyhow::Result<bool> {
182191
let bin_path = pg_bin_dir.join("pg_isready");
@@ -229,12 +238,17 @@ impl StorageController {
229238
.unwrap()
230239
.join("storage_controller_db");
231240
let pg_bin_dir = self.get_pg_bin_dir().await?;
241+
let pg_lib_dir = self.get_pg_lib_dir().await?;
232242
let pg_log_path = pg_data_path.join("postgres.log");
233243

234244
if !tokio::fs::try_exists(&pg_data_path).await? {
235245
// Initialize empty database
236246
let initdb_path = pg_bin_dir.join("initdb");
237247
let mut child = Command::new(&initdb_path)
248+
.envs(vec![
249+
("LD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
250+
("DYLD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
251+
])
238252
.args(["-D", pg_data_path.as_ref()])
239253
.spawn()
240254
.expect("Failed to spawn initdb");
@@ -269,7 +283,10 @@ impl StorageController {
269283
&self.env.base_data_dir,
270284
pg_bin_dir.join("pg_ctl").as_std_path(),
271285
db_start_args,
272-
[],
286+
vec![
287+
("LD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
288+
("DYLD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
289+
],
273290
background_process::InitialPidFile::Create(self.postgres_pid_file()),
274291
retry_timeout,
275292
|| self.pg_isready(&pg_bin_dir),
@@ -324,7 +341,10 @@ impl StorageController {
324341
&self.env.base_data_dir,
325342
&self.env.storage_controller_bin(),
326343
args,
327-
[],
344+
vec![
345+
("LD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
346+
("DYLD_LIBRARY_PATH".to_owned(), pg_lib_dir.to_string()),
347+
],
328348
background_process::InitialPidFile::Create(self.pid_file()),
329349
retry_timeout,
330350
|| async {

0 commit comments

Comments
 (0)