Skip to content

Commit

Permalink
Merge branch 'main' into pg16
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel authored Dec 13, 2023
2 parents 152182a + 6105840 commit aa8c707
Show file tree
Hide file tree
Showing 29 changed files with 384 additions and 209 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/builder-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ jobs:
- "15"
- "16"
pgrx_version:
- "0.7.4"
- "0.8.0"
- "0.8.3"
- "0.8.4"
- "0.9.0"
- "0.9.1"
- "0.9.7"
- "0.9.8"
- "0.10.0"
- "0.10.1"
- "0.10.2"
- "0.11.0"
# - "0.7.4"
# - "0.8.0"
# - "0.8.3"
# - "0.8.4"
# - "0.9.0"
# - "0.9.1"
# - "0.9.7"
# - "0.9.8"
# - "0.10.0"
# - "0.10.1"
# - "0.10.2"
# - "0.11.0"
- "0.11.1"
steps:
- name: Check out the repo
uses: actions/checkout@v3
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,38 @@ jobs:
changed_relative_to_ref: ${{ steps.versions.outputs.changed_relative_to_ref }}
ignore_dirs: ".tembo cli"

test:
name: Test extensions
runs-on:
- self-hosted
- dind
- large-8x8
container:
image: quay.io/tembo/trunk-test-tembo:0.0.27
options: --user root
needs:
- find_directories
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.find_directories.outputs.directories) }}
steps:
- uses: actions/[email protected]
- name: Install system dependencies
run: |
set -xe
apt-get update
apt-get install -y pkg-config libssl-dev gosu
- name: Test the extension within Docker
run: cd ${{ matrix.path }} && trunk build --test

build:
name: Build extensions
runs-on:
- self-hosted
- dind
- large-8x8
container:
image: quay.io/tembo/trunk-test-tembo:0.0.26
image: quay.io/tembo/trunk-test-tembo:0.0.27
options: --user root
needs:
- find_directories
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trunk-install-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- dind
- large-8x8
container:
image: quay.io/tembo/trunk-test-tembo:0.0.26
image: quay.io/tembo/trunk-test-tembo:0.0.27
options: --user root
env:
PGHOST: "localhost"
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pg-trunk"
version = "0.11.9"
version = "0.11.12"
edition = "2021"
authors = ["Steven Miller", "Ian Stanton", "Vinícius Miguel"]
description = "A package manager for PostgreSQL extensions"
Expand Down
30 changes: 19 additions & 11 deletions cli/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::SubCommand;
use crate::commands::generic_build::build_generic;
use crate::commands::pgrx::build_pgrx;
use crate::config;
use crate::config::{self, ExtensionConfiguration, LoadableLibrary};
use crate::trunk_toml::{cli_or_trunk, cli_or_trunk_opt, SystemDependencies};
use anyhow::anyhow;
use async_trait::async_trait;
Expand Down Expand Up @@ -49,13 +49,14 @@ pub struct BuildSettings {
pub name: Option<String>,
pub extension_name: Option<String>,
pub extension_dependencies: Option<Vec<String>>,
pub preload_libraries: Option<Vec<String>>,
pub configurations: Option<Vec<ExtensionConfiguration>>,
pub system_dependencies: Option<SystemDependencies>,
pub glob_patterns_to_include: Vec<glob::Pattern>,
pub platform: Option<String>,
pub dockerfile_path: Option<String>,
pub install_command: Option<String>,
pub should_test: bool,
pub loadable_libraries: Option<Vec<LoadableLibrary>>,
}

