diff --git a/.github/workflows/ci-run-on-pr.yaml b/.github/workflows/ci-run-on-pr.yaml new file mode 100644 index 0000000..eb52986 --- /dev/null +++ b/.github/workflows/ci-run-on-pr.yaml @@ -0,0 +1,74 @@ +name: Minimal workflow for CI/CD +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +env: + COMPOSE_DOCKER_CLI_BUILD: 1 + +jobs: + integration_tests: + strategy: + matrix: + pgversion: + #- 14 + #- 15 + #- 16 + - 17 + #- 18 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + + - name: update to docker-compose v2 + run: | + sudo apt-get install -y curl + sudo curl -SL https://github.com/docker/compose/releases/download/v2.34.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + docker-compose --version + + - name: start DB2 (background) + run: | + docker-compose up db2 -d + env: + PGVERSION: ${{ matrix.pgversion }} + + - name: create rpms folder + run: | + mkdir -p rpms + chmod 777 rpms + + - name: build rpm + run: | + docker-compose up builder --exit-code-from builder + env: + PGVERSION: ${{ matrix.pgversion }} + + - name: copy rpm to postgres context + run: | + cp -av rpms docker/postgres/ + + - name: start postgres + run: | + docker-compose up postgres -d + env: + PGVERSION: ${{ matrix.pgversion }} + + - name: wait for db2 and postgres + run: | + set -x + for ((i=0;i<60;i++)); do + docker-compose exec postgres /usr/pgsql-${{ matrix.pgversion }}/bin/pg_isready && break + sleep 1 + done + for ((i=0;i<60;i++)); do + docker-compose exec db2 ls /database/config/db2inst1/sqllib/ctrl/db2strst.lck + sleep 1 + done + docker-compose logs db2 + docker-compose exec db2 sh -c "ps -ef" + env: + PGVERSION: ${{ matrix.pgversion }} diff --git a/.gitignore b/.gitignore index 3660933..c1fc822 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.so test.bash *.bc -.vscode/ \ No newline at end of file +.vscode/ +rpms \ No newline at end of file diff --git a/db2_fdw.spec b/db2_fdw.spec new file mode 100644 index 0000000..dca62e6 --- /dev/null +++ b/db2_fdw.spec @@ -0,0 +1,41 @@ +%global _prefix /usr/local +Summary: PostgreSQL %{pgversion} db2 foreign data wrapper +Name: postgresql%{pgversion}-db2_fdw +Version: %{fdw_version} +Release: 1%{?dist} +License: PostgreSQL License +Group: Applications/Databases +Url: https://github.com/Living-Mainframe/db2_fdw +%undefine _disable_source_fetch +BuildArch: x86_64 + +Requires: postgresql%{pgversion}-server +%global __requires_exclude ^libdb2.*\\.so + +%description +db2_fdw is a PostgreSQL extension that provides a Foreign Data Wrapper for easy and efficient +access to DB2 databases, including pushdown of WHERE conditions and required columns as well +as comprehensive EXPLAIN support. + +%install + +cd /host +make clean +make +%make_install + +#mkdir -p %{buildroot}/usr/pgsql-%pgversion/lib/bitcode/db2_fdw/ +#mkdir -p %{buildroot}/usr/pgsql-%pgversion/share/extension/ +#mkdir -p %{buildroot}/usr/pgsql-%pgversion/doc/extension/ +# +#%{__install} -m 0755 %{_builddir}/usr/pgsql-%pgversion/lib/db2_fdw.so %{buildroot}/usr/pgsql-%pgversion/lib/db2_fdw.so +#%{__install} -m 0644 %{_builddir}/usr/pgsql-%pgversion/lib/bitcode/db2_fdw/* %{buildroot}/usr/pgsql-%pgversion/lib/bitcode/db2_fdw/ +#%{__install} -m 0644 %{_builddir}/usr/pgsql-%pgversion/share/extension/db2_fdw* %{buildroot}/usr/pgsql-%pgversion/share/extension/ +#%{__install} -m 0644 %{_builddir}/usr/pgsql-%pgversion/share/extension/uninstall_db2_fdw* %{buildroot}/usr/pgsql-%pgversion/share/extension/ +#%{__install} -m 0644 %{_builddir}/usr/pgsql-%pgversion/doc/extension/db2_fdw.md %{buildroot}/usr/pgsql-%pgversion/doc/extension/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +/usr/pgsql-%{pgversion}/* diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5bdc9a4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +services: + db2: + image: icr.io/db2_community/db2 + platform: linux/amd64 + privileged: true + environment: + LICENSE: accept + DB2INST1_PASSWORD: db2fdw + DBNAME: testdb + volumes: + - db2-data:/database + builder: + image: builder + environment: + DB2_HOME: /opt/ibm/db2/V12.1 + build: + context: docker/builder + args: + - PGVERSION=${PGVERSION} + platform: linux/amd64 + volumes: + - ./:/host + command: /scripts/build_rpm.sh + postgres: + build: + context: docker/postgres + environment: + LD_LIBRARY_PATH: /opt/ibm/db2/V12.1/lib64 + #rpmsigner: + # image: builder + # command: + # - /host/scripts/sign_rpms.sh + # volumes: + # - ./:/host + # environment: + # - GPG_PASSPHRASE + # - GPG_KEY_B64 + #dev: + # image: builder + # platform: linux/amd64 + # volumes: + # - ./:/host + # command: + # - /bin/bash + # - -c + # - while sleep 1; do echo -n .; done +volumes: + db2-data: diff --git a/docker/builder/Dockerfile b/docker/builder/Dockerfile new file mode 100644 index 0000000..bffe42c --- /dev/null +++ b/docker/builder/Dockerfile @@ -0,0 +1,20 @@ +FROM --platform=${BUILDPLATFORM} icr.io/db2_community/db2 AS builder + +FROM rockylinux:9 +ARG PGVERSION +ENV PGVERSION=${PGVERSION} + +COPY --from=builder /opt/ibm/db2/V12.1/include /opt/ibm/db2/V12.1/include +COPY --from=builder /opt/ibm/db2/V12.1/lib64 /opt/ibm/db2/V12.1/lib64 +COPY --from=builder /opt/ibm/db2/V12.1/bin /opt/ibm/db2/V12.1/bin +COPY scripts /scripts + +RUN dnf install -y epel-release && \ + dnf install 'dnf-command(config-manager)' && \ + dnf config-manager --enable crb && \ + # See https://forums.rockylinux.org/t/status-code-404-on-mirrors-upon-dnf-update/3204/6 + find /etc/yum.repos.d -name "Rocky-*.repo" -exec sed -i 's/^mirrorlist=/#&/' {} \; -exec sed -i '/^#baseurl=/s/^#//' {} \; && \ + dnf update -y && \ + dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm && \ + dnf -qy module disable postgresql && \ + dnf install -y postgresql${PGVERSION}-server postgresql${PGVERSION}-devel git rpm-build rpm-sign diff --git a/docker/builder/scripts/build_rpm.sh b/docker/builder/scripts/build_rpm.sh new file mode 100755 index 0000000..43bab59 --- /dev/null +++ b/docker/builder/scripts/build_rpm.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex +export PATH="${PATH}:/usr/pgsql-${PGVERSION}/bin" +echo %pgversion "${PGVERSION}" >>~/.rpmmacros + +git config --global --add safe.directory /host +cd /host +FDW_MAJOR=$(git describe --tags --abbrev=0 | grep -o '[0-9.]\+') +echo %fdw_version "${FDW_MAJOR}" >>~/.rpmmacros + +rpmbuild -ba /host/db2_fdw.spec + +cp ~/rpmbuild/RPMS/x86_64/postgresql*-db2_fdw-*.rpm /host/rpms/ diff --git a/docker/builder/scripts/sign_rpms.sh b/docker/builder/scripts/sign_rpms.sh new file mode 100755 index 0000000..b492365 --- /dev/null +++ b/docker/builder/scripts/sign_rpms.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +DEST=${DEST:-/host} +cd "$DEST" +export GPG_TTY=$(tty) + +sed "s/PASSPHRASE/${GPG_PASSPHRASE}/" config/rpmmacros >~/.rpmmacros +echo "Importing pubkey..." +gpg --import --no-tty --batch --yes