Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
af11b18
[UPD] pre-commit
Tardo Jun 22, 2022
c0d552c
[UPD] add pg14
Tardo Jun 22, 2022
dda8b4b
Merge pull request #11 from Tecnativa/add-pg14-latests
Tardo Jun 22, 2022
60ee4ce
[FIX] tests
Tardo Jun 22, 2022
bb6d234
[IMP] latest release
Tardo Jun 23, 2022
09942e8
[ADD] ci: pg15
Tardo Feb 14, 2023
8179fde
Merge pull request #13 from Tardo/add-pg15
pedrobaeza Feb 14, 2023
7839943
[DCK] pre-commit dependencies updated
josep-tecnativa Sep 26, 2023
1b95106
[ADD] pg16
josep-tecnativa Oct 7, 2024
57ea0f2
Merge pull request #19 from Tecnativa/add-postgres-16
josep-tecnativa Oct 7, 2024
4eec7d8
Revert "Add postgres 16"
josep-tecnativa Oct 7, 2024
baeaa65
Merge pull request #20 from Tecnativa/revert-19-add-postgres-16
josep-tecnativa Oct 7, 2024
8e7eef9
[FIX] apk add command
josep-tecnativa Oct 7, 2024
c926d1a
[ADD] Postgres 16
josep-tecnativa Oct 7, 2024
11e7071
Merge pull request #21 from Tecnativa/add-pg-16
josep-tecnativa Oct 7, 2024
41e5558
[ADD] HBA_EXTRA_RULES support to allow custom pg_hba.conf rules
josep-tecnativa Nov 28, 2024
80ddfb7
[ADD] Tests to check if new feature works
josep-tecnativa Nov 28, 2024
eba6aff
[IMP] Add pushing PR images to be able to test it correctly
josep-tecnativa Nov 29, 2024
6db61e4
Merge pull request #22 from Tecnativa/add-hba-extra-rules
josep-tecnativa Nov 29, 2024
bc6b537
[IMP] Reorder rules to certaintly apply extra hba rules
josep-tecnativa Dec 9, 2024
e665865
Merge pull request #24 from Tecnativa/reorder-rules
josep-tecnativa Dec 9, 2024
f8a0902
[ADD] Psql 17
josep-tecnativa Sep 15, 2025
f59618b
[FIX] Modernize CI
josep-tecnativa Sep 15, 2025
e21fcfe
Merge pull request #25 from Tecnativa/add-pg-17
josep-tecnativa Sep 15, 2025
95614e5
[ADD] Add pgvector library
josep-tecnativa Sep 26, 2025
4b63f77
Merge pull request #26 from Tecnativa/add-pgvector-extension
josep-tecnativa Sep 29, 2025
aa1a78c
[FIX] Skip push on fork PRs
josep-tecnativa Nov 7, 2025
3a2087b
Merge pull request #28 from Tecnativa/fix-ci-prs-from-forks
josep-tecnativa Nov 7, 2025
5d27541
[FIX] pgvector files: copy extension files to /local/ folder
JordiMForgeFlow Oct 27, 2025
87635ad
Merge pull request #27 from ForgeFlow/fix-pgvector-files
josep-tecnativa Nov 7, 2025
8737a46
[FIX] Build pgvector from source on Alpine
josep-tecnativa Dec 19, 2025
193cc25
Merge pull request #29 from Tecnativa/fix-ci
josep-tecnativa Dec 22, 2025
5357fc9
[ADD] PG 18
josep-tecnativa Dec 24, 2025
567995b
Merge pull request #30 from Tecnativa/add-pg18
josep-tecnativa Dec 24, 2025
6b50875
[FIX] Define correctly PGVECTOR_VERSION
josep-tecnativa Jan 19, 2026
313f179
Merge pull request #32 from Tecnativa/fix-pgvector-version
josep-tecnativa Jan 19, 2026
66241e4
[FIX] fix alpine dependencies for pg_vector compilation
Auneor Mar 3, 2026
fbffb62
Merge pull request #34 from Auneor/FIX_pg_vector_build
josep-tecnativa Mar 18, 2026
79d281e
[IMP] Build Multiarch images in CI
ljmnoonan Jun 1, 2026
74192dc
[FIX] Bump actions/checkout and actions/cache
ljmnoonan Jun 9, 2026
49178e7
[FIX] Fix or get rid of broken repo badges
ljmnoonan Jun 6, 2026
5a3dcfc
Merge pull request #37 from Pyxiris/add-arm
david-banon-tecnativa Jun 15, 2026
311d76e
Fix clang/llvm
ljmnoonan Jul 6, 2026
6c0a19c
Merge pull request #40 from Pyxiris/fix-clang
david-banon-tecnativa Jul 6, 2026
85f46b5
ci: run build-test-push on all PRs and fix ghcr push auth
yajo Jun 22, 2026
e79329a
Merge pull request #39 from moduon/ci-build-on-prs
david-banon-tecnativa Jul 14, 2026
89cd20c
fix(pgvector): target x86-64-v2 for CPU portability
yajo Jun 12, 2026
0e87caf
Merge pull request #38 from moduon/pgvector-arch
david-banon-tecnativa Jul 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 61 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,96 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- name: Set PY
run:
echo "PY=$(python -c 'import hashlib,
sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
>> $GITHUB_ENV
- uses: actions/cache@v1
run: |
echo "PY=$(python -c 'import hashlib,sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
- uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/action@v1.0.1