impl BuildCommand {
Expand Down Expand Up @@ -90,6 +91,11 @@ impl BuildCommand {

let name = cli_or_trunk(&self.name, |toml| &toml.extension.name, &trunk_toml);

let loadable_libraries = trunk_toml
.as_ref()
.and_then(|toml| toml.extension.loadable_libraries.as_ref())
.cloned();

let extension_name = cli_or_trunk_opt(
&self.extension_name,
|toml| &toml.extension.extension_name,
Expand All @@ -102,12 +108,6 @@ impl BuildCommand {
&trunk_toml,
);

let preload_libraries = cli_or_trunk_opt(
&self.preload_libraries,
|toml| &toml.extension.preload_libraries,
&trunk_toml,
);

let version = cli_or_trunk(&self.version, |toml| &toml.extension.version, &trunk_toml);

let platform = cli_or_trunk(&self.platform, |toml| &toml.build.platform, &trunk_toml);
Expand All @@ -129,6 +129,11 @@ impl BuildCommand {
glob_patterns_to_include.display()
);

let configurations = trunk_toml
.as_ref()
.and_then(|toml| toml.extension.configurations.as_ref())
.cloned();

let system_dependencies = trunk_toml
.as_ref()
.and_then(|toml| toml.dependencies.as_ref())
Expand Down Expand Up @@ -157,13 +162,14 @@ impl BuildCommand {
name,
extension_name,
extension_dependencies,
preload_libraries,
system_dependencies,
glob_patterns_to_include,
platform,
dockerfile_path,
install_command,
should_test: self.test,
configurations,
loadable_libraries,
})
}
}
Expand Down Expand Up @@ -232,10 +238,11 @@ impl SubCommand for BuildCommand {
&build_settings.output_path,
build_settings.extension_name,
build_settings.extension_dependencies,
build_settings.preload_libraries,
cargo_toml,
build_settings.system_dependencies,
build_settings.glob_patterns_to_include,
build_settings.configurations,
build_settings.loadable_libraries,
task,
)
.await?;
Expand Down Expand Up @@ -276,12 +283,13 @@ impl SubCommand for BuildCommand {
build_settings.name.clone().unwrap().as_str(),
build_settings.extension_name,
build_settings.extension_dependencies,
build_settings.preload_libraries,
build_settings.system_dependencies,
build_settings.version.clone().unwrap().as_str(),
build_settings.glob_patterns_to_include,
task,
build_settings.should_test,
build_settings.configurations,
build_settings.loadable_libraries,
)
.await?;
return Ok(());
Expand Down
7 changes: 5 additions & 2 deletions cli/src/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::io::Cursor;
use std::path::{Path, PathBuf};

