diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..fe6e7806 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "warsql-devcontainer", + "image": "samagragovernance/postgres:latest-pg15", + "extensions": [ + "ms-vscode-remote.vscode-remote-extensionpack" + ], + "settings": {}, + "forwardPorts": [5432], + "postCreateCommand": "pip install -r requirements.txt" +} diff --git a/.github/ISSUE_TEMPLATE /c4gt.md b/.github/ISSUE_TEMPLATE /c4gt.md new file mode 100644 index 00000000..e3cbd23d --- /dev/null +++ b/.github/ISSUE_TEMPLATE /c4gt.md @@ -0,0 +1,96 @@ +--- +name: C4GT +about: C4GT Community Issues Template +title: "[C4GT] Button for likes" +labels: C4GT Community +assignees: '' + +--- + +## Description +[Provide a brief description of the feature, including why it is needed and what it will accomplish. You can skip any of Goals, Expected Outcome, Implementation Details, Mockups / Wireframes if they are irrelevant] + +## Goals +- [ ] [Goal 1] +- [ ] [Goal 2] +- [ ] [Goal 3] +- [ ] [Goal 4] +- [ ] [Goal 5] + +## Expected Outcome +[Describe in detail what the final product or result should look like and how it should behave.] + +## Acceptance Criteria +- [ ] [Criteria 1] +- [ ] [Criteria 2] +- [ ] [Criteria 3] +- [ ] [Criteria 4] +- [ ] [Criteria 5] + +## Implementation Details +[List any technical details about the proposed implementation, including any specific technologies that will be used.] + +## Mockups / Wireframes +[Include links to any visual aids, mockups, wireframes, or diagrams that help illustrate what the final product should look like. This is not always necessary, but can be very helpful in many cases.] + +--- + +### Project +[Project Name] + +### Organization Name: +[Organization Name] + +### Domain +[Area of governance] + + + +### Tech Skills Needed: +[Required technical skills for the project] + +### Mentor(s) +[@Mentor1] [@Mentor2] [@Mentor3] + +### Complexity +Pick one of [High]/[Medium]/[Low] + +### Category +Pick one or more of [CI/CD], [Integrations], [Performance Improvement], [Security], [UI/UX/Design], [Bug], [Feature], [Documentation], [Deployment], [Test], [PoC] + +### Sub Category +Pick one or more of [API], [Database], [Analytics], [Refactoring], [Data Science], [Machine Learning], [Accessibility], [Internationalization], [Localization], [Frontend], [Backend], [Mobile], [SEO], [Configuration], [Deprecation], [Breaking Change], [Maintenance], [Support], [Question], [Technical Debt], [Beginner friendly], [Research], [Reproducible], [Needs Reproduction]. diff --git a/.github/ISSUE_TEMPLATE/c4gt-community-ticket.md b/.github/ISSUE_TEMPLATE/c4gt-community-ticket.md new file mode 100644 index 00000000..2b9a3fce --- /dev/null +++ b/.github/ISSUE_TEMPLATE/c4gt-community-ticket.md @@ -0,0 +1,58 @@ +--- +name: C4GT Community Ticket +about: C4GT Community Ticket +title: C4GT +labels: C4GT Community +assignees: '' + +--- + +## Description +There is a need for a commenting system that will allow users to interact with the blog posts. This will increase user engagement and provide feedback to the blog authors. + +## Goals +- [ ] Add a comment section to each blog post +- [ ] Implement a moderation system for comments +- [ ] Ensure comments are tied to a registered user +- [ ] Implement spam and bot protection for the comments +- [ ] Add notification system for new comments + +## Expected Outcome +- Users must be registered and logged in to leave a comment. +- Each comment should include the user's name, profile picture (if available), comment text, and timestamp. +- Comments should be displayed in chronological order, with the most recent comment at the top. +- An email notification should be sent to the blog post author when a new comment is made. +- Blog post authors and administrators should be able to moderate comments (approve, deny, delete). + +## Acceptance Criteria +- [ ] A registered user can submit a comment on a blog post. +- [ ] The comment appears on the blog post after approval from the post author or administrator. +- [ ] An email notification is sent to the blog post author when a new comment is posted. +- [ ] Comments can be moderated by the blog post author and administrators. +- [ ] Commenting system is resistant to spam and bot attacks. + +## Implementation Details +- Leverage Django's built-in commenting framework (if applicable) +- Use JavaScript and AJAX for real-time comment posting and updates +- Consider integrating with a service like Akismet for spam protection +- Use Django's built-in email function for the notification system + +## Mockups / Wireframes +(Here, you can link to any visual aids, mockups, wireframes, or diagrams that help illustrate what the final product should look like. This is not always necessary, but can be very helpful in many cases.) + +--- + +### Project +OpenBlog Platform + +### Organization Name: +The name of the organization proposing the project. + +### Domain +The area of governance the project pertains to (ex: agri, healthcare, ed etc). + +### Tech Skills Needed: +Django, Typescript, NextJS, Akismet + +### Mentor(s) +@ChakshuGautam @Shruti3004 @sukhpreetssekhon diff --git a/.github/workflows/configure_jekyll.yml b/.github/workflows/configure_jekyll.yml new file mode 100644 index 00000000..559bddf5 --- /dev/null +++ b/.github/workflows/configure_jekyll.yml @@ -0,0 +1,51 @@ +# Sample workflow for building and deploying a Jekyll site to GitHub Pages +name: Deploy Jekyll with GitHub Pages dependencies preinstalled + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./ + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/image-analysis-comment.yml b/.github/workflows/image-analysis-comment.yml new file mode 100644 index 00000000..dbf79c0b --- /dev/null +++ b/.github/workflows/image-analysis-comment.yml @@ -0,0 +1,97 @@ +# image-analysis.yml and image-analysis-comment.yml workflows, are used to calculate and comment the size difference between Dockerfile in the main branch and the changes made in a pull request. + +name: comment Image Analysis on PR + +# this workflow writes all the messages present in the comment artifact to the respective Pull Request so only one parallel run is required +concurrency: + group: ${{ github.workflow }} + +on: + workflow_run: + workflows: ["Image Analysis"] + types: + - completed + +jobs: + comment-on-pr: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write + actions: write + steps: + - name: Download the comments list + id: download-artifact + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: image-analysis.yml + name: image-analysis-comments + check_artifacts: true + search_artifacts: true + if_no_artifact_found: fail + + # set up dependency for github scripts + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: | + npm install fs + + - name: Comment on PR + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Modified from https://github.com/kanga333/comment-hider + async function hideComment(issueNumber,userName,reason){ + const comments = await github.issues.listComments({ + owner:context.repo.owner, + repo:context.repo.repo, + issue_number: issueNumber + }); + const ids = []; + for (const r of comments.data) { + if (r.user !== null && r.user.login !== userName) { + continue; + } + ids.push(r.node_id); + } + ids.splice(-1,1); + for ( let id of ids){ + const resp = await github.graphql(` + mutation { + minimizeComment(input: {classifier: ${reason}, subjectId: "${id}"}) { + minimizedComment { + isMinimized + } + } + } + `); + + if (resp.errors) { + core.setFailed(`${resp.errors[0].message}`); + } + } + } + var fs = require('fs'); + var comments = JSON.parse(fs.readFileSync('./comments.json')); + console.log(comments); + while (comments.length > 0) { + const comment = comments[0]; + hideComment(comment.issue_number,'github-actions[bot]','OUTDATED') ; + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: comment.issue_number, + body: comment.body + }); + comments.shift(); + } + + - name: Delete the comment list + uses: jimschubert/delete-artifacts-action@v1 + with: + log_level: "debug" + artifact_name: image-analysis-comments + min_bytes: "0" diff --git a/.github/workflows/image-analysis.yml b/.github/workflows/image-analysis.yml new file mode 100644 index 00000000..71336b23 --- /dev/null +++ b/.github/workflows/image-analysis.yml @@ -0,0 +1,112 @@ +# image-analysis.yml and image-analysis-comment.yml workflows, are used to calculate and comment the size difference between Dockerfiles in the main branch and the changes made in a pull request. +name: Image Analysis + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_run: + workflows: ["Smoke Test Docker Image"] + types: [completed] + +env: + ORG: timescaledev + TS_VERSION: main + PLATFORM: linux/amd64 + +jobs: + image-analysis: + name: PG${{ matrix.pg }}-${{ matrix.type }}-analysis + runs-on: ubuntu-latest + permissions: + actions: write #write permission is need to delete actions + strategy: + max-parallel: 1 # Running sequentially to add comments to the comment artifact without overwriting + fail-fast: false + matrix: + pg: [15] + type: ["bitnami", "normal"] + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Check out the source + uses: actions/checkout@v3 + + - name: Download image built from the PR + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: smoke-test.yml + name: ${{matrix.type}}-${{ github.event.workflow_run.head_sha }} + check_artifacts: true + search_artifacts: true + if_no_artifact_found: fail + skip_unpack: true # Docker images are too big to unpack with this action + - name: unzip the image artifact + run: | + unzip ${{matrix.type}}-${{ github.event.workflow_run.head_sha }}.zip + + - name: Load image into docker + run: | + cat ./${{matrix.type}}-${{ github.event.workflow_run.head_sha }}.tar | docker import - smoketest-image + + # set up dependency for github scripts + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: | + npm install fs + + - name: Download metrics of main branch + if: github.event.workflow_run.event == 'pull_request' + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: image-analysis.yml + name: image-metric-${{matrix.type}} + check_artifacts: true + search_artifacts: true + if_no_artifact_found: warn + + - name: Download comments artifact + if: github.event.workflow_run.event == 'pull_request' + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: image-analysis.yml + name: image-analysis-comments + check_artifacts: true + search_artifacts: true + workflow_conclusion: "" # Consider current successful runs of matrix jobs + if_no_artifact_found: warn + + - name: Analyse image + uses: actions/github-script@v6.4.1 + with: + workspace: ${{ github.workspace }} + image-type: ${{matrix.type}} + script: | + const fs = require('fs') + const script = require('./image_size.js') + console.log(script({github, context, exec,core,fs})) + + - name: Upload the updated comments + uses: actions/upload-artifact@v3 + if: github.event.workflow_run.event == 'pull_request' + with: + name: image-analysis-comments + path: comments.json + if-no-files-found: error + + - name: Upload metrics from main branch + uses: actions/upload-artifact@v3 + if: github.event.workflow_run.event == 'push' + with: + name: image-metric-${{matrix.type}} + path: image-metrics-${{matrix.type}}.json + if-no-files-found: error + + + - name: Delete docker image artifact + uses: jimschubert/delete-artifacts-action@v1 + with: + log_level: "debug" + artifact_name: ${{matrix.type}}-${{ github.event.workflow_run.head_sha }} + min_bytes: "0" diff --git a/.github/workflows/smoke-test-packer.yml b/.github/workflows/smoke-test-packer.yml new file mode 100644 index 00000000..504cd8d0 --- /dev/null +++ b/.github/workflows/smoke-test-packer.yml @@ -0,0 +1,129 @@ +name: Smoke Test packer template + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + pull_request: + push: + branches: + - main + +env: + ORG: timescaledev + TS_VERSION: main + PLATFORM: linux/amd64 + +jobs: + smoketest-all: + name: PG${{ matrix.pg }}-${{ matrix.type }}-paacker + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + pg: [15] + type: ['alpine', 'bitnami'] + steps: + - name: Check out the source + uses: actions/checkout@v3 + + + - name: Build packer template + run: | + cd packer + PACKER_LOG=1 packer init . && packer build -only 'warpsql.docker.${{matrix.type}}' -var image_repository=smoketest-image warpsql.pkr.hcl + + - name: Install psql + run: sudo apt install postgresql-client + + - name: Run the smoke test + run: | + set -eu + export PGHOST=localhost + export PGUSER=postgres + export PGPASSWORD=test1234 + docker container stop smoketest-container || true + docker container rm smoketest-container || true + docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=${PGPASSWORD} --name smoketest-container smoketest-image:latest + for _ in {1..120} + do + if [ -z "$(docker container ls -q --filter name=smoketest-container)" ] + then + echo "Smoketest container is not running" + exit 1 + fi + if psql -c "select 1" + then + bash ./test/smoke_test/smoke_test.sh + break + fi + sleep 1 + done + if ! psql -c "select 1" + then + echo "Cannot connect to PostgreSQL" + exit 1 + fi + + - name: Show the logs + if: always() + run: | + docker logs smoketest-container + + smoketest-individual: + name: PG${{ matrix.pg }}-${{ matrix.type }}-${{matrix.extention}}-packer + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + pg: [15] + type: ['alpine', 'bitnami'] + extention: ['timescaledb','pgvector','postgis','zombodb','pg_repack','pgautofailover','hll','citus'] + steps: + - name: Check out the source + uses: actions/checkout@v3 + + + - name: Build packer template + run: | + cd packer + PACKER_LOG=1 packer init . && packer build -only 'warpsql.docker.${{matrix.type}}' -var image_repository=smoketest-image -var extentions='${{matrix.extention}}' warpsql.pkr.hcl + + - name: Install psql + run: sudo apt install postgresql-client + + - name: Run the smoke test + run: | + set -eu + export PGHOST=localhost + export PGUSER=postgres + export PGPASSWORD=test1234 + docker container stop smoketest-container || true + docker container rm smoketest-container || true + docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=${PGPASSWORD} --name smoketest-container smoketest-image:latest + for _ in {1..120} + do + if [ -z "$(docker container ls -q --filter name=smoketest-container)" ] + then + echo "Smoketest container is not running" + exit 1 + fi + if psql -c "select 1" + then + bash ./test/smoke_test/smoke_test.sh "${{matrix.extention}}" + break + fi + sleep 1 + done + if ! psql -c "select 1" + then + echo "Cannot connect to PostgreSQL" + exit 1 + fi + + - name: Show the logs + if: always() + run: | + docker logs smoketest-container diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index e5151234..384f54e6 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -1,4 +1,9 @@ name: Smoke Test Docker Image + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: pull_request: push: @@ -12,24 +17,37 @@ env: jobs: smoketest: - name: PG${{ matrix.pg }}-${{ matrix.type }} + name: PG${{ matrix.pg }}-${{ matrix.type }}-docker runs-on: ubuntu-latest strategy: fail-fast: false matrix: pg: [15] - type: ['normal', 'bitnami'] + type: ["normal", "bitnami"] steps: + - name: set the correct commit sha + env: + EVENT: ${{github.event_name}} + run: | + if [ "$EVENT" == 'pull_request' ] + then + echo "commit=${{ github.event.pull_request.head.sha}}" >> "$GITHUB_ENV" + else + echo "commit=${{ github.sha}}" >> "$GITHUB_ENV" + fi - name: Check out the source uses: actions/checkout@v3 + - name: Expose GitHub Runtime + uses: crazy-max/ghaction-github-runtime@v2 + - name: Build Docker Image for TimescaleDB run: | if [ ${{ matrix.type }} == bitnami ] then cd bitnami fi - make image PG_VER=pg${{ matrix.pg }} TAG_VERSION=smoketest-image BETA=1 + make build-docker-cache image PG_VER=pg${{ matrix.pg }} TAG_VERSION=smoketest-image BETA=1 - name: Install psql run: sudo apt install postgresql-client @@ -52,6 +70,7 @@ jobs: fi if psql -c "select 1" then + bash ./test/smoke_test/smoke_test.sh break fi sleep 1 @@ -66,3 +85,21 @@ jobs: if: always() run: | docker logs smoketest-container + + - name: export the image + run: | + set -eux + export PGHOST=localhost + export PGUSER=postgres + export PGPASSWORD=test1234 + docker container stop smoketest-container || true + docker container rm smoketest-container || true + docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=${PGPASSWORD} --name smoketest-container smoketest-image + docker export smoketest-container > ${{matrix.type}}-${{ env.commit }}.tar + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.type}}-${{ env.commit }} + path: ./${{matrix.type}}-${{ env.commit }}.tar + retention-days: 1 diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 63a3e4fd..00000000 --- a/.gitpod.yml +++ /dev/null @@ -1,10 +0,0 @@ -# This configuration file was automatically generated by Gitpod. -# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) -# and commit this file to your remote git repository to share the goodness with others. - -# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart - -tasks: - - init: make - - diff --git a/Dockerfile b/Dockerfile index 78d8c632..f8f694a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,9 @@ RUN set -ex \ && rm -rf /build \ && sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample +# Update to shared_preload_libraries +RUN echo "shared_preload_libraries = 'citus,timescaledb,pg_stat_statements,pgautofailover'" >> /usr/local/share/postgresql/postgresql.conf.sample + # Adding PG Vector RUN cd /tmp @@ -84,12 +87,257 @@ RUN apk add --no-cache --virtual .build-deps \ krb5-dev \ libc-dev \ llvm15 \ - clang \ make \ cmake \ + clang15 \ util-linux-dev \ && git clone --branch v0.4.1 https://github.com/pgvector/pgvector.git \ && cd /pgvector \ && ls \ && make \ && make install + +## Adding Citus + +# Install Citus dependencies +RUN apk add --no-cache --virtual .citus-deps \ + curl \ + jq + +# Install Citus +ARG CITUS_VERSION +RUN set -ex \ + && apk add --no-cache --virtual .citus-build-deps \ + gcc \ + libc-dev \ + make \ + curl-dev \ + lz4-dev \ + zstd-dev \ + clang \ + krb5-dev \ + icu-dev \ + libxslt-dev \ + libxml2-dev \ + llvm15-dev \ + && CITUS_DOWNLOAD_URL="https://github.com/citusdata/citus/archive/refs/tags/v${CITUS_VERSION}.tar.gz" \ + && curl -L -o /tmp/citus.tar.gz "${CITUS_DOWNLOAD_URL}" \ + && tar -C /tmp -xvf /tmp/citus.tar.gz \ + && chown -R postgres:postgres /tmp/citus-${CITUS_VERSION} \ + && cd /tmp/citus-${CITUS_VERSION} \ + && PATH="/usr/local/pgsql/bin:$PATH" ./configure \ + && make \ + && make install \ + && cd ~ \ + && rm -rf /tmp/citus.tar.gz /tmp/citus-${CITUS_VERSION} \ + && apk del .citus-deps .citus-build-deps + + +ARG POSTGIS_VERSION +ARG POSTGIS_SHA256 + +RUN set -eux \ + \ + && if [ $(printf %.1s "$POSTGIS_VERSION") == 3 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.11 ; \ + export GDAL_ALPINE_VER=3.6.4-r4 ; \ + export PROJ_ALPINE_VER=9.2 ; \ + elif [ $(printf %.1s "$POSTGIS_VERSION") == 2 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.8 ; \ + export GDAL_ALPINE_VER=3.2 ; \ + export PROJ_ALPINE_VER=7.2 ; \ + \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/community' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/community' >> /etc/apk/repositories ; \ + \ + else \ + set -eux ; \ + echo ".... unknown \$POSTGIS_VERSION ...." ; \ + exit 1 ; \ + fi \ + \ + && apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + openssl \ + tar \ + \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \ + && echo "${POSTGIS_SHA256} *postgis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ + && apk add --no-cache --virtual .build-deps \ + \ + gdal-dev~=${GDAL_ALPINE_VER} \ + geos-dev~=${GEOS_ALPINE_VER} \ + proj-dev~=${PROJ_ALPINE_VER} \ + \ + autoconf \ + automake \ + clang-dev \ + clang15 \ + cunit-dev \ + file \ + g++ \ + gcc \ + gettext-dev \ + git \ + json-c-dev \ + libtool \ + libxml2-dev \ + llvm-dev \ + llvm15 \ + make \ + pcre-dev \ + perl \ + protobuf-c-dev \ + \ +# build PostGIS + \ + && cd /usr/src/postgis \ + && gettextize \ + && ./autogen.sh \ + && ./configure \ + --with-pcredir="$(pcre-config --prefix)" \ + && make -j$(nproc) \ + && make install \ + \ +# add .postgis-rundeps + && apk add --no-cache --virtual .postgis-rundeps \ + \ + gdal~=${GDAL_ALPINE_VER} \ + geos~=${GEOS_ALPINE_VER} \ + proj~=${PROJ_ALPINE_VER} \ + \ + json-c \ + libstdc++ \ + pcre \ + protobuf-c \ + \ + ca-certificates \ +# clean + && cd / \ + && rm -rf /usr/src/postgis \ + && apk del .fetch-deps .build-deps + +ENV RUSTFLAGS="-C target-feature=-crt-static" +ARG PG_VER +RUN apk add --no-cache --virtual .zombodb-build-deps \ + git \ + curl \ + bash \ + ruby-dev \ + ruby-etc \ + musl-dev \ + make \ + gcc \ + coreutils \ + util-linux-dev \ + musl-dev \ + openssl-dev \ + clang15 \ + tar \ + && gem install --no-document fpm \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \ + && PATH=$HOME/.cargo/bin:$PATH \ + && cargo install cargo-pgrx --version 0.9.3 \ + && cargo pgrx init --${PG_VER}=$(which pg_config) \ + && git clone https://github.com/zombodb/zombodb.git \ + && cd ./zombodb \ + && cargo pgrx install --release \ + && cd .. \ + && rm -rf ./zombodb \ + && apk del .zombodb-build-deps + +## Adding pg_repack +ARG PG_REPACK_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .pg_repack-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + clang15 \ + gawk \ + llvm15 \ + gcc \ + musl-dev \ +# build pg_repack + && wget -O /tmp/pg_repack-${PG_REPACK_VERSION}.zip "https://api.pgxn.org/dist/pg_repack/${PG_REPACK_VERSION}/pg_repack-${PG_REPACK_VERSION}.zip" \ + && unzip /tmp/pg_repack-${PG_REPACK_VERSION}.zip -d /tmp \ + && cd /tmp/pg_repack-${PG_REPACK_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/pg_repack-${PG_REPACK_VERSION} /tmp/pg_repack.zip \ + && apk del .pg_repack-build-deps + +# Adding pgautofailover +ARG PG_AUTO_FAILOVER_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .pg_auto_failover-build-deps \ + make \ + gcc \ + musl-dev \ + krb5-dev \ + openssl-dev \ + clang15 \ + ncurses-dev \ + linux-headers \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + libedit-dev \ + libxml2-utils \ + libxslt-dev \ + llvm15 \ +# build pg_auto_failover + && wget -O /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip "https://github.com/hapostgres/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.zip" \ + && unzip /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip -d /tmp \ + && ls -alh /tmp \ + && cd /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION} /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION}.zip \ + && apk del .pg_auto_failover-build-deps + + +## Adding postgresql-hll +ARG POSTGRES_HLL_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .postgresql-hll-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + git \ + clang15 \ + gawk \ + llvm15 \ + g++ \ + musl-dev \ +# build postgresql-hll + && wget -O /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v${POSTGRES_HLL_VERSION}.zip" \ + && unzip /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip -d /tmp \ + && cd /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip \ + && apk del .postgresql-hll-build-deps + diff --git a/Makefile b/Makefile index 0e6d6029..181317ff 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,17 @@ NAME=postgres # Set ORG to timescale in the caller ORG=samagragovernance PG_VER=pg15 +CITUS_VERSION="11.2.0" +POSTGIS_VERSION=3.3.2 +PG_REPACK_VERSION = 1.4.8 +PG_AUTO_FAILOVER_VERSION = 2.0 +POSTGRES_HLL_VERSION = 2.17 +POSTGIS_SHA256=2a6858d1df06de1c5f85a5b780773e92f6ba3a5dc09ac31120ac895242f5a77b PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) TS_VERSION=main PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') -PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)" -PREV_IMAGE=$(shell if docker pull $(PREV_TS_IMAGE) >/dev/null; then echo "$(PREV_TS_IMAGE)"; else echo "postgres:$(PG_VER_NUMBER)-alpine"; fi ) +PREV_TS_IMAGE="samagragovernance/postgres:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)" +PREV_IMAGE=$(shell if docker pull "$(PREV_TS_IMAGE)" >/dev/null 2>&1; then echo "$(PREV_TS_IMAGE)"; else echo "timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)"; fi ) # Beta releases should not be tagged as latest, so BETA is used to track. BETA=$(findstring rc,$(TS_VERSION)) PLATFORM=linux/amd64,linux/arm64 @@ -19,6 +25,18 @@ TAG_LATEST=$(ORG)/$(NAME):latest-$(PG_VER) TAG=-t $(TAG_VERSION) $(if $(BETA),,-t $(TAG_LATEST)) TAG_OSS=-t $(TAG_VERSION)-oss $(if $(BETA),,-t $(TAG_LATEST)-oss) +DOCKER_BUILD_ARGS = --build-arg PG_VERSION=$(PG_VER_NUMBER) \ + --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PREV_IMAGE=$(PREV_IMAGE) \ + --build-arg CITUS_VERSION=$(CITUS_VERSION) \ + --build-arg PG_VER=$(PG_VER) \ + --build-arg PG_REPACK_VERSION=$(PG_REPACK_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) \ + --build-arg PG_AUTO_FAILOVER_VERSION=$(PG_AUTO_FAILOVER_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) \ + --build-arg POSTGIS_SHA256=$(POSTGIS_SHA256) \ + --build-arg POSTGRES_HLL_VERSION=$(POSTGRES_HLL_VERSION) + default: image .multi_$(TS_VERSION)_$(PG_VER)_oss: Dockerfile @@ -54,7 +72,12 @@ default: image touch .build_$(TS_VERSION)_$(PG_VER)_oss .build_$(TS_VERSION)_$(PG_VER): Dockerfile - docker build --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) . + docker build $(DOCKER_BUILD_ARGS) $(TAG) . + touch .build_$(TS_VERSION)_$(PG_VER) + +build-docker-cache: Dockerfile + docker buildx create --use --driver=docker-container + docker buildx build --progress=plain --load --cache-to "type=gha,mode=max" --cache-from type=gha $(DOCKER_BUILD_ARGS) $(TAG) . touch .build_$(TS_VERSION)_$(PG_VER) image: .build_$(TS_VERSION)_$(PG_VER) @@ -83,4 +106,4 @@ clean: rm -f *~ .build_* .multi_* -docker buildx rm multibuild -.PHONY: default image push push-oss oss multi multi-oss clean all +.PHONY: default image push push-oss oss multi multi-oss clean all build-docker-cache diff --git a/README.md b/README.md index 41678219..a0248259 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,192 @@ -## Test on GitPod -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ChakshuGautam/postgres-tsdb-vector-docker) +

