diff --git a/.gitignore b/.gitignore index bb04034d..6f7a0505 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env # Build directory build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 75be74a9..76d1a23a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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() @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c3fa2e2a --- /dev/null +++ b/Dockerfile @@ -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/* \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..8f4281e5 --- /dev/null +++ b/Taskfile.yml @@ -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" + diff --git a/cmake/BuildInfo.cmake b/cmake/BuildInfo.cmake index 6e256f34..2ed92bde 100644 --- a/cmake/BuildInfo.cmake +++ b/cmake/BuildInfo.cmake @@ -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( diff --git a/cmake/Postgresdb.cmake b/cmake/Postgresdb.cmake new file mode 100644 index 00000000..efeca02d --- /dev/null +++ b/cmake/Postgresdb.cmake @@ -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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ee56ea15..f18d3e8a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/upgrade_test/CMakeLists.txt b/upgrade_test/CMakeLists.txt index bf96af5f..9bc1ee1b 100644 --- a/upgrade_test/CMakeLists.txt +++ b/upgrade_test/CMakeLists.txt @@ -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