use crate::commands::generic_build::GenericBuildError;
use crate::config::{ExtensionConfiguration, LoadableLibrary};
use crate::control_file::ControlFile;
use crate::manifest::Manifest;
use crate::sync_utils::{ByteStreamSyncReceiver, ByteStreamSyncSender};
Expand Down Expand Up @@ -399,13 +400,14 @@ pub async fn package_installed_extension_files(
docker: Docker,
container_id: &str,
package_path: &str,
preload_libraries: Option<Vec<String>>,
system_dependencies: Option<SystemDependencies>,
name: &str,
mut extension_name: Option<String>,
extension_version: &str,
extension_dependencies: Option<Vec<String>>,
inclusion_patterns: Vec<glob::Pattern>,
configurations: Option<Vec<ExtensionConfiguration>>,
loadable_libraries: Option<Vec<LoadableLibrary>>,
) -> Result<(), anyhow::Error> {
let name = name.to_owned();
let extension_version = extension_version.to_owned();
Expand Down Expand Up @@ -497,11 +499,12 @@ pub async fn package_installed_extension_files(
extension_version,
extension_dependencies,
manifest_version: 2,
preload_libraries,
architecture: target_arch,
sys: "linux".to_string(),
files: None,
dependencies: system_dependencies,
configurations,
loadable_libraries,
};
// If the docker copy command starts to stream data
println!("Create Trunk bundle:");
Expand Down
7 changes: 5 additions & 2 deletions cli/src/commands/generic_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::commands::containers::{
start_postgres,
};
use crate::commands::license::{copy_licenses, find_licenses};
use crate::config::{ExtensionConfiguration, LoadableLibrary};
use crate::trunk_toml::SystemDependencies;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -74,12 +75,13 @@ pub async fn build_generic(
name: &str,
extension_name: Option<String>,
extension_dependencies: Option<Vec<String>>,
preload_libraries: Option<Vec<String>>,
system_dependencies: Option<SystemDependencies>,
extension_version: &str,
inclusion_patterns: Vec<glob::Pattern>,
_task: Task,
should_test: bool,
configurations: Option<Vec<ExtensionConfiguration>>,
loadable_libraries: Option<Vec<LoadableLibrary>>,
) -> Result<(), GenericBuildError> {
println!("Building with name {}", &name);
println!("Building with version {}", &extension_version);
Expand Down Expand Up @@ -149,13 +151,14 @@ pub async fn build_generic(
docker.clone(),
&temp_container.id,
output_path,
preload_libraries,
system_dependencies,
name,
extension_name,
extension_version,
extension_dependencies,
inclusion_patterns,
configurations,
loadable_libraries,
)
.await?;

Expand Down
13 changes: 10 additions & 3 deletions cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use flate2::read::GzDecoder;
use log::{error, info, warn};
use reqwest;
use reqwest::Url;
use slicedisplay::SliceDisplay;
use std::ffi::OsStr;
use std::fs::File;
use std::io::{Read, Seek, Write};
Expand Down Expand Up @@ -439,10 +440,16 @@ fn print_post_installation_guide(manifest: &Manifest) {
}
// If the manifest has preload_libraries, then we need to add the extension to preload_libraries
// Output will look like preload_libraries = 'spl1,spl2,spl3'
if let Some(preload_libraries) = &manifest.preload_libraries {
let spl = preload_libraries.join(",");
if let Some(preload_libraries) = &manifest.loadable_libraries {
let libraries: Vec<_> = preload_libraries
.iter()
.map(|lib| &lib.library_name)
.collect();
println!("\nAdd the following to your postgresql.conf:");
println!("\tshared_preload_libraries = '{}'", spl);
println!(
"\tshared_preload_libraries = {}",
libraries.display().terminator('\'', '\'')
);
}

println!("\nEnable the extension with:");
Expand Down
23 changes: 18 additions & 5 deletions cli/src/commands/pgrx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use bollard::Docker;
use crate::commands::containers::{
build_image, exec_in_container, package_installed_extension_files, run_temporary_container,
};
use crate::config::{ExtensionConfiguration, LoadableLibrary};
use crate::trunk_toml::SystemDependencies;
use tokio::sync::mpsc;

Expand Down Expand Up @@ -57,8 +58,18 @@ pub enum PgrxBuildError {

fn semver_from_range(pgrx_range: &str) -> Result<String, PgrxBuildError> {
let versions = [
"0.11.0", "0.10.2", "0.10.1", "0.10.0", "0.9.8", "0.9.7", "0.9.1", "0.9.0", "0.8.4",
"0.8.3", "0.8.0", "0.7.4",
"0.11.1, 0.11.0",
"0.10.2",
"0.10.1",
"0.10.0",
"0.9.8",
"0.9.7",
"0.9.1",
"0.9.0",
"0.8.4",
"0.8.3",
"0.8.0",
"0.7.4",
];

if versions.contains(&pgrx_range) {
Expand Down Expand Up @@ -105,10 +116,11 @@ pub async fn build_pgrx(
output_path: &str,
extension_name: Option<String>,
extension_dependencies: Option<Vec<String>>,
preload_libraries: Option<Vec<String>>,
cargo_toml: toml::Table,
system_dependencies: Option<SystemDependencies>,
inclusion_patterns: Vec<glob::Pattern>,
configurations: Option<Vec<ExtensionConfiguration>>,
loadable_libraries: Option<Vec<LoadableLibrary>>,
_task: Task,
) -> Result<(), PgrxBuildError> {
let cargo_package_info = cargo_toml
Expand Down Expand Up @@ -231,13 +243,14 @@ pub async fn build_pgrx(
docker.clone(),
&temp_container.id,
output_path,
preload_libraries,
system_dependencies,
name,
extension_name,
extension_version,
extension_dependencies,
inclusion_patterns,
configurations,
loadable_libraries,
)
.await?;

Expand Down Expand Up @@ -274,7 +287,7 @@ mod tests {
assert_eq!(result.unwrap(), "0.8.4");
let result = semver_from_range(">=0.9.0, <0.10.0");
assert_eq!(result.unwrap(), "0.9.8");
let result = semver_from_range(">=0.10.0, <0.11.0");
let result = semver_from_range(">=0.10.0, <0.11.1");
assert_eq!(result.unwrap(), "0.10.2");
}
}
Loading

0 comments on commit aa8c707

Please sign in to comment.