build-test-push:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: pre-commit
permissions:
contents: read
packages: write
services:
registry:
image: registry:3
ports:
- 5000:5000
strategy:
fail-fast: false
matrix:
# Test modern Odoo versions with latest Postgres version
pg_version:
- "18"
- "17"
- "16"
- "15"
- "14"
- "13"
- "12"
- "11"
- "10"
- "9.6"
env:
DOCKER_PLATFORM: linux/amd64,linux/arm64
LOCAL_REGISTRY: localhost:5000
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
LATEST_RELEASE: "14.0"
# Variables found by default in Docker Hub builder
DOCKER_REPO: tecnativa/postgres-autoconf
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
LATEST_RELEASE: "18-alpine"
DOCKER_REPO: ${{ github.repository == 'Tecnativa/docker-postgres-autoconf' && 'tecnativa/postgres-autoconf' || github.repository }}
BASE_TAG: ${{ matrix.pg_version }}-alpine
DOCKER_TAG: ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
GIT_SHA1: ${{ github.sha }}
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_LOGIN: ${{ secrets.BOT_LOGIN }}
steps:
# Prepare
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
# Image repo names have to be lowercase.
- name: Lowercase image repository name
run: |
DOCKER_REPO=${DOCKER_REPO,,}
echo "DOCKER_REPO=$DOCKER_REPO" >> "$GITHUB_ENV"
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- run: pip install -r tests/ci-requirements.txt

- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
driver-opts: network=host
# Build images
- run: ./hooks/build
- name: Build images
run: ./hooks/build
# Test
- run: ./tests/test.py -v
- name: Test each platform
run: |
IFS=',' read -ra PLATFORMS <<< "$DOCKER_PLATFORM"
for platform in "${PLATFORMS[@]}"; do
echo "Testing platform: $platform"
TEST_PLATFORM="$platform" python -m unittest tests.test -v
done
# Push
- name: push to docker hub
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master'
- name: Push Docker Image to Docker Hub
if: env.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
env:
REGISTRY_HOST: docker.io
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
REGISTRY_TOKEN: ${{ env.DOCKERHUB_TOKEN }}
REGISTRY_USERNAME: ${{ env.DOCKERHUB_LOGIN }}
run: ./hooks/push
- name: push to github registry
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master'
- name: Push Docker Image to GitHub Registry
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository || env.BOT_TOKEN && env.BOT_LOGIN
env:
REGISTRY_HOST: ghcr.io
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
REGISTRY_TOKEN: ${{ secrets.BOT_LOGIN && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.BOT_TOKEN && secrets.BOT_LOGIN || github.repository_owner }}
run: ./hooks/push
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 19.3b0
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -21,10 +21,10 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.3
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
rev: v5.10.1
hooks:
- id: isort
32 changes: 20 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ARG BASE_TAG
FROM docker.io/postgres:${BASE_TAG}
ENTRYPOINT [ "/autoconf-entrypoint" ]
CMD []
ARG PGVECTOR_VERSION=0.8.1
ENV CERTS="{}" \
CONF_EXTRA="" \
LAN_AUTH_METHOD=md5 \
Expand All @@ -15,18 +16,25 @@ ENV CERTS="{}" \
WAN_DATABASES='["all"]' \
WAN_HBA_TPL="{connection} {db} {user} {cidr} {meth}" \
WAN_TLS=1 \
WAN_USERS='["all"]'
RUN apk add --no-cache python3 \
&& mkdir -p /etc/postgres \
&& chmod a=rwx /etc/postgres
RUN apk add --no-cache -t .build \
build-base \
linux-headers \
py3-pip \
python3-dev \
&& pip3 install --no-cache-dir \
netifaces \
&& apk del .build
WAN_USERS='["all"]' \
HBA_EXTRA_RULES=""
RUN apk add --no-cache python3 py3-netifaces \
&& if [ "${PG_MAJOR:-0}" -ge 13 ]; then \
PG_CLANG="$(pg_config --configure | tr "'" "\n" | sed -n 's/^CLANG=clang-//p')"; \
PG_LLVM="$(pg_config --configure | tr "'" "\n" | sed -n 's#^LLVM_CONFIG=/usr/lib/llvm\([0-9][0-9]*\)/bin/llvm-config#\1#p')"; \
test -n "${PG_CLANG}" && test -n "${PG_LLVM}" && test "${PG_CLANG}" = "${PG_LLVM}"; \
apk add --no-cache --virtual .pgvector-build build-base linux-headers ca-certificates "clang${PG_CLANG}" "llvm${PG_LLVM}"; \
wget -qO- "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" \
| tar -xz -C /tmp; \
cd "/tmp/pgvector-${PGVECTOR_VERSION}" \
&& make $(if [ "$(uname -m)" = "x86_64" ]; then echo 'CFLAGS=-march=x86-64-v2'; fi) PG_CONFIG=/usr/local/bin/pg_config \
&& make install PG_CONFIG=/usr/local/bin/pg_config; \
cd / && rm -rf "/tmp/pgvector-${PGVECTOR_VERSION}"; \
apk del .pgvector-build; \
fi \
&& mkdir -p /etc/postgres \
&& chmod a=rwx /etc/postgres

