Skip to content

Commit

Permalink
chore: work in progress to attempt building a Postgres Quota Plugin f…
Browse files Browse the repository at this point in the history
…rom the GPDB
  • Loading branch information
francescotimperi committed Apr 17, 2024
1 parent 467fcf6 commit e3eaf5a
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
# Build directory
build*/

Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Git.cmake)
GitHash_Get(DISKQUOTA_GIT_HASH)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Gpdb.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Gpdb.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Postgresdb.cmake)


# set include directories for all sub-projects
Expand Down Expand Up @@ -85,7 +86,7 @@ set_target_properties(
C_STANDARD 99
LINKER_LANGUAGE "C")

if (${GP_MAJOR_VERSION} STRGREATER_EQUAL "7")
if (${PG_MAJORVERSION} STRGREATER_EQUAL "14")
TARGET_LINK_LIBRARIES(diskquota ${PG_LIB_DIR}/libpq.so)
endif()

Expand Down Expand Up @@ -160,8 +161,8 @@ BuildInfo_Create(${build_info_PATH}
VARS
DISKQUOTA_GIT_HASH
DISKQUOTA_VERSION
GP_MAJOR_VERSION
GP_VERSION
PG_MAJORVERSION
PG_VERSION
CMAKE_BUILD_TYPE)
# Create build-info end

Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM pgvector/pgvector:pg14

COPY . /tmp/diskquota
RUN cd /tmp/diskquota
RUN mkdir build

RUN apt-get update && \
apt-mark hold locales && \
apt-get install -y --no-install-recommends build-essential git postgresql-server-dev-14

RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
RUN echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null

RUN apt-get update && apt-get install -y cmake

RUN cd /tmp/diskquota/build
RUN cmake -S /tmp/diskquota -D PG_CONFIG=/usr/bin/pg_config
RUN make install