+

WarpSQL

+Opinionated extensions to Postgres packaged as a single docker deployment. Why install 10 DBs when you can have everything at once (maybe not everything). + +Certified as Indie Hacker's best friend!!! -## Postgres +### Current and future supported extensions - [x] [PgVector](https://github.com/pgvector/pgvector) - [x] [TimescaleDB](https://github.com/timescale/timescaledb) -- [ ] [Citus](https://www.citusdata.com/) +- [x] [Citus](https://www.citusdata.com/) +- [x] [PostGIS](https://postgis.net) +- [x] [ZomboDB](https://github.com/zombodb/zombodb) +- [ ] [PLV8](https://github.com/plv8/plv8) +- [ ] [Pg Repack](https://github.com/reorg/pg_repack) Bootstrapped from [TimescaleDB](https://github.com/timescale/timescaledb-docker) + +### Usage with Compose + +```yaml +version: '3.6' +services: + warpsql: + container_name: warpsql + image: samagragovernance/postgres:latest-pg15 + restart: always + ports: + - "5432:5432" + volumes: + - ./pgdata:/var/lib/postgresql/data + environment: + POSTGRES_USER: warpSQLUser + POSTGRES_PASSWORD: warpSQLPass +``` + +WarpSQL is a powerful solution that provides opinionated extensions to Postgres, conveniently packaged as a single Docker deployment. It eliminates the need to install multiple separate databases by offering a comprehensive set of features in one place (although not everything, as some features might not be included). + +By utilizing WarpSQL, you can benefit from the following: + +- *Simplified setup*: With WarpSQL, you can have all the necessary extensions for your Postgres database in one go, saving you time and effort. +- *Seamless integration*: WarpSQL includes popular extensions like PgVector, TimescaleDB, Citus, and PostGIS, allowing you to leverage their functionality seamlessly. +- *Enhanced performance*: The included extensions are carefully selected to optimize database performance, enabling you to work efficiently with large datasets. +- *Extensibility*: While WarpSQL already supports a range of extensions, it aims to expand its offerings to include even more powerful tools in the future, such as ZomboDB, PLV8, and Pg Repack. +Get started with WarpSQL today and experience the convenience of a comprehensive Postgres solution. + +## PostgreSQL Image Packer Template + +This repository contains a Packer template for building the WarpSQL image with multiple sources and provisioners. The template supports building images based on both the Alpine and Bitnami PostgreSQL images. + +#### Prerequisites + +Before using this Packer template, ensure that you have the following prerequisites installed: + +- [Packer](https://www.packer.io/) +- [Docker](https://www.docker.com/) (for building Docker images) + +### Usage + +To build the WarpSQL image using the Packer template, follow these steps: + +1. Clone this repository and navigate to the packer directory: + + ```shell + git clone https://github.com/Samagra-Development/WarpSQL.git + cd WarpSQL/packer +2. Build the images: + ```shell + packer build warpsql.pkr.hcl + ``` +To build only the Alpine image, you can use the `-only` option: + + ```shell + packer build -only=warpsql.docker.alpine warpsql.pkr.hcl + ``` + By default, all supported [extensions](#list-of-supported-extensions) are installed. If you want to install specific extensions, you can provide the `extensions` variable: + ```shell + packer build -var extentions='pg_repack,hll' -only warpsql.docker.alpine warpsql.pkr.hcl + ``` + + Note that currently only the `Docker` source has been added to the template. + +You can further customize the image repository and tags by providing values for the `image_repository` and `image_tags` variables using the `-var` option. Here's an example command: +```shell +packer build -var="image_repository=your_value" -var="image_tags=[tag1,tag2]" warpsql.pkr.hcl +``` + +### List of supported extensions +|Extension | Identifier | +|----------------|------------------| +|[PgVector](https://github.com/pgvector/pgvector) | `pgvector` | +|[TimescaleDB](https://github.com/timescale/timescaledb) | `timescaledb` | +|[Citus](https://github.com/citusdata/citus) | `citus` | +|[PostGIS](https://github.com/postgis/postgis) | `postgis` | +|[ZomboDB](https://github.com/zombodb/zombodb) | `zombodb` | +|[PgRepack](https://github.com/reorg/pg_repack) | `pg_repack` | +|[PG Auto Failover](https://github.com/hapostgres/pg_auto_failover)| `pgautofailover` | +|[HyperLogLog](https://github.com/citusdata/postgresql-hll) | `hll` | +### AWS +WarpSQL provides a streamlined approach to deploying and managing PostgreSQL databases on AWS EC2 instances, complete with a disaster recovery solution powered by Barman. +> **Warning** +WarpSQL is a work in progress, and the current setup allows public SSH access to instances, which might not be secure. + + +To get started, ensure you have your AWS credentials set up and Docker,Terraform installed. + +First, create Docker images using the provided Dockerfiles in the `barman` and `warpsql_ssh` directories. Once built, push these images to a public image repository. +Specify the repository where you pushed these Docker images by passing the repository URL as a variable in the Terraform command. + +To launch WarpSQL with Barman, run: +```shell +git clone https://github.com/Samagra-Development/WarpSQL.git +cd WarpSQL/terraform/aws +terraform apply -var img_warpsql= -var img_barman= +``` + +You can also set the password for the Postgres instance by using the `warpsql_password` variable in the Terraform script the default value is `warpsql`. + +This will initiate the deployment of three EC2 instances that include an Ansible controller, PostgreSQL and Barman Docker containers.These instances are provisioned on an Ubuntu Host OS and are fully configured, requiring no further setup on your end. + +During any subsequent launches of the WarpSQL instance, the data is recovered from the latest backup stored by Barman. + +To specify the size of each instance's disk, provide the desired size in gigabytes to the respective variables: `warpsql_disk_size`, `ansible_disk_size`, and `barman_disk_size` in the terraform script. + + +The Barman images are based on [ubc/barman-docker](https://github.com/ubc/barman-docker). By default, Barman performs a base backup according to the cron schedule `0 4 * * *`. If you need to modify this schedule, refer to the environment variables documentation at https://github.com/ubc/barman-docker#environment-variables. + +## Contribution + +You can contribute to the development of WarpSQL using both Gitpod and Codespaces. Follow the steps below to set up your development environment and make contributions: + +### Gitpod + +Click the "Open in Gitpod" button above or use the following link:[Open in Gitpod](https://gitpod.io/new/#https://github.com/ChakshuGautam/postgres-tsdb-vector-docker) + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ChakshuGautam/postgres-tsdb-vector-docker) + +- Wait for the Gitpod environment to be created and initialized. +- Once the environment is ready, you can start working on the project. +- Make your desired changes or additions. +- Test your changes and ensure they meet the project's guidelines. +- Commit and push your changes to your forked repository. +- Create a pull request from your forked repository to the main WarpSQL repository. + +### GitHub Codespaces + +You can use GitHub Codespaces to develop this project in the cloud. + +[![GitHub Codespaces](https://img.shields.io/badge/GitHub-Codespaces-blue?logo=github)](https://github.com/features/codespaces) + +- Click on the "Code" button. +- Select "Open with Codespaces" from the dropdown menu. +- Choose the appropriate Codespace configuration. +- Wait for the environment to be provisioned. + +Once the environment is ready, you can start working on the project. + +- Make your desired changes or additions. +- Test your changes and ensure they meet the project's guidelines. +- Commit and push your changes to your forked repository. +- Create a pull request from your forked repository to the main WarpSQL repository. +- We welcome contributions from the community and appreciate your support in improving WarpSQL! + +### Ensure CI passes ![](https://img.shields.io/badge/CI-Passing-brightgreen) + +Before merging any contributions or changes, it's essential to ensure that the continuous integration (CI) tests pass successfully. CI helps maintain code quality standards and prevents the introduction of regressions. To ensure a smooth integration process, follow these steps: + +- Make your desired changes or additions to the codebase. +- Run the relevant tests locally to verify that your changes are functioning as expected. +- Push your changes to the branch you're working on. +- The CI system will automatically run tests and checks on your code. +- Monitor the CI build status to ensure that all tests pass successfully. +- If the CI build fails, review the error messages and make the necessary fixes. +- Repeat steps 3-6 until the CI build passes successfully. +- Once the CI build is successful, you can proceed with merging your changes into the main WarpSQL repository. + +## Maintainers + + + + + + + + + + +
Jayanth Kumar
Jayanth Kumar
💻
+ + + + diff --git a/barman/Dockerfile b/barman/Dockerfile new file mode 100644 index 00000000..8cb5700d --- /dev/null +++ b/barman/Dockerfile @@ -0,0 +1,16 @@ +FROM ubcctlt/barman + +RUN apt-get update && \ + apt-get install -y openssh-server && \ + apt-get clean +# Permit root login via SSH +RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config +RUN sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config + +# SSH port +EXPOSE 22 +COPY barman_entrypoint.sh /barman_entrypoint.sh +RUN chmod +x /barman_entrypoint.sh +RUN mkdir -p /run/sshd +ENTRYPOINT ["tini","--","/barman_entrypoint.sh"] +CMD ["cron", "-L", "4", "-f"] \ No newline at end of file diff --git a/barman/barman_entrypoint.sh b/barman/barman_entrypoint.sh new file mode 100644 index 00000000..373e34b2 --- /dev/null +++ b/barman/barman_entrypoint.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# copy ssh keys to root and barman users +set -ex +if [ -d "/tmp/ssh/" ]; then + cp -R /tmp/ssh/ /root/.ssh/ +chmod 700 /root/.ssh +chmod 644 /root/.ssh/id_rsa.pub +chmod 600 /root/.ssh/id_rsa +cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys +chmod 600 /root/.ssh/authorized_keys +cp -R /tmp/ssh/* ~barman/.ssh/ +ls -alh ~barman/.ssh/ +ls -alh /tmp/ssh/ +ls -alh /root/.ssh/ +chown barman:barman -R ~barman/.ssh/ + su - barman -c "chmod 700 ~barman/.ssh \ + && chmod 644 ~barman/.ssh/id_rsa.pub \ + && chmod 600 ~barman/.ssh/id_rsa \ + && cat ~barman/.ssh/id_rsa.pub >> ~barman/.ssh/authorized_keys \ + && chmod 600 ~barman/.ssh/authorized_keys" +/usr/sbin/sshd +fi +exec /entrypoint.sh "$@" \ No newline at end of file diff --git a/bitnami/Dockerfile b/bitnami/Dockerfile index 1042b37a..27b48d24 100644 --- a/bitnami/Dockerfile +++ b/bitnami/Dockerfile @@ -51,6 +51,7 @@ RUN set +o pipefail \ ARG PG_VERSION FROM bitnami/postgresql:${PG_VERSION} ARG PG_VERSION +ARG CITUS_VERSION LABEL maintainer="Timescale https://www.timescale.com" @@ -89,6 +90,22 @@ RUN set -ex \ && cd build && make install \ && cd ~ \ \ + # Install Citus + && apt-get update \ + && apt-get install -y curl liblz4-dev libzstd-dev clang libkrb5-dev libicu-dev libxslt1-dev libxml2-dev llvm-dev libcurl4-openssl-dev \ + && CITUS_DOWNLOAD_URL="https://github.com/citusdata/citus/archive/refs/tags/v${CITUS_VERSION}.tar.gz" \ + && curl -L -o /tmp/citus.tar.gz "${CITUS_DOWNLOAD_URL}" \ + && tar -C /tmp -xvf /tmp/citus.tar.gz \ + && addgroup --system postgres \ + && adduser --system --ingroup postgres --home /opt/bitnami/postgresql --no-create-home postgres \ + && chown -R postgres:postgres /tmp/citus-${CITUS_VERSION} \ + && cd /tmp/citus-${CITUS_VERSION} \ + && PATH="/opt/bitnami/postgresql/bin:$PATH" ./configure \ + && make \ + && make install \ + && cd ~ \ + && rm -rf /tmp/citus.tar.gz /tmp/citus-${CITUS_VERSION} \ + \ && apt-get autoremove --purge -y \ \ build-essential \ @@ -105,7 +122,209 @@ RUN set -ex \ "${HOME}/.cache" \ /var/lib/apt/lists/* \ /tmp/* \ - /var/tmp/* + /var/tmp/* + +# Add PG vector +RUN apt-get update \ + && cd /tmp \ + && apt-get install -y --no-install-recommends build-essential git \ + && git clone --branch v0.4.4 https://github.com/pgvector/pgvector.git /tmp/pgvector \ + && cd /tmp/pgvector \ + && make clean \ + && make OPTFLAGS="" \ + && make install \ + && rm -r /tmp/pgvector \ + && apt-get remove -y build-essential git \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* + +# Add PostGIS Extension +ARG POSTGIS_VERSION +ARG POSTGIS_SHA256 + +RUN set -eux \ + && apt update \ + && apt install -y \ + ca-certificates \ + openssl \ + tar \ + wget \ + gettext \ + automake \ + libltdl-dev \ + libxml2-dev \ + libgeos-dev \ + libproj-dev \ + libprotobuf-c-dev \ + protobuf-c-compiler \ + g++\ + gcc \ + make \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \ + && echo "${POSTGIS_SHA256} *postgis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ +# build PostGIS + \ + && cd /usr/src/postgis \ + && gettextize \ + && ./autogen.sh \ + && ./configure \ + --with-pcredir="$(pcre-config --prefix)" --with-geosconfig="/usr/bin/geos-config"\ + && make -j$(nproc) \ + && make install \ + && cd / \ +# clean + && apt-get autoremove --purge -y \ + wget \ + g++\ + gcc \ + make \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +# ADD pg_repack Extention +ARG PG_REPACK_VERSION + +RUN set -eux \ + && apt-get update \ + && apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libssl-dev \ + wget \ +# build pg_repack + && wget -O /tmp/pg_repack-${PG_REPACK_VERSION}.zip "https://api.pgxn.org/dist/pg_repack/${PG_REPACK_VERSION}/pg_repack-${PG_REPACK_VERSION}.zip" \ + && unzip /tmp/pg_repack-${PG_REPACK_VERSION}.zip -d /tmp \ + && cd /tmp/pg_repack-${PG_REPACK_VERSION} \ + && make \ + && make install \ +#clean + && apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libssl-dev \ + wget \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +# Adding pgautofailover +ARG PG_AUTO_FAILOVER_VERSION +RUN apt-get update \ + && apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libedit-dev \ + libssl-dev \ + wget \ +# build pg_auto_failover + && wget -O /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip "https://github.com/hapostgres/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.zip" \ + && unzip /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip -d /tmp \ + && ls -alh /tmp \ + && cd /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION} /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION}.zip \ + && apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libedit-dev \ + libssl-dev \ + wget \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +## Adding postgresql-hll +ARG POSTGRES_HLL_VERSION +RUN apt-get update \ + && apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libedit-dev \ + libssl-dev \ + wget \ +# build postgresql-hll + && wget -O /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v${POSTGRES_HLL_VERSION}.zip" \ + && unzip /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip -d /tmp \ + && cd /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip \ + && apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libedit-dev \ + libssl-dev \ + wget \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +# Install zombodb extension +ARG PG_MAJOR +RUN apt-get update -y -qq --fix-missing \ + && apt-get install -y wget gnupg \ + && echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list \ + && echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list \ + && wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ + && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 \ + && apt update \ + && apt-get update -y --fix-missing \ + && apt-get install -y git curl clang-14 llvm-14 gcc make build-essential libz-dev zlib1g-dev pkg-config libreadline-dev libgdbm-dev libssl1.0-dev \ + && wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz \ + && tar -xzvf openssl-1.0.2l.tar.gz \ + && cd openssl-1.0.2l \ + && ./config \ + && make install \ + && ln -sf /usr/local/ssl/bin/openssl `which openssl` \ + && mkdir ruby \ + && cd ruby \ + && wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz \ + && tar xvfz ruby-2.3.0.tar.gz \ + && cd ruby-2.3.0 \ + && ./configure --with-openssl-dir=/usr/include/openssl-1.0 \ + && make -j64 \ + && make install \ + && gem install --no-document fpm \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && export PATH="/.cargo/bin:$PATH" \ + && export PGRX_HOME="/.pgrx/" \ + && mkdir -p $PGRX_HOME \ + && cargo install cargo-pgrx --version 0.9.3 \ + && cargo pgrx init --pg${PG_MAJOR}=/opt/bitnami/postgresql/bin/pg_config \ + && git clone https://github.com/zombodb/zombodb.git \ + && cd zombodb \ + && export PATH="/.cargo/bin:$PATH" && cargo pgrx install --release \ + && cd / \ + && apt-get autoremove --purge -y git curl clang-14 gcc make build-essential wget \ + && rm -rf .cargo .gem openssl-1.0.2l .rustup openssl-1.0.2l.tar.gz USER 1001 diff --git a/bitnami/Makefile b/bitnami/Makefile index dc4d5b85..a3718a34 100644 --- a/bitnami/Makefile +++ b/bitnami/Makefile @@ -2,7 +2,15 @@ NAME=timescaledb # Default is to timescaledev to avoid unexpected push to the main repo # Set ORG to timescale in the caller ORG=timescaledev -PG_VER=pg12 +PG_VER=pg15 +CITUS_VERSION="11.2.0" +POSTGIS_MAJOR=3 +PG_MAJOR=15 +POSTGIS_VERSION=3.3.2 +POSTGIS_SHA256=2a6858d1df06de1c5f85a5b780773e92f6ba3a5dc09ac31120ac895242f5a77b +PG_REPACK_VERSION = 1.4.8 +PG_AUTO_FAILOVER_VERSION = 2.0 +POSTGRES_HLL_VERSION = 2.17 PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) TS_VERSION=main @@ -16,14 +24,30 @@ TAG_VERSION=$(ORG)/$(NAME):$(TS_VERSION)-$(PG_VER)-bitnami TAG_LATEST=$(ORG)/$(NAME):latest-$(PG_VER)-bitnami TAG=-t $(TAG_VERSION) $(if $(BETA),,-t $(TAG_LATEST)) +DOCKER_BUILD_ARGS = --build-arg PG_VERSION=$(PG_VER_NUMBER) \ + --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PREV_IMAGE=$(PREV_IMAGE) \ + --build-arg CITUS_VERSION=$(CITUS_VERSION) \ + --build-arg PG_REPACK_VERSION=$(PG_REPACK_VERSION) \ + --build-arg PG_AUTO_FAILOVER_VERSION=$(PG_AUTO_FAILOVER_VERSION) \ + --build-arg POSTGIS_MAJOR=$(POSTGIS_MAJOR) \ + --build-arg PG_MAJOR=$(PG_MAJOR) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) \ + --build-arg POSTGIS_SHA256=$(POSTGIS_SHA256) \ + --build-arg POSTGRES_HLL_VERSION=$(POSTGRES_HLL_VERSION) + default: image .build_$(TS_VERSION)_$(PG_VER): Dockerfile test -n "$(TS_VERSION)" # TS_VERSION test -n "$(PREV_TS_VERSION)" # PREV_TS_VERSION - docker build -f ./Dockerfile --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) .. + docker build -f ./Dockerfile $(DOCKER_BUILD_ARGS) $(TAG) .. touch .build_$(TS_VERSION)_$(PG_VER)-bitnami +build-docker-cache: Dockerfile + docker buildx create --use --driver=docker-container + docker buildx build -f ./Dockerfile --progress=plain --load --cache-to "type=gha,mode=max" --cache-from type=gha $(DOCKER_BUILD_ARGS) $(TAG) .. + touch .build_$(TS_VERSION)_$(PG_VER) image: .build_$(TS_VERSION)_$(PG_VER) push: image @@ -35,4 +59,4 @@ push: image clean: rm -f *~ .build_* -.PHONY: default image push clean +.PHONY: default image push clean build-docker-cache diff --git a/bitnami/timescaledb-bitnami-entrypoint.sh b/bitnami/timescaledb-bitnami-entrypoint.sh index 62b94610..c813e3b2 100755 --- a/bitnami/timescaledb-bitnami-entrypoint.sh +++ b/bitnami/timescaledb-bitnami-entrypoint.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -# We have to use the bitnami configuration variable to add timescaledb to -# shared preload list, or else it gets overwritten. +# We have to use the Bitnami configuration variable to add TimescaleDB, Citus to +# the shared preload list, or else it gets overwritten. if [ -z "$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" ] then - POSTGRESQL_SHARED_PRELOAD_LIBRARIES=timescaledb + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="citus,timescaledb,zombodb,pg_repack,pgautofailover,hll" else - POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb" + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="citus,timescaledb,zombodb,pg_repack,pgautofailover,hll,$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" fi export POSTGRESQL_SHARED_PRELOAD_LIBRARIES # Fall through to the original entrypoint. Note that we use exec here because # this wrapper script shouldn't change PID 1 of the container. -exec /opt/bitnami/scripts/postgresql/entrypoint.sh "$@" +exec /opt/bitnami/scripts/postgresql/entrypoint.sh "$@" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c249bd07..f11ce7cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.6' services: timescaledb: container_name: timescaledb - image: timescaledev/timescaledb:main-pg15 + image: samagragovernance/postgres:latest-pg15 restart: always ports: - "5432:5432" @@ -32,4 +32,14 @@ services: ## uncomment next line to set an admin secret # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey HASURA_GRAPHQL_MIGRATIONS_DISABLE_TRANSACTION: "true" - HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets \ No newline at end of file + HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets + + pgwatch2: + image: cybertec/pgwatch2-postgres:latest + ports: + - "3000:3000" + environment: + PW2_ADHOC_CONN_STR: "postgresql://timescaledb:postgrespassword@timescaledb:5432/postgres?sslmode=disable" + depends_on: + - "timescaledb" + restart: always diff --git a/icon.jpeg b/icon.jpeg new file mode 100644 index 00000000..2b0b72ef Binary files /dev/null and b/icon.jpeg differ diff --git a/image_size.js b/image_size.js new file mode 100644 index 00000000..0d4538f1 --- /dev/null +++ b/image_size.js @@ -0,0 +1,212 @@ +async function saveToFile(metrics, fs, path) { + const filePath = path; + const jsonData = JSON.stringify(metrics, null, 2); + + try { + await fs.promises.writeFile(filePath, jsonData); + console.log(`Metrics saved to ${filePath}`); + } catch (error) { + console.error(`Error saving metrics to ${filePath}: ${error}`); + } +} + +async function readFromFile(fs, path) { + const filePath = path; + try { + const jsonData = await fs.promises.readFile(filePath); + const metrics = JSON.parse(jsonData); + return metrics; + } catch (error) { + console.error(`Error reading metrics from ${filePath}: ${error}`); + return null; + } +} + +function parseSizeToBytes(value, unit) { + let bytes; + + switch (unit) { + case "KB": + bytes = value * 1024; + break; + case "MB": + bytes = value * 1024 * 1024; + break; + case "GB": + bytes = value * 1024 * 1024 * 1024; + break; + default: + throw new Error("Invalid size unit"); + } + + return bytes; +} + +function formatBytes(bytes, decimals = 2) { + if (bytes == null) return "Unknown"; + if (!+bytes) return "0 Bytes"; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = [ + "Bytes", + "KiB", + "MiB", + "GiB", + "TiB", + "PiB", + "EiB", + "ZiB", + "YiB", + ]; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; +} + +async function captureExecOutput( + exec, + command, + arguments, + ignoreExitCode = false +) { + let myOutput = ""; + let myError = ""; + + const options = {}; + options.listeners = { + stdout: (data) => { + myOutput += data.toString(); + }, + stderr: (data) => { + myError += data.toString(); + }, + }; + if (ignoreExitCode) { + options.ignoreReturnCode = true; + } + await exec.exec(command, arguments, options); + console.log(myOutput); + return myOutput; +} + +function calculatePercentageChange(currentValue, previousValue) { + if (!previousValue || previousValue === 0) { + return ""; + } + + const percentageChange = + ((currentValue - previousValue) / previousValue) * 100; + const colorIndicator = + percentageChange > 0 ? ":small_red_triangle:" : ":small_red_triangle_down:"; + console.log(percentageChange); + console.log(percentageChange.toFixed(2)); + const formattedChange = `[${percentageChange.toFixed( + 2 + )} % ${colorIndicator}]`; + return formattedChange; +} + +function createIssueComment( + imageType, + commitSHA, + imageSizeInBytes, + metricToCompare +) { + const currentSize = formatBytes(imageSizeInBytes); + const previousSize = formatBytes(metricToCompare?.imageSize || null); + const percentageChange = calculatePercentageChange( + imageSizeInBytes, + metricToCompare?.imageSize || null + ); + + const githubMessage = `### :bar_chart: ${imageType} Image Analysis (Commit: ${commitSHA} ) + #### Summary + + - **Current Size:** ${currentSize} ${percentageChange} + - **Previous Size :** ${previousSize}`; + + return githubMessage; +} + +async function getPullNumber(github, workflow_run, context, core) { + let head = `${workflow_run.actor.login}:${workflow_run.head_branch}`; + let prNumber = ( + await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: head, + }) + ).data[0]?.number; + if (prNumber != undefined) { + console.log(`Found PR number ${prNumber} based on base and head branches`); + core.exportVariable("pull_request_number", prNumber); + } else { + core.setFailed( + `Action failed: Pull-Request Number NOt found with head: ${head}` + ); + } + + console.log(prNumber); + return prNumber; +} + +module.exports = async ({ github, context, exec, core, fs }) => { + let commitSHA = context.payload.workflow_run.head_sha; + let imageSize = await captureExecOutput(exec, "docker", [ + "image", + "list", + "--format", + "{{.Size}}", + "smoketest-image", + ]); + let imageSizeInBytes = parseSizeToBytes( + imageSize.trim().slice(0, -2), + imageSize.trim().slice(-2) + ); + let imageLayers = await captureExecOutput(exec, "docker", [ + "image", + "history", + "-H", + "--format", + "table {{.CreatedBy}} \\t\\t {{.Size}}", + "smoketest-image", + ]); + const imageType = core.getInput("image-type", { required: true }); + + const workspace = core.getInput("workspace", { required: true }); + + if (context.payload.workflow_run.event == "pull_request") { + const metricToCompare = + (await readFromFile(fs, "image-metrics-" + imageType + ".json")) || {}; + + let githubMessage = createIssueComment( + imageType, + commitSHA, + imageSizeInBytes, + metricToCompare + ); + let issueNumber = await getPullNumber( + github, + context.payload.workflow_run, + context, + core + ); + const comment = { + body: githubMessage, + issue_number: issueNumber, + }; + const commentQueue = (await readFromFile(fs, "comments.json")) || []; + commentQueue.push(comment); + console.log(commentQueue); + await saveToFile(commentQueue, fs, "comments.json"); + } else if (context.payload.workflow_run.event == "push") { + const updatedMetric = { + imageId: imageType, + imageSize: imageSizeInBytes, + }; + console.log(updatedMetric); + await saveToFile(updatedMetric, fs, "image-metrics-" + imageType + ".json"); + } +}; diff --git a/index.html b/index.html new file mode 100644 index 00000000..025c6201 --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + WarpSQL + + + + + + + +
+ + + + + + + + + + + + + diff --git a/packer/postgres-alpine.sh b/packer/postgres-alpine.sh new file mode 100644 index 00000000..c37a7a43 --- /dev/null +++ b/packer/postgres-alpine.sh @@ -0,0 +1,361 @@ +#! /bin/bash + +set -ex + +check_env_variables() { + for var in "$@"; do + if [ -z "${!var}" ]; then + echo "Error: '$var' environment variable is not set." + exit 1 + fi + done +} + +install_timescaledb (){ + check_env_variables TS_VERSION + apk add libssl1.1 + apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + git \ + openssl \ + openssl-dev \ + tar + mkdir -p /build/ + git clone https://github.com/timescale/timescaledb /build/timescaledb + apk add --no-cache --virtual .build-deps \ + coreutils \ + dpkg-dev dpkg \ + gcc \ + krb5-dev \ + libc-dev \ + make \ + cmake \ + util-linux-dev \ + # Build current version \ + cd /build/timescaledb && rm -fr build + git checkout ${TS_VERSION} + ./bootstrap -DCMAKE_BUILD_TYPE=RelWithDebInfo -DREGRESS_CHECKS=OFF -DTAP_CHECKS=OFF -DGENERATE_DOWNGRADE_SCRIPT=ON -DWARNINGS_AS_ERRORS=OFF -DPROJECT_INSTALL_METHOD="docker"${OSS_ONLY} + cd build && make install + cd ~ + if [ "${OSS_ONLY}" != "" ]; then rm -f $(pg_config --pkglibdir)timescaledb-tsl-*.so; fi + apk del .fetch-deps .build-deps + rm -rf /build + sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample +} + + + +install_pgvector(){ +# Adding PG Vector + cd /tmp + apk add --no-cache --virtual .build-deps \ + coreutils \ + dpkg-dev dpkg \ + gcc \ + git \ + krb5-dev \ + libc-dev \ + llvm15 \ + make \ + cmake \ + clang15 \ + util-linux-dev + git clone --branch v0.4.1 https://github.com/pgvector/pgvector.git + cd pgvector + ls + make + make install +} + +install_citus(){ +## Adding Citus +check_env_variables CITUS_VERSION + apk add --no-cache --virtual .citus-deps \ + curl \ + jq \ + curl-dev + apk add --no-cache --virtual .citus-build-deps \ + gcc \ + libc-dev \ + make \ + lz4-dev \ + zstd-dev \ + clang15 \ + krb5-dev \ + icu-dev \ + libxslt-dev \ + libxml2-dev \ + llvm15-dev + export CITUS_DOWNLOAD_URL="https://github.com/citusdata/citus/archive/refs/tags/v${CITUS_VERSION}.tar.gz" + curl -L -o /tmp/citus.tar.gz "${CITUS_DOWNLOAD_URL}" + tar -C /tmp -xvf /tmp/citus.tar.gz + chown -R postgres:postgres /tmp/citus-${CITUS_VERSION} + cd /tmp/citus-${CITUS_VERSION} + PATH="/usr/local/pgsql/bin:$PATH" ./configure + make + make install + cd ~ + rm -rf /tmp/citus.tar.gz /tmp/citus-${CITUS_VERSION} + apk del .citus-build-deps + sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'citus,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample +} + +install_postgis(){ +# Adding Postgis +check_env_variables POSTGIS_VERSION POSTGIS_SHA256 +if [ $(printf %.1s "$POSTGIS_VERSION") == 3 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.11 ; \ + export GDAL_ALPINE_VER=3.6.4-r4 ; \ + export PROJ_ALPINE_VER=9.2 ; \ + elif [ $(printf %.1s "$POSTGIS_VERSION") == 2 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.8 ; \ + export GDAL_ALPINE_VER=3.2 ; \ + export PROJ_ALPINE_VER=7.2 ; \ + \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/community' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/community' >> /etc/apk/repositories ; \ + \ + else \ + set -eux ; \ + echo ".... unknown \$POSTGIS_VERSION ...." ; \ + exit 1 ; \ + fi + + apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + openssl \ + tar + + wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" + echo "${POSTGIS_SHA256} *postgis.tar.gz" | sha256sum -c - + mkdir -p /usr/src/postgis + tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 + rm postgis.tar.gz + + apk add --no-cache --virtual .build-deps \ + \ + gdal-dev~=${GDAL_ALPINE_VER} \ + geos-dev~=${GEOS_ALPINE_VER} \ + proj-dev~=${PROJ_ALPINE_VER} \ + \ + autoconf \ + automake \ + clang-dev \ + clang15 \ + cunit-dev \ + file \ + g++ \ + gcc \ + gettext-dev \ + git \ + json-c-dev \ + libtool \ + libxml2-dev \ + llvm-dev \ + llvm15 \ + make \ + pcre-dev \ + perl \ + protobuf-c-dev \ + +# build PostGIS + + cd /usr/src/postgis + gettextize + ./autogen.sh + ./configure \ + --with-pcredir="$(pcre-config --prefix)" + make -j$(nproc) + make install + +# add .postgis-rundeps + apk add --no-cache --virtual .postgis-rundeps \ + \ + gdal~=${GDAL_ALPINE_VER} \ + geos~=${GEOS_ALPINE_VER} \ + proj~=${PROJ_ALPINE_VER} \ + \ + json-c \ + libstdc++ \ + pcre \ + protobuf-c \ + \ + ca-certificates +# clean + cd / + rm -rf /usr/src/postgis + apk del .fetch-deps .build-deps + +} + +install_zombodb(){ +# adding zombodb +check_env_variables PG_VER +export RUSTFLAGS="-C target-feature=-crt-static" +apk add --no-cache --virtual .zombodb-build-deps \ + git \ + curl \ + bash \ + ruby-dev \ + ruby-etc \ + musl-dev \ + make \ + gcc \ + coreutils \ + util-linux-dev \ + musl-dev \ + openssl-dev \ + clang15 \ + tar + gem install --no-document fpm + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y + PATH=$HOME/.cargo/bin:$PATH + cargo install cargo-pgrx --version 0.9.3 + cargo pgrx init --${PG_VER}=$(which pg_config) + git clone https://github.com/zombodb/zombodb.git + cd ./zombodb + cargo pgrx install --release + cd .. + rm -rf ./zombodb + apk del .zombodb-build-deps + sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'zombodb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample + +} + +install_pgrepack(){ +## Adding pg_repack + check_env_variables PG_REPACK_VERSION + apk add --no-cache --virtual .pg_repack-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + clang15 \ + gawk \ + llvm15 \ + gcc \ + musl-dev +# build pg_repack + wget -O /tmp/pg_repack-${PG_REPACK_VERSION}.zip "https://api.pgxn.org/dist/pg_repack/${PG_REPACK_VERSION}/pg_repack-${PG_REPACK_VERSION}.zip" + unzip /tmp/pg_repack-${PG_REPACK_VERSION}.zip -d /tmp + cd /tmp/pg_repack-${PG_REPACK_VERSION} + make + make install +# clean + cd / + rm -rf /tmp/pg_repack-${PG_REPACK_VERSION} /tmp/pg_repack.zip + apk del .pg_repack-build-deps + +} +install_pgautofailover(){ +# Adding pgautofailover + check_env_variables PG_AUTO_FAILOVER_VERSION + apk add --no-cache --virtual .pg_auto_failover-build-deps \ + make \ + gcc \ + musl-dev \ + krb5-dev \ + openssl-dev \ + clang15 \ + ncurses-dev \ + linux-headers \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + libedit-dev \ + libxml2-utils \ + libxslt-dev \ + llvm15 +# build pg_auto_failover + wget -O /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip "https://github.com/hapostgres/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.zip" + unzip /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip -d /tmp + ls -alh /tmp + cd /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} + make + make install +# clean + cd / + rm -rf /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION} /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION}.zip + apk del .pg_auto_failover-build-deps + sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'pgautofailover,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample + +} +install_hll(){ +## Adding postgresql-hll +check_env_variables POSTGRES_HLL_VERSION + apk add --no-cache --virtual .postgresql-hll-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + git \ + clang15 \ + gawk \ + llvm15 \ + g++ \ + musl-dev +# build postgresql-hll + wget -O /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v${POSTGRES_HLL_VERSION}.zip" + unzip /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip -d /tmp + cd /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} + make + make install +# clean + cd / + rm -rf /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip + apk del .postgresql-hll-build-deps + +} + + +# enable contrib extentions +sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'pg_stat_statements,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample + + +# Retrieve and split the extension names +IFS=',' read -ra EXTENSION_LIST <<< "$EXTENSIONS" + +# Install each extension +for extension in "${EXTENSION_LIST[@]}"; do + case $extension in + timescaledb) + install_timescaledb + ;; + pgvector) + install_pgvector + ;; + citus) + install_citus + ;; + postgis) + install_postgis + ;; + zombodb) + install_zombodb + ;; + pg_repack) + install_pgrepack + ;; + pgautofailover) + install_pgautofailover + ;; + hll) + install_hll + ;; + *) + # Handle unrecognized extensions + echo "Unknown extension: $extension" + exit 1 + ;; + esac +done \ No newline at end of file diff --git a/packer/postgres-bitnami.sh b/packer/postgres-bitnami.sh new file mode 100644 index 00000000..ce52e598 --- /dev/null +++ b/packer/postgres-bitnami.sh @@ -0,0 +1,362 @@ +#! /bin/bash + +set -ex + +check_env_variables() { + for var in "$@"; do + if [ -z "${!var}" ]; then + echo "Error: '$var' environment variable is not set." + exit 1 + fi + done +} + +install_timescaledb (){ + check_env_variables TS_VERSION + apt-get update + apt-get -y install \ + build-essential \ + libssl-dev \ + git \ + \ + dpkg-dev \ + gcc \ + libc-dev \ + make \ + cmake \ + wget + mkdir -p /build/ + git clone https://github.com/timescale/timescaledb /build/timescaledb + # Build current version \ + cd /build/timescaledb && rm -fr build + git checkout ${TS_VERSION} + ./bootstrap -DCMAKE_BUILD_TYPE=RelWithDebInfo -DREGRESS_CHECKS=OFF -DTAP_CHECKS=OFF -DGENERATE_DOWNGRADE_SCRIPT=ON -DWARNINGS_AS_ERRORS=OFF -DPROJECT_INSTALL_METHOD="docker-bitnami" + cd build && make install + apt-get autoremove --purge -y \ + \ + build-essential \ + libssl-dev \ + \ + dpkg-dev \ + gcc \ + libc-dev \ + make \ + cmake + apt-get clean -y + rm -rf \ + /build \ + "${HOME}/.cache" \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + sed -r -i 's/[#]*\s*(POSTGRESQL_SHARED_PRELOAD_LIBRARIES)\s*=\s*"(.*)"/\1="timescaledb,\2"/;s/,"/"/' /opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh + +} + + + +install_pgvector(){ +# Adding PG Vector +check_env_variables PG_MAJOR + cd /tmp + apt-get update + apt-get install -y --no-install-recommends build-essential git + git clone --branch v0.4.4 https://github.com/pgvector/pgvector.git /tmp/pgvector + cd /tmp/pgvector + make clean + make OPTFLAGS="" + make install + rm -r /tmp/pgvector + apt-get remove -y build-essential git && \ + apt-get autoremove -y && \ + rm -rf /var/lib/apt/lists/* +} + +install_citus(){ +## Adding Citus +check_env_variables CITUS_VERSION + apt-get update + apt-get install -y curl liblz4-dev libzstd-dev clang libkrb5-dev libicu-dev libxslt1-dev libxml2-dev llvm-dev libcurl4-openssl-dev gawk flex gcc make libssh-dev + export CITUS_DOWNLOAD_URL="https://github.com/citusdata/citus/archive/refs/tags/v${CITUS_VERSION}.tar.gz" + curl -L -o /tmp/citus.tar.gz "${CITUS_DOWNLOAD_URL}" + tar -C /tmp -xvf /tmp/citus.tar.gz + addgroup --system postgres + adduser --system --ingroup postgres --home /opt/bitnami/postgresql --no-create-home postgres + chown -R postgres:postgres /tmp/citus-${CITUS_VERSION} + cd /tmp/citus-${CITUS_VERSION} + PATH="/opt/bitnami/postgresql/bin:$PATH" ./configure + make + make install + cd ~ + rm -rf /tmp/citus.tar.gz /tmp/citus-${CITUS_VERSION} + apt-get autoremove --purge -y \ + \ + build-essential \ + libssl-dev \ + \ + dpkg-dev \ + gcc \ + libc-dev \ + make \ + gawk \ + flex \ + make \ + libssh-dev \ + cmake + apt-get clean -y + rm -rf \ + /build \ + "${HOME}/.cache" \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + sed -r -i 's/[#]*\s*(POSTGRESQL_SHARED_PRELOAD_LIBRARIES)\s*=\s*"(.*)"/\1="citus,\2"/;s/,"/"/' /opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh + +} + +install_postgis(){ +# Adding Postgis +check_env_variables POSTGIS_VERSION POSTGIS_SHA256 + cd /tmp + apt update + apt install -y \ + ca-certificates \ + openssl \ + tar \ + wget \ + gettext \ + automake \ + libltdl-dev \ + libxml2-dev \ + libgeos-dev \ + libproj-dev \ + libprotobuf-c-dev \ + protobuf-c-compiler \ + g++\ + gcc \ + make + wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" + echo "${POSTGIS_SHA256} *postgis.tar.gz" | sha256sum -c - + mkdir -p /usr/src/postgis + tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 + rm postgis.tar.gz +# build PostGIS + cd /usr/src/postgis + gettextize + ./autogen.sh + ./configure \ + --with-pcredir="$(pcre-config --prefix)" --with-geosconfig="/usr/bin/geos-config" + make -j$(nproc) + make install + cd / +# clean + apt-get autoremove --purge -y \ + wget \ + g++\ + gcc \ + make + apt-get clean -y + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* +} + +install_zombodb(){ +# adding zombodb +check_env_variables PG_VER + cd /tmp + apt-get update -y -qq --fix-missing + apt-get install -y wget gnupg + echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list + echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list + wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 + apt update + apt-get update -y --fix-missing + apt-get install -y git curl clang-14 llvm-14 gcc make build-essential libz-dev zlib1g-dev pkg-config libreadline-dev libgdbm-dev libssl1.0-dev + wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz + tar -xzvf openssl-1.0.2l.tar.gz + cd openssl-1.0.2l + wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz + tar -xzvf openssl-1.0.2l.tar.gz + cd openssl-1.0.2l + ./config + make install + ln -sf /usr/local/ssl/bin/openssl `which openssl` + mkdir ruby + cd ruby + wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz + tar xvfz ruby-2.3.0.tar.gz + cd ruby-2.3.0 + ./configure --with-openssl-dir=/usr/include/openssl-1.0 + make -j64 + make install + gem install --no-document fpm + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + export PATH="/.cargo/bin:$PATH" + export PGRX_HOME="/.pgrx/" + mkdir -p $PGRX_HOME + cargo install cargo-pgrx --version 0.9.3 + cargo pgrx init --pg${PG_MAJOR}=/opt/bitnami/postgresql/bin/pg_config + git clone https://github.com/zombodb/zombodb.git + cd zombodb + export PATH="/.cargo/bin:$PATH" && cargo pgrx install --release + cd / + apt-get autoremove --purge -y git curl clang-14 gcc make build-essential wget + rm -rf .cargo .gem openssl-1.0.2l .rustup openssl-1.0.2l.tar.gz + sed -r -i 's/[#]*\s*(POSTGRESQL_SHARED_PRELOAD_LIBRARIES)\s*=\s*"(.*)"/\1="zombodb,\2"/;s/,"/"/' /opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh +} + +install_pgrepack(){ +## Adding pg_repack + check_env_variables PG_REPACK_VERSION + apt-get update + apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libssl-dev \ + wget +# build pg_repack + wget -O /tmp/pg_repack-${PG_REPACK_VERSION}.zip "https://api.pgxn.org/dist/pg_repack/${PG_REPACK_VERSION}/pg_repack-${PG_REPACK_VERSION}.zip" + unzip /tmp/pg_repack-${PG_REPACK_VERSION}.zip -d /tmp + cd /tmp/pg_repack-${PG_REPACK_VERSION} + make + make install +#clean + apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libssl-dev \ + wget + apt-get clean -y + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +} +install_pgautofailover(){ +# Adding pgautofailover + check_env_variables PG_AUTO_FAILOVER_VERSION + apt-get update + apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libedit-dev \ + libssl-dev \ + libxslt1-dev \ + libxml2-dev \ + wget +# build pg_auto_failover + wget -O /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip "https://github.com/hapostgres/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.zip" + unzip /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip -d /tmp + ls -alh /tmp + cd /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} + make + make install +# clean + cd / + rm -rf /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION} /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION}.zip + apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libedit-dev \ + libssl-dev \ + libxslt1-dev \ + libxml2-dev \ + wget + apt-get clean -y + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + sed -r -i 's/[#]*\s*(POSTGRESQL_SHARED_PRELOAD_LIBRARIES)\s*=\s*"(.*)"/\1="pgautofailover,\2"/;s/,"/"/' /opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh + +} + +install_hll(){ +## Adding postgresql-hll +check_env_variables POSTGRES_HLL_VERSION + apt-get update + apt-get install -y unzip \ + build-essential \ + liblz4-dev \ + zlib1g-dev \ + libedit-dev \ + libssl-dev \ + wget +# build postgresql-hll + wget -O /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v${POSTGRES_HLL_VERSION}.zip" + unzip /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip -d /tmp + cd /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} + make + make install +# clean + cd / + rm -rf /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip + apt-get autoremove --purge -y \ + unzip \ + build-essential \ + liblz4-dev \ + libedit-dev \ + libssl-dev \ + wget + apt-get clean -y + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +} + + +# enable contrib extentions +# sed -r -i 's/[#]*\s*(POSTGRESQL_SHARED_PRELOAD_LIBRARIES)\s*=\s*"(.*)"/\1="pg_stat_statements,\2"/;s/,"/"/' /opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh + + +# Retrieve and split the extension names +IFS=',' read -ra EXTENSION_LIST <<< "$EXTENSIONS" + +# Install each extension +for extension in "${EXTENSION_LIST[@]}"; do + case $extension in + timescaledb) + install_timescaledb + ;; + pgvector) + install_pgvector + ;; + citus) + install_citus + ;; + postgis) + install_postgis + ;; + zombodb) + install_zombodb + ;; + pg_repack) + install_pgrepack + ;; + pgautofailover) + install_pgautofailover + ;; + hll) + install_hll + ;; + *) + # Handle unrecognized extensions + echo "Unknown extension: $extension" + exit 1 + ;; + esac +done \ No newline at end of file diff --git a/packer/timescaledb-bitnami-entrypoint.sh b/packer/timescaledb-bitnami-entrypoint.sh new file mode 100755 index 00000000..46bf2259 --- /dev/null +++ b/packer/timescaledb-bitnami-entrypoint.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# We have to use the Bitnami configuration variable to add TimescaleDB, Citus to +# the shared preload list, or else it gets overwritten. +if [ -z "$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" ] +then + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="" +else + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" +fi +export POSTGRESQL_SHARED_PRELOAD_LIBRARIES + +# Fall through to the original entrypoint. Note that we use exec here because +# this wrapper script shouldn't change PID 1 of the container. +exec /opt/bitnami/scripts/postgresql/entrypoint.sh "$@" diff --git a/packer/warpsql.pkr.hcl b/packer/warpsql.pkr.hcl new file mode 100644 index 00000000..e58e2b01 --- /dev/null +++ b/packer/warpsql.pkr.hcl @@ -0,0 +1,104 @@ +# Packer configuration file for building a PostgreSQL image with multiple sources and provisioners +packer { + required_plugins { + docker = { + version = ">= 0.0.7" + source = "github.com/hashicorp/docker" + } + } +} +# # This variable defines the repository where the built image will be committed. +variable "image_repository" { + type = string + default = "warpsql" +} +# Tags to be applied to the built image +variable "image_tags" { + type = list(string) + default = ["latest"] + +} +variable "extentions" { + type = string + default = "timescaledb,pgvector,postgis,zombodb,pg_repack,pgautofailover,hll,citus" +} +source "docker" "alpine" { + image = "postgres:15-alpine" + commit = true + # Restore the parent image's ENTRYPOINT and CMD instructions + changes = [ + "ENTRYPOINT [\"docker-entrypoint.sh\"]", + "CMD [\"postgres\"]" + ] + run_command = ["-d", "-i", "-u=root", "-t", "--entrypoint=/bin/sh", "--", "{{.Image}}"] # running as the root user regardless of user instruction +} + +source "docker" "bitnami" { + image = "bitnami/postgresql:15" + commit = true + changes = [ + "USER 1001", + "ENTRYPOINT [ \"/opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh\" ]", + "CMD [ \"/opt/bitnami/scripts/postgresql/run.sh\" ]" + ] + run_command = ["-d", "-i", "-u=root", "-t", "--entrypoint=/bin/sh", "--", "{{.Image}}"] +} + +# Build configuration +build { + name = "warpsql" + # Specify the sources for the build + sources = [ + "source.docker.alpine", + "source.docker.bitnami" + ] + # provisioners for the Alpine image + provisioner "shell" { + environment_vars = [ + "EXTENSIONS=${var.extentions}", + "PG_VERSION=15", + "PG_VER=pg15", + "CITUS_VERSION=11.2.0", + "POSTGIS_VERSION=3.3.2", + "PG_REPACK_VERSION=1.4.8", + "PG_AUTO_FAILOVER_VERSION=2.0", + "POSTGRES_HLL_VERSION=2.17", + "POSTGIS_SHA256=2a6858d1df06de1c5f85a5b780773e92f6ba3a5dc09ac31120ac895242f5a77b", + "TS_VERSION=main" + ] + script = "postgres-alpine.sh" + only = ["docker.alpine"] + } + + # provisioners for the Bitnami image + provisioner "file" { + source = "timescaledb-bitnami-entrypoint.sh" + destination = "/opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh" + only = ["docker.bitnami"] + + } + + provisioner "shell" { + environment_vars = [ + "EXTENSIONS=${var.extentions}", + "PG_VERSION=15", + "PG_VER=pg15", + "CITUS_VERSION=11.2.0", + "POSTGIS_VERSION=3.3.2", + "PG_REPACK_VERSION=1.4.8", + "PG_MAJOR=15", + "PG_AUTO_FAILOVER_VERSION=2.0", + "POSTGRES_HLL_VERSION=2.17", + "POSTGIS_SHA256=2a6858d1df06de1c5f85a5b780773e92f6ba3a5dc09ac31120ac895242f5a77b", + "TS_VERSION=main" + ] + script = "postgres-bitnami.sh" + only = ["docker.bitnami"] + } + + post-processor "docker-tag" { + repository = var.image_repository + tags = var.image_tags + } + +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..824dabde --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +pgvector +timescaledb-tune +timescaledb-parallel-copy +libssl1.1 +libssl-dev +libkrb5-dev +libpq-dev +libc-dev +make +cmake +llvm15 +clang diff --git a/terraform/aws/config/barman/barman.conf b/terraform/aws/config/barman/barman.conf new file mode 100644 index 00000000..a1e76567 --- /dev/null +++ b/terraform/aws/config/barman/barman.conf @@ -0,0 +1,24 @@ +; Commented lines show the default values + +[barman] +; archiver = off +; backup_method = rsync +; backup_directory = %(barman_home)s/%(name)s + +; This must be set to the BARMAN_DATA_DIR environment variable +barman_home = /var/lib/barman + +; barman_lock_directory = %(barman_home)s +compression = gzip +configuration_files_direct +ory = /etc/barman/barman.d +;last_backup_maximum_age = 1 week +log_file = /var/lib/barman/barman.log +log_level = DEBUG +;minimum_redundancy = 1 +network_compression = true +retention_policy = RECOVERY WINDOW of 4 WEEKS +; retention_policy_mode = auto +reuse_backup = link +streaming_archiver = on +; wal_retention_policy = main \ No newline at end of file diff --git a/terraform/aws/config/barman/barman.d/pg.conf b/terraform/aws/config/barman/barman.d/pg.conf new file mode 100644 index 00000000..c81e1b20 --- /dev/null +++ b/terraform/aws/config/barman/barman.d/pg.conf @@ -0,0 +1,33 @@ +[pg] +; active = true +; archiver = off +; archiver_batch_size = 0 +; backup_directory = %(barman_home)s/%(name)s +backup_method = postgres +; backup_options = +; basebackup_retry_sleep = 30 +; basebackup_retry_times = 0 +; basebackups_directory = %(backup_directory)s/base +; check_timeout = 30 +conninfo = host=pg user=barman dbname=postgres +description = 'warpsql database' +; disabled = false +; errors_directory = %(backup_directory)s/errors +; immediate_checkpoint = false +; incoming_wals_directory = %(backup_directory)s/incoming +; minimum_redundancy = 0 +; network_compression = false +; path_prefix = /usr/lib/postgresql/9.5 +; recovery_options = +; retention_policy_mode = auto +; ssh_command = 'ssh -i /home/barman/.ssh/pg.id_rsa postgres@pg' +slot_name = barman +create_slot = auto +streaming_archiver = on +; streaming_archiver_batch_size = 0 +; streaming_archiver_name = barman_receive_wal +; streaming_backup_name = barman_streaming_backup +streaming_conninfo = host=pg user=streaming_barman dbname=postgres +; streaming_wals_directory = %(backup_directory)s/streaming +; wal_retention_policy = main +; wals_directory = %(backup_directory)s/wals' \ No newline at end of file diff --git a/terraform/aws/config/init/init.sh b/terraform/aws/config/init/init.sh new file mode 100644 index 00000000..38ec38e4 --- /dev/null +++ b/terraform/aws/config/init/init.sh @@ -0,0 +1,3 @@ +# !/bin/bash +set -e +echo "host replication all all scram-sha-256" >> /var/lib/postgresql/data/pg_hba.conf \ No newline at end of file diff --git a/terraform/aws/config/init/init.sql b/terraform/aws/config/init/init.sql new file mode 100644 index 00000000..a98e1ba7 --- /dev/null +++ b/terraform/aws/config/init/init.sql @@ -0,0 +1,2 @@ +CREATE USER barman WITH SUPERUSER PASSWORD 'barman'; +CREATE USER streaming_barman WITH REPLICATION PASSWORD 'streaming_barman'; \ No newline at end of file diff --git a/terraform/aws/main.tf b/terraform/aws/main.tf new file mode 100644 index 00000000..29a67c2f --- /dev/null +++ b/terraform/aws/main.tf @@ -0,0 +1,233 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.42.0" + } + } + required_version = ">= 0.14.5" +} + +provider "aws" { + region = var.region +} + +locals { + ami_id = "ami-053b0d53c279acc90" #ubuntu 22.04 LTS +} + +resource "aws_vpc" "vpc" { + cidr_block = var.cidr_vpc + enable_dns_support = true + enable_dns_hostnames = true +} + +resource "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.vpc.id +} + +resource "aws_subnet" "subnet_public" { + vpc_id = aws_vpc.vpc.id + cidr_block = var.cidr_subnet +} + +resource "aws_route_table" "rtb_public" { + vpc_id = aws_vpc.vpc.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } +} + +resource "aws_route_table_association" "rta_subnet_public" { + subnet_id = aws_subnet.subnet_public.id + route_table_id = aws_route_table.rtb_public.id +} + +resource "aws_security_group" "sg_22_80" { + name_prefix = "warpsql" + vpc_id = aws_vpc.vpc.id + # SSH access from the VPC + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + # postgres access + ingress { + from_port = 5432 + to_port = 5432 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + from_port = 7000 + to_port = 7000 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "tls_private_key" "warpsql-rsa" { + algorithm = "RSA" + rsa_bits = 4096 +} +resource "aws_key_pair" "deployer" { + key_name_prefix = "warpsql" + public_key = tls_private_key.warpsql-rsa.public_key_openssh +} +resource "local_sensitive_file" "pem_file" { + # write the private key to local for ssh access + filename = pathexpand("./${aws_key_pair.deployer.key_name}.pem") + file_permission = "600" + content = tls_private_key.warpsql-rsa.private_key_pem +} + +resource "aws_instance" "warpsql" { + ami = local.ami_id + instance_type = "t2.micro" + subnet_id = aws_subnet.subnet_public.id + vpc_security_group_ids = [aws_security_group.sg_22_80.id] + associate_public_ip_address = true + key_name = aws_key_pair.deployer.key_name + root_block_device { + volume_size = var.warpsql_disk_size + } + user_data = < '[3,1,2]' LIMIT 5;" \ No newline at end of file diff --git a/test/smoke_test/extentions_test/test_postgis.sh b/test/smoke_test/extentions_test/test_postgis.sh new file mode 100644 index 00000000..881a531a --- /dev/null +++ b/test/smoke_test/extentions_test/test_postgis.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ex + +echo "Test PostGIS Extension" +psql -c "CREATE EXTENSION postgis;" || true +psql -c "SELECT PostGIS_Version();" + +echo "Test PostGIS Geometry Function" +psql -c "CREATE TABLE test_geometry_table (id serial primary key, geom geometry(Point, 4326));" +psql -c "INSERT INTO test_geometry_table (geom) VALUES (ST_GeomFromText('POINT(0 0)', 4326));" +psql -c "SELECT * FROM test_geometry_table;" \ No newline at end of file diff --git a/test/smoke_test/extentions_test/test_timescaledb.sh b/test/smoke_test/extentions_test/test_timescaledb.sh new file mode 100644 index 00000000..3d3e0b5d --- /dev/null +++ b/test/smoke_test/extentions_test/test_timescaledb.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -ex + +psql < NOW() - interval '3 hours' + GROUP BY fifteen_min, location + ORDER BY fifteen_min DESC, max_temp DESC; +EOF \ No newline at end of file diff --git a/test/smoke_test/extentions_test/test_zombodb.sh b/test/smoke_test/extentions_test/test_zombodb.sh new file mode 100644 index 00000000..23e57bc0 --- /dev/null +++ b/test/smoke_test/extentions_test/test_zombodb.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -ex + +echo "Test zombodb Extension" +psql -c "CREATE EXTENSION zombodb;" +psql -c "SELECT zdb.internal_version();" + + + + \ No newline at end of file diff --git a/test/smoke_test/smoke_test.sh b/test/smoke_test/smoke_test.sh new file mode 100755 index 00000000..08f3cc71 --- /dev/null +++ b/test/smoke_test/smoke_test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +set -ex +# get the base dir of the script +scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")") +echo $scriptDir/extentions_test +# Find all test script files in the directory +test_scripts=$(find $scriptDir/extentions_test -type f -name 'test_*.sh') + +# If no extensions provided, run all test scripts +if [[ -z $1 ]]; then + for script in $test_scripts; do + bash "$script" + done +else +IFS=',' read -ra EXTENSION_LIST <<< "$1" + for extension in "${EXTENSION_LIST[@]}"; do + test_script="$scriptDir/extentions_test/test_${extension}.sh" + if [[ -f "$test_script" ]]; then + bash "$test_script" + else + echo "Test script for '$extension' not found." + fi + done +fi \ No newline at end of file diff --git a/warpsql_ssh/Dockerfile b/warpsql_ssh/Dockerfile new file mode 100644 index 00000000..14308b55 --- /dev/null +++ b/warpsql_ssh/Dockerfile @@ -0,0 +1,379 @@ +ARG PG_VERSION +ARG PREV_IMAGE +ARG TS_VERSION +############################ +# Build tools binaries in separate image +############################ +ARG GO_VERSION=1.18.7 +FROM golang:${GO_VERSION}-alpine AS tools + +ENV TOOLS_VERSION 0.8.1 + +RUN apk update && apk add --no-cache git gcc musl-dev \ + && go install github.com/timescale/timescaledb-tune/cmd/timescaledb-tune@latest \ + && go install github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy@latest + +############################ +# Grab old versions from previous version +############################ +ARG PG_VERSION +ARG PREV_IMAGE +FROM ${PREV_IMAGE} AS oldversions +# Remove update files, mock files, and all but the last 5 .so/.sql files +RUN rm -f $(pg_config --sharedir)/extension/timescaledb*mock*.sql \ + && if [ -f $(pg_config --pkglibdir)/timescaledb-tsl-1*.so ]; then rm -f $(ls -1 $(pg_config --pkglibdir)/timescaledb-tsl-1*.so | head -n -5); fi \ + && if [ -f $(pg_config --pkglibdir)/timescaledb-1*.so ]; then rm -f $(ls -1 $(pg_config --pkglibdir)/timescaledb-*.so | head -n -5); fi \ + && if [ -f $(pg_config --sharedir)/extension/timescaledb--1*.sql ]; then rm -f $(ls -1 $(pg_config --sharedir)/extension/timescaledb--1*.sql | head -n -5); fi + +############################ +# Now build image and copy in tools +############################ +ARG PG_VERSION +FROM postgres:${PG_VERSION}-alpine +ARG OSS_ONLY + +LABEL maintainer="Timescale https://www.timescale.com" + +COPY docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/ +COPY --from=tools /go/bin/* /usr/local/bin/ +COPY --from=oldversions /usr/local/lib/postgresql/timescaledb-*.so /usr/local/lib/postgresql/ +COPY --from=oldversions /usr/local/share/postgresql/extension/timescaledb--*.sql /usr/local/share/postgresql/extension/ + +ARG TS_VERSION +RUN set -ex \ + && apk add libssl1.1 \ + && apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + git \ + openssl \ + openssl-dev \ + tar \ + && mkdir -p /build/ \ + && git clone https://github.com/timescale/timescaledb /build/timescaledb \ + \ + && apk add --no-cache --virtual .build-deps \ + coreutils \ + dpkg-dev dpkg \ + gcc \ + krb5-dev \ + libc-dev \ + make \ + cmake \ + util-linux-dev \ + \ + # Build current version \ + && cd /build/timescaledb && rm -fr build \ + && git checkout ${TS_VERSION} \ + && ./bootstrap -DCMAKE_BUILD_TYPE=RelWithDebInfo -DREGRESS_CHECKS=OFF -DTAP_CHECKS=OFF -DGENERATE_DOWNGRADE_SCRIPT=ON -DWARNINGS_AS_ERRORS=OFF -DPROJECT_INSTALL_METHOD="docker"${OSS_ONLY} \ + && cd build && make install \ + && cd ~ \ + \ + && if [ "${OSS_ONLY}" != "" ]; then rm -f $(pg_config --pkglibdir)/timescaledb-tsl-*.so; fi \ + && apk del .fetch-deps .build-deps \ + && rm -rf /build \ + && sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample + +# Update to shared_preload_libraries +RUN echo "shared_preload_libraries = 'citus,timescaledb,pg_stat_statements,pgautofailover'" >> /usr/local/share/postgresql/postgresql.conf.sample + +# Adding PG Vector + +RUN cd /tmp +RUN apk add --no-cache --virtual .build-deps \ + coreutils \ + dpkg-dev dpkg \ + gcc \ + git \ + krb5-dev \ + libc-dev \ + llvm15 \ + make \ + cmake \ + clang15 \ + util-linux-dev \ + && git clone --branch v0.4.1 https://github.com/pgvector/pgvector.git \ + && cd /pgvector \ + && ls \ + && make \ + && make install + +## Adding Citus + +# Install Citus dependencies +RUN apk add --no-cache --virtual .citus-deps \ + curl \ + jq + +# Install Citus +ARG CITUS_VERSION +RUN set -ex \ + && apk add --no-cache --virtual .citus-build-deps \ + gcc \ + libc-dev \ + make \ + curl-dev \ + lz4-dev \ + zstd-dev \ + clang \ + krb5-dev \ + icu-dev \ + libxslt-dev \ + libxml2-dev \ + llvm15-dev \ + && CITUS_DOWNLOAD_URL="https://github.com/citusdata/citus/archive/refs/tags/v${CITUS_VERSION}.tar.gz" \ + && curl -L -o /tmp/citus.tar.gz "${CITUS_DOWNLOAD_URL}" \ + && tar -C /tmp -xvf /tmp/citus.tar.gz \ + && chown -R postgres:postgres /tmp/citus-${CITUS_VERSION} \ + && cd /tmp/citus-${CITUS_VERSION} \ + && PATH="/usr/local/pgsql/bin:$PATH" ./configure \ + && make \ + && make install \ + && cd ~ \ + && rm -rf /tmp/citus.tar.gz /tmp/citus-${CITUS_VERSION} \ + && apk del .citus-deps .citus-build-deps + + +ARG POSTGIS_VERSION +ARG POSTGIS_SHA256 + +RUN set -eux \ + \ + && if [ $(printf %.1s "$POSTGIS_VERSION") == 3 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.11 ; \ + export GDAL_ALPINE_VER=3.6.4-r4 ; \ + export PROJ_ALPINE_VER=9.2 ; \ + elif [ $(printf %.1s "$POSTGIS_VERSION") == 2 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.8 ; \ + export GDAL_ALPINE_VER=3.2 ; \ + export PROJ_ALPINE_VER=7.2 ; \ + \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/community' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/community' >> /etc/apk/repositories ; \ + \ + else \ + set -eux ; \ + echo ".... unknown \$POSTGIS_VERSION ...." ; \ + exit 1 ; \ + fi \ + \ + && apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + openssl \ + tar \ + \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \ + && echo "${POSTGIS_SHA256} *postgis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ + && apk add --no-cache --virtual .build-deps \ + \ + gdal-dev~=${GDAL_ALPINE_VER} \ + geos-dev~=${GEOS_ALPINE_VER} \ + proj-dev~=${PROJ_ALPINE_VER} \ + \ + autoconf \ + automake \ + clang-dev \ + clang15 \ + cunit-dev \ + file \ + g++ \ + gcc \ + gettext-dev \ + git \ + json-c-dev \ + libtool \ + libxml2-dev \ + llvm-dev \ + llvm15 \ + make \ + pcre-dev \ + perl \ + protobuf-c-dev \ + \ +# build PostGIS + \ + && cd /usr/src/postgis \ + && gettextize \ + && ./autogen.sh \ + && ./configure \ + --with-pcredir="$(pcre-config --prefix)" \ + && make -j$(nproc) \ + && make install \ + \ +# add .postgis-rundeps + && apk add --no-cache --virtual .postgis-rundeps \ + \ + gdal~=${GDAL_ALPINE_VER} \ + geos~=${GEOS_ALPINE_VER} \ + proj~=${PROJ_ALPINE_VER} \ + \ + json-c \ + libstdc++ \ + pcre \ + protobuf-c \ + \ + ca-certificates \ +# clean + && cd / \ + && rm -rf /usr/src/postgis \ + && apk del .fetch-deps .build-deps + +ENV RUSTFLAGS="-C target-feature=-crt-static" +ARG PG_VER +RUN apk add --no-cache --virtual .zombodb-build-deps \ + git \ + curl \ + bash \ + ruby-dev \ + ruby-etc \ + musl-dev \ + make \ + gcc \ + coreutils \ + util-linux-dev \ + musl-dev \ + openssl-dev \ + clang15 \ + tar \ + && gem install --no-document fpm \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \ + && PATH=$HOME/.cargo/bin:$PATH \ + && cargo install cargo-pgrx --version 0.9.3 \ + && cargo pgrx init --${PG_VER}=$(which pg_config) \ + && git clone https://github.com/zombodb/zombodb.git \ + && cd ./zombodb \ + && cargo pgrx install --release \ + && cd .. \ + && rm -rf ./zombodb \ + && apk del .zombodb-build-deps + +## Adding pg_repack +ARG PG_REPACK_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .pg_repack-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + clang15 \ + gawk \ + llvm15 \ + gcc \ + musl-dev \ +# build pg_repack + && wget -O /tmp/pg_repack-${PG_REPACK_VERSION}.zip "https://api.pgxn.org/dist/pg_repack/${PG_REPACK_VERSION}/pg_repack-${PG_REPACK_VERSION}.zip" \ + && unzip /tmp/pg_repack-${PG_REPACK_VERSION}.zip -d /tmp \ + && cd /tmp/pg_repack-${PG_REPACK_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/pg_repack-${PG_REPACK_VERSION} /tmp/pg_repack.zip \ + && apk del .pg_repack-build-deps + +# Adding pgautofailover +ARG PG_AUTO_FAILOVER_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .pg_auto_failover-build-deps \ + make \ + gcc \ + musl-dev \ + krb5-dev \ + openssl-dev \ + clang15 \ + ncurses-dev \ + linux-headers \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + libedit-dev \ + libxml2-utils \ + libxslt-dev \ + llvm15 \ +# build pg_auto_failover + && wget -O /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip "https://github.com/hapostgres/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.zip" \ + && unzip /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION}.zip -d /tmp \ + && ls -alh /tmp \ + && cd /tmp/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION} /tmp/pg_auto_failove-${PG_AUTO_FAILOVER_VERSION}.zip \ + && apk del .pg_auto_failover-build-deps + + +## Adding postgresql-hll +ARG POSTGRES_HLL_VERSION +RUN set -eux \ + && apk add --no-cache --virtual .postgresql-hll-build-deps \ + openssl-dev \ + zstd-dev \ + lz4-dev \ + zlib-dev \ + make \ + git \ + clang15 \ + gawk \ + llvm15 \ + g++ \ + musl-dev \ +# build postgresql-hll + && wget -O /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v${POSTGRES_HLL_VERSION}.zip" \ + && unzip /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip -d /tmp \ + && cd /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} \ + && make \ + && make install \ +# clean + && cd / \ + && rm -rf /tmp/postgresql-hll-${POSTGRES_HLL_VERSION} /tmp/postgresql-hll-${POSTGRES_HLL_VERSION}.zip \ + && apk del .postgresql-hll-build-deps + + +# install barman client +RUN apk add --no-cache \ + gcc \ + python3 \ + rsync \ + py3-pip \ + python3-dev \ + git \ + openssh \ + musl-dev \ + && cd /tmp \ + && git clone https://github.com/EnterpriseDB/barman \ + && cd barman \ + && ./setup.py install \ + && ./setup.py build \ + cd / \ + && rm -rf /tmp/barman + +# Install SSH server +RUN apk add --no-cache openssh-server + + +# Permit root login via SSH +RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config + +# Unloack the postgres account for ssh +RUN passwd -u postgres + +# SSH port +EXPOSE 22 + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT [ "/entrypoint.sh" ] +CMD ["postgres"] diff --git a/warpsql_ssh/Makefile b/warpsql_ssh/Makefile new file mode 100644 index 00000000..181317ff --- /dev/null +++ b/warpsql_ssh/Makefile @@ -0,0 +1,109 @@ +NAME=postgres +# Default is to timescaledev to avoid unexpected push to the main repo +# Set ORG to timescale in the caller +ORG=samagragovernance +PG_VER=pg15 +CITUS_VERSION="11.2.0" +POSTGIS_VERSION=3.3.2 +PG_REPACK_VERSION = 1.4.8 +PG_AUTO_FAILOVER_VERSION = 2.0 +POSTGRES_HLL_VERSION = 2.17 +POSTGIS_SHA256=2a6858d1df06de1c5f85a5b780773e92f6ba3a5dc09ac31120ac895242f5a77b +PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) +TS_VERSION=main +PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') +PREV_TS_IMAGE="samagragovernance/postgres:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)" +PREV_IMAGE=$(shell if docker pull "$(PREV_TS_IMAGE)" >/dev/null 2>&1; then echo "$(PREV_TS_IMAGE)"; else echo "timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)"; fi ) +# Beta releases should not be tagged as latest, so BETA is used to track. +BETA=$(findstring rc,$(TS_VERSION)) +PLATFORM=linux/amd64,linux/arm64 + +# PUSH_MULTI can be set to nothing for dry-run without pushing during multi-arch build +PUSH_MULTI=--push +TAG_VERSION=$(ORG)/$(NAME):$(TS_VERSION)-$(PG_VER) +TAG_LATEST=$(ORG)/$(NAME):latest-$(PG_VER) +TAG=-t $(TAG_VERSION) $(if $(BETA),,-t $(TAG_LATEST)) +TAG_OSS=-t $(TAG_VERSION)-oss $(if $(BETA),,-t $(TAG_LATEST)-oss) + +DOCKER_BUILD_ARGS = --build-arg PG_VERSION=$(PG_VER_NUMBER) \ + --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PREV_IMAGE=$(PREV_IMAGE) \ + --build-arg CITUS_VERSION=$(CITUS_VERSION) \ + --build-arg PG_VER=$(PG_VER) \ + --build-arg PG_REPACK_VERSION=$(PG_REPACK_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) \ + --build-arg PG_AUTO_FAILOVER_VERSION=$(PG_AUTO_FAILOVER_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) \ + --build-arg POSTGIS_SHA256=$(POSTGIS_SHA256) \ + --build-arg POSTGRES_HLL_VERSION=$(POSTGRES_HLL_VERSION) + +default: image + +.multi_$(TS_VERSION)_$(PG_VER)_oss: Dockerfile + test -n "$(TS_VERSION)" # TS_VERSION + test -n "$(PREV_TS_VERSION)" # PREV_TS_VERSION + docker buildx create --platform $(PLATFORM) --name multibuild --use + docker buildx inspect multibuild --bootstrap + docker buildx build --platform $(PLATFORM) \ + --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PG_VERSION=$(PG_VER_NUMBER) \ + --build-arg PREV_IMAGE=$(PREV_IMAGE) \ + --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" \ + $(TAG_OSS) $(PUSH_MULTI) . + touch .multi_$(TS_VERSION)_$(PG_VER)_oss + docker buildx rm multibuild + +.multi_$(TS_VERSION)_$(PG_VER): Dockerfile + test -n "$(TS_VERSION)" # TS_VERSION + test -n "$(PREV_TS_VERSION)" # PREV_TS_VERSION + test -n "$(PREV_IMAGE)" # PREV_IMAGE + docker buildx create --platform $(PLATFORM) --name multibuild --use + docker buildx inspect multibuild --bootstrap + docker buildx build --platform $(PLATFORM) \ + --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PREV_IMAGE=$(PREV_IMAGE) \ + --build-arg PG_VERSION=$(PG_VER_NUMBER) \ + $(TAG) $(PUSH_MULTI) . + touch .multi_$(TS_VERSION)_$(PG_VER) + docker buildx rm multibuild + +.build_$(TS_VERSION)_$(PG_VER)_oss: Dockerfile + docker build --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" --build-arg PG_VERSION=$(PG_VER_NUMBER) $(TAG_OSS) . + touch .build_$(TS_VERSION)_$(PG_VER)_oss + +.build_$(TS_VERSION)_$(PG_VER): Dockerfile + docker build $(DOCKER_BUILD_ARGS) $(TAG) . + touch .build_$(TS_VERSION)_$(PG_VER) + +build-docker-cache: Dockerfile + docker buildx create --use --driver=docker-container + docker buildx build --progress=plain --load --cache-to "type=gha,mode=max" --cache-from type=gha $(DOCKER_BUILD_ARGS) $(TAG) . + touch .build_$(TS_VERSION)_$(PG_VER) + +image: .build_$(TS_VERSION)_$(PG_VER) + +oss: .build_$(TS_VERSION)_$(PG_VER)_oss + +push: image + docker push $(TAG_VERSION) + if [ -z "$(BETA)" ]; then \ + docker push $(TAG_LATEST); \ + fi + +push-oss: oss + docker push $(TAG_VERSION)-oss + if [ -z "$(BETA)" ]; then \ + docker push $(TAG_LATEST)-oss; \ + fi + +multi: .multi_$(TS_VERSION)_$(PG_VER) + +multi-oss: .multi_$(TS_VERSION)_$(PG_VER)_oss + +all: multi multi-oss + +clean: + rm -f *~ .build_* .multi_* + -docker buildx rm multibuild + +.PHONY: default image push push-oss oss multi multi-oss clean all build-docker-cache diff --git a/warpsql_ssh/entrypoint.sh b/warpsql_ssh/entrypoint.sh new file mode 100644 index 00000000..c098836f --- /dev/null +++ b/warpsql_ssh/entrypoint.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# copy ssh keys to root and postgres users +set -e +if [ -d "/tmp/ssh/" ]; then + cp -R /tmp/ssh/ /root/.ssh/ + chmod 700 /root/.ssh + chmod 644 /root/.ssh/id_rsa.pub + chmod 600 /root/.ssh/id_rsa + cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys + chmod 600 /root/.ssh/authorized_keys + cp -R /tmp/ssh/ ~postgres/.ssh/ + echo -e > ~postgres/.ssh/config "Host *\n\tStrictHostKeyChecking no" # prevent barman commands failing when using ssh + chown postgres:postgres -R ~postgres/.ssh/ + su - postgres -c "chmod 700 ~postgres/.ssh \ + && chmod 644 ~postgres/.ssh/id_rsa.pub \ + && chmod 600 ~postgres/.ssh/id_rsa \ + && chmod 600 ~postgres/.ssh/config \ + && cat ~postgres/.ssh/id_rsa.pub >> ~postgres/.ssh/authorized_keys \ + && chmod 600 ~postgres/.ssh/authorized_keys" +/usr/sbin/sshd #start the ssh server +fi + +exec /usr/local/bin/docker-entrypoint.sh "$@" \ No newline at end of file