From a98ef79d9eca231bc8ac036b1269dd844201196b Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Tue, 23 Apr 2024 16:06:47 -0500 Subject: [PATCH] feat: Initial commit --- .dockerignore | 1 + .github/CODEOWNERS | 1 + .github/workflows/build.yaml | 91 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 + Dockerfile | 32 +++++++++++++ README.md | 29 ++++++++++++ renovate.json | 28 +++++++++++ 7 files changed, 184 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/build.yaml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 renovate.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1d085ca --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +** diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1a1a071 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @clevyr/devops diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..aa51a16 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,91 @@ +name: Build + +on: push + +env: + # renovate datasource=github-releases depName=timescale/timescaledb + TIMESCALEDB_VERSION: 2.14.2 + +jobs: + build: + name: Build Image (pg${{ matrix.postgres_version }}) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - postgres_version: "16" + # renovate datasource=docker depName=ghcr.io/cloudnative-pg/postgresql + cnpg_version: 16.2-7 + latest: "true" + - postgres_version: "15" + # renovate datasource=docker depName=ghcr.io/cloudnative-pg/postgresql + cnpg_version: 15.6-6 + - postgres_version: "14" + # renovate datasource=docker depName=ghcr.io/cloudnative-pg/postgresql + cnpg_version: 14.11-6 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Get CloudNativePG version + id: cnpg + env: + VERSION: ${{ matrix.cnpg_version }} + run: | + { + echo "version=$VERSION" + echo "minor=$(cut -d- -f1 <<<"$VERSION")" + echo "major=$(cut -d. -f1 <<<"$VERSION")" + } >> $GITHUB_OUTPUT + - name: Get Timescale version + id: timescale + env: + VERSION: ${{ env.TIMESCALE_VERSION }} + run: | + { + echo "version=$VERSION" + echo "minor=$(cut -d. -f-2 <<<"$VERSION")" + echo "major=$(cut -d. -f1 <<<"$VERSION")" + } >> $GITHUB_OUTPUT + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/cloudnativepg-timescale + flavor: latest=false + tags: | + type=raw,priority=1000,value=latest,enable=${{ matrix.latest || 'false' }} + type=raw,priority=999,value=${{ steps.cnpg.outputs.version }}-ts{{ steps.timescale.outputs.version }} + type=raw,priority=998,value=${{ steps.cnpg.outputs.minor }}-ts${{ steps.timescale.outputs.minor }} + type=raw,priority=997,value=${{ steps.cnpg.outputs.major }}-ts${{ steps.timescale.outputs.major }} + type=raw,priority=996,value=${{ steps.cnpg.outputs.version }} + type=raw,priority=995,value=${{ steps.cnpg.outputs.minor }} + type=raw,priority=994,value=${{ steps.cnpg.outputs.major }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Build and Push + uses: docker/build-push-action@v5 + with: + context: . + pull: true + push: ${{ github.ref_name == 'main' }} + platforms: linux/amd64,linux/arm64/v8 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + POSTGRES_VERSION=${{ matrix.postgres_version }} + CLOUDNATIVEPG_VERSION=${{ steps.cnpg.outputs.version }} + TIMESCALE_VERSION=${{ steps.timescale.outputs.version }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af56f61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ad89847 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +#syntax=docker/dockerfile:1.7 + +ARG CLOUDNATIVEPG_VERSION + +FROM ghcr.io/cloudnative-pg/postgresql:$CLOUDNATIVEPG_VERSION +USER root + +ARG POSTGRES_VERSION +ARG TIMESCALE_VERSION +RUN </dev/null + echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $VERSION_CODENAME main" >/etc/apt/sources.list.d/timescaledb.list + curl -Lsf https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor >/etc/apt/trusted.gpg.d/timescale.gpg + + # Install Timescale + apt-get update + apt-get install -y --no-install-recommends "timescaledb-2-postgresql-$POSTGRES_VERSION=$TIMESCALE_VERSION~debian$VERSION_ID" + + # Cleanup + apt-get purge -y curl + rm /etc/apt/sources.list.d/timescaledb.list /etc/apt/trusted.gpg.d/timescale.gpg + rm -rf /var/cache/apt/* +EOT + +USER 26 diff --git a/README.md b/README.md new file mode 100644 index 0000000..f494c2b --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# CloudNativePG Containers with TimescaleDB + +[![Build](https://github.com/clevyr/docker-cloudnativepg-timescale/actions/workflows/build.yaml/badge.svg)](https://github.com/clevyr/docker-cloudnativepg-timescale/actions/workflows/build.yaml) + +This repo builds Docker images for [CloudNativePG](https://cloudnative-pg.io/) with the [TimescaleDB](https://timescale.com) extension installed. + +Both versions are automatically updated by Renovate bot, so new releases will be available within a few hours. + +## Images + +Images are available at [`ghcr.io/clevyr/cloudnativepg-timescale`](https://github.com/clevyr/docker-cloudnativepg-timescale/pkgs/container/cloudnativepg-timescale). There are tags available for Postgres v14, v15, and v16. + +## Deployment + +Set `.spec.imageName` in the `Cluster` to use one of the container images provided by this repository. + +For example: +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: example +spec: + instances: 3 + imageName: ghcr.io/clevyr/cloudnativepg-timescale:16-ts2 + postgresql: + shared_preload_libraries: + - timescaledb +``` diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..ed88d01 --- /dev/null +++ b/renovate.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>gabe565/renovate-config", + ":automergeAll" + ], + "regexManagers": [ + { + "fileMatch": ["\\.ya?ml$"], + "matchStrings": [ + "# ?renovate datasource=(?.+?) depName=(?.+)\\n.+: [\"']?(?.+?)[\"']?\\n" + ] + }, + { + "fileMatch": ["README.md"], + "matchStrings": [ + "\\n.*\\/Version-(?.+?)-" + ] + } + ], + "packageRules": [ + { + "matchDepNames": ["ghcr.io/cloudnative-pg/postgresql"], + "matchUpdateTypes": ["major"], + "enabled": false + } + ] +}