RUN mkdir /usr/share/doc/diskquota && \
cp LICENSE README.md SECURITY.md VERSiON /usr/share/doc/diskquota && \
rm -r /tmp/diskquota && \
apt-get remove -y build-essential postgresql-server-dev-$PG_MAJOR && \
apt-get autoremove -y && \
apt-mark unhold locales && \
rm -rf /var/lib/apt/lists/*
52 changes: 52 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

version: '3'

vars:
BASETAG: 14.1

env:
NUV_PG_QUOTA_TAG:
sh: git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD
NUV_PG_QUOTA_IMAGE: ghcr.io/nuvolaris/nuvolaris-pg

dotenv:
- .env

tasks:

image-tag:
- git tag -d $(git tag)
- git tag -f {{.P}}{{.BASETAG}}.$(date +%y%m%d%H%M)
- env PAGER= git tag

docker-login: >
echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USER --password-stdin
docker-setup:
- docker buildx create --use
- docker run -it --rm --privileged tonistiigi/binfmt --install all

# Docker image
build-and-push:
cmds:
- task: docker-setup
- task: docker-login
- "docker buildx build --platform linux/amd64,linux/arm64 . -t {{.NUV_PG_QUOTA_IMAGE}}:{{.NUV_PG_QUOTA_TAG}} --push"

4 changes: 2 additions & 2 deletions cmake/BuildInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# ${CMAKE_CURRENT_BINARY_DIR}/build-info
# VARS
# DISKQUOTA_GIT_HASH
# GP_MAJOR_VERSION)
# PG_MAJORVERSION)
# )
# will create a build info file:
# ❯ cat build-info
# DISKQUOTA_GIT_HASH = 151ed92
# GP_MAJOR_VERSION = 6
# PG_MAJORVERSION = 14

function(BuildInfo_Create path)
cmake_parse_arguments(
Expand Down
71 changes: 71 additions & 0 deletions cmake/Postgresdb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Use pg_config to detect postgres dependencies
#
# Variables:
#
# PG_CONFIG - the path to the pg_config executable to be used. this determines the
# version to be built with.
# PG_MAJOR_VERSION - the major version parsed from Postgres source
# PG_VERSION - The PG_VERSION string
# PG_BIN_DIR - location of user executables
# PG_INCLUDE_DIR - location of C header files of the client
# PG_INCLUDE_DIR_SERVER - location of C header files for the server
# PG_LIBS - LIBS value used when PostgreSQL was built
# PG_LIB_DIR - location of object code libraries
# PG_PKG_LIB_DIR - location of dynamically loadable modules
# PG_SHARE_DIR - location of architecture-independent support files
# PG_PGXS - location of extension makefile
# PG_CPP_FLAGS - CPPFLAGS value used when PostgreSQL was built
# PG_C_FLAGS - CFLAGS value used when PostgreSQL was built
# PG_LD_FLAGS - LDFLAGS value used when PostgreSQL was built
# PG_HOME - The installation directory of Greenplum
# PG_SRC_DIR - The directory of the postgres/greenplum source code

include_guard()
find_program(PG_CONFIG pg_config)
if(PG_CONFIG)
message(STATUS "Use '${PG_CONFIG}'")
else()
message(FATAL_ERROR "Unable to find 'pg_config'")
endif()
exec_program(${PG_CONFIG} ARGS --includedir OUTPUT_VARIABLE PG_INCLUDE_DIR)
exec_program(${PG_CONFIG} ARGS --includedir-server OUTPUT_VARIABLE PG_INCLUDE_DIR_SERVER)
exec_program(${PG_CONFIG} ARGS --pkglibdir OUTPUT_VARIABLE PG_PKG_LIB_DIR)
exec_program(${PG_CONFIG} ARGS --sharedir OUTPUT_VARIABLE PG_SHARE_DIR)
exec_program(${PG_CONFIG} ARGS --bindir OUTPUT_VARIABLE PG_BIN_DIR)
exec_program(${PG_CONFIG} ARGS --cppflags OUTPUT_VARIABLE PG_CPP_FLAGS)
exec_program(${PG_CONFIG} ARGS --cflags OUTPUT_VARIABLE PG_C_FLAGS)
exec_program(${PG_CONFIG} ARGS --ldflags OUTPUT_VARIABLE PG_LD_FLAGS)
exec_program(${PG_CONFIG} ARGS --libs OUTPUT_VARIABLE PG_LIBS)
exec_program(${PG_CONFIG} ARGS --libdir OUTPUT_VARIABLE PG_LIB_DIR)
exec_program(${PG_CONFIG} ARGS --pgxs OUTPUT_VARIABLE PG_PGXS)
get_filename_component(PG_HOME "${PG_BIN_DIR}/.." ABSOLUTE)
if (NOT PG_SRC_DIR)
get_filename_component(pgsx_SRC_DIR ${PG_PGXS} DIRECTORY)
set(makefile_global ${pgsx_SRC_DIR}/../Makefile.global)
# Some magic to find out the source code root from pg's Makefile.global
execute_process(
COMMAND_ECHO STDOUT
COMMAND
grep "^abs_top_builddir" ${makefile_global}
COMMAND
sed s/.*abs_top_builddir.*=\\\(.*\\\)/\\1/
OUTPUT_VARIABLE PG_SRC_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
string(STRIP ${PG_SRC_DIR} PG_SRC_DIR)
endif()

# Get the GP_MAJOR_VERSION from header
file(READ ${PG_INCLUDE_DIR}/pg_config.h config_header)
string(REGEX MATCH "#define *PG_MAJORVERSION *\"[0-9]+\"" macrodef "${config_header}")
string(REGEX MATCH "[0-9]+" PG_MAJORVERSION "${macrodef}")
if (PG_MAJORVERSION)
message(STATUS "Build extension for POSTGRESDB ${PG_MAJORVERSION}")
else()
message(FATAL_ERROR "Cannot read PG_MAJORVERSION from '${PG_INCLUDE_DIR}/pg_config.h'")
endif()
string(REGEX MATCH "#define *PG_VERSION *\"[^\"]*\"" macrodef "${config_header}")
string(REGEX REPLACE ".*\"\(.*\)\".*" "\\1" PG_VERSION "${macrodef}")
if (PG_VERSION)
message(STATUS "The exact POSTGRESDB version is '${PG_VERSION}'")
else()
message(FATAL_ERROR "Cannot read PG_VERSION from '${PG_INCLUDE_DIR}/pg_config.h'")
endif()
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(${CMAKE_SOURCE_DIR}/cmake/Regress.cmake)

list(APPEND isolation2_expected_DIR ${CMAKE_CURRENT_SOURCE_DIR}/isolation2/expected)
list(APPEND regress_expected_DIR ${CMAKE_CURRENT_SOURCE_DIR}/regress/expected)
if (${GP_MAJOR_VERSION} EQUAL 7)
if (${PG_MAJORVERSION} EQUAL 14)
list(APPEND isolation2_expected_DIR ${CMAKE_CURRENT_SOURCE_DIR}/isolation2/expected7)
list(APPEND regress_expected_DIR ${CMAKE_CURRENT_SOURCE_DIR}/regress/expected7)
# PLPYTHON_LANG_STR will be replaced by Regress.cmake
Expand Down
2 changes: 1 addition & 1 deletion upgrade_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(NOT DEFINED DISKQUOTA_DDL_CHANGE_CHECK)
STRING "Skip the DDL updates check. Should not be disabled on CI" FORCE)
endif()

if (${GP_MAJOR_VERSION} EQUAL 6)
if (${PG_MAJORVERSION} EQUAL 6)
list(APPEND schedule_files
${CMAKE_CURRENT_SOURCE_DIR}/schedule_1.0--2.0
${CMAKE_CURRENT_SOURCE_DIR}/schedule_2.0--1.0
Expand Down

0 comments on commit e3eaf5a

Please sign in to comment.