COPY autoconf-entrypoint /

# Metadata
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# PostgreSQL Auto-Conf

[![Build Status](https://travis-ci.org/Tecnativa/docker-postgres-autoconf.svg?branch=master)](https://travis-ci.org/Tecnativa/docker-postgres-autoconf)
[![Build Status](../../actions/workflows/ci.yaml/badge.svg?branch=master)](../../actions/workflows/ci.yaml)
[![Docker Pulls](https://img.shields.io/docker/pulls/tecnativa/postgres-autoconf.svg)](https://hub.docker.com/r/tecnativa/postgres-autoconf)
[![Layers](https://images.microbadger.com/badges/image/tecnativa/postgres-autoconf.svg)](https://microbadger.com/images/tecnativa/postgres-autoconf)
[![Commit](https://images.microbadger.com/badges/commit/tecnativa/postgres-autoconf.svg)](https://microbadger.com/images/tecnativa/postgres-autoconf)
[![License](https://img.shields.io/github/license/Tecnativa/docker-postgres-autoconf.svg)](https://github.com/Tecnativa/docker-postgres-autoconf/blob/master/LICENSE)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](../../blob/master/LICENSE)

## What

Expand Down Expand Up @@ -105,4 +103,17 @@ Wether to enable or not TLS in WAN connections.

Users allowed to connect from WAN.

#### `HBA_EXTRA_RULES`

JSON array of additional pg_hba.conf rules to append. Each array element should be a string representing a valid pg_hba.conf line.

Example HBA_EXTRA_RULES format in an .env file:

HBA_EXTRA_RULES=["host all all 192.168.1.0/24 md5", "hostssl mydb myuser 10.0.0.0/8 scram-sha-256"]

This adds the following lines to pg_hba.conf:

host all all 192.168.1.0/24 md5
hostssl mydb myuser 10.0.0.0/8 scram-sha-256

[`Dockerfile`]: https://github.com/Tecnativa/docker-postgres-autoconf/blob/master/Dockerfile
46 changes: 39 additions & 7 deletions autoconf-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ WAN_DATABASES = json.loads(os.environ["WAN_DATABASES"])
WAN_HBA_TPL = os.environ["WAN_HBA_TPL"]
WAN_TLS = json.loads(os.environ["WAN_TLS"])
WAN_USERS = json.loads(os.environ["WAN_USERS"])
PGSSLCERT = os.environ.get("PGSSLCERT")
PGSSLKEY = os.environ.get("PGSSLKEY")
PGSSLROOTCERT = os.environ.get("PGSSLROOTCERT")
HBA_EXTRA_RULES = os.environ.get("HBA_EXTRA_RULES", "")

# Configuration file templates
CONF_FOLDER = "/etc/postgres"
Expand All @@ -47,36 +51,55 @@ local all all trust
local replication all trust

# LAN/WAN autogenerated configurations
{extra_hba}
{extra_conf}
"""
WAN_CIDRS = ("0.0.0.0/0", "::0/0")

# Configuration helpers
hba_conf = []
ssl_conf = []
extra_hba = []


def permissions_fix(filename):
def permissions_fix(filename, client=False):
"""Make :param:`filename` be owned by root user and postgres group."""
shutil.chown(filename, "root", "postgres")
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
if client:
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR)
else:
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)


# Configure TLS
for key, filename in SUPPORTED_CERTS.items():
full_path = os.path.join(CONF_FOLDER, filename)
for key, filen in SUPPORTED_CERTS.items():
full_path = os.path.join(CONF_FOLDER, filen)
# Write PEM file if it came from env variable
if not os.path.exists(full_path) and CERTS.get(filename):
if not os.path.exists(full_path) and CERTS.get(filen):
with open(full_path, "w") as cert_file:
cert_file.write(CERTS[filename])
cert_file.write(CERTS[filen])
if os.path.exists(full_path):
# Enable file in postgres configuration
ssl_conf.append("{} = '{}'".format(key, full_path))
permissions_fix(full_path)
for filen in (PGSSLCERT, PGSSLKEY, PGSSLROOTCERT):
if filen and os.path.exists(filen):
permissions_fix(filen, client=True)

if ssl_conf:
ssl_conf.append("ssl = on")

# Parse extra rules for pg_hba.conf
extra_hba_rules = []
if HBA_EXTRA_RULES:
try:
extra_hba_rules = json.loads(HBA_EXTRA_RULES)
if not isinstance(extra_hba_rules, list):
raise ValueError("HBA_EXTRA_RULES must be a JSON array")
except json.JSONDecodeError:
print("Invalid JSON in HBA_EXTRA_RULES", file=sys.stderr)
sys.exit(1)

# Generate LAN auth configuration
for interface in netifaces.interfaces():
for type_, addresses in netifaces.ifaddresses(interface).items():
Expand Down Expand Up @@ -114,6 +137,13 @@ if WAN_CONNECTION != "hostssl" or ssl_conf:
)
)

# Append extra rules to extra_hba
for rule in extra_hba_rules:
if not isinstance(rule, str):
print("Each rule in HBA_EXTRA_RULES must be a string", file=sys.stderr)
sys.exit(1)
extra_hba.append(rule)

# Write postgres configuration files
with open(CONF_FILE, "w") as conf_file:
conf_file.write(
Expand All @@ -123,7 +153,9 @@ with open(CONF_FILE, "w") as conf_file:
)
permissions_fix(CONF_FILE)
with open(HBA_FILE, "w") as conf_file:
conf_file.write(HBA_TPL.format(extra_conf="\n".join(hba_conf)))
conf_file.write(
HBA_TPL.format(extra_hba="\n".join(extra_hba), extra_conf="\n".join(hba_conf))
)
permissions_fix(HBA_FILE)

# Continue normal execution
Expand Down
33 changes: 27 additions & 6 deletions hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,42 @@ from plumbum import FG, local
from plumbum.cmd import date, docker

# Check environment variables are present
DOCKER_PLATFORM = local.env.get("DOCKER_PLATFORM", "linux/amd64")
DOCKER_TAG = local.env["DOCKER_TAG"]
BASE_TAG = local.env.get("BASE_TAG", DOCKER_TAG)
REPO = local.env["DOCKER_REPO"]
COMMIT = local.env.get("GIT_SHA1")
DATE = date("--rfc-3339", "ns")
LOCAL_REGISTRY = local.env.get("LOCAL_REGISTRY")
IMAGE = (
"%s/%s:%s" % (LOCAL_REGISTRY, REPO, DOCKER_TAG)
if LOCAL_REGISTRY
else "%s:%s" % (REPO, DOCKER_TAG)
)
PLATFORMS = [p.strip() for p in DOCKER_PLATFORM.split(",") if p.strip()]

# Build image
docker[
"image",
build = docker[
"buildx",
"build",
"--platform",
DOCKER_PLATFORM,
"--build-arg",
"VCS_REF={}".format(COMMIT),
"--build-arg",
"BUILD_DATE={}".format(DATE),
"--build-arg",
"BASE_TAG={}".format(DOCKER_TAG),
"BASE_TAG={}".format(BASE_TAG),
"--tag",
"tecnativa/postgres-autoconf:{}".format(DOCKER_TAG),
IMAGE,
".",
] & FG
]
if LOCAL_REGISTRY:
build = build["--push"]
elif len(PLATFORMS) == 1:
build = build["--load"]
else:
raise SystemExit(
"Multi-platform builds require LOCAL_REGISTRY; "
"set DOCKER_PLATFORM to one value for local --load builds."
)
(build & FG)
Loading