14 Commits
v0.1.4 ... main

Author SHA1 Message Date
b9accfedd2 doc: remove env file from readme
All checks were successful
Continuous Integration / lint_n_build (push) Successful in 18s
2026-03-08 23:09:15 +01:00
8a8da6a7be fix: add run postgresql folder to rpmspec files
All checks were successful
Continuous Integration / lint_n_build (push) Successful in 17s
Continuous Delivery / build_n_upload (push) Successful in 18s
2026-03-08 22:58:10 +01:00
644ced9ca6 ci: trigger
All checks were successful
Continuous Integration / lint_n_build (push) Successful in 17s
Continuous Delivery / build_n_upload (push) Successful in 18s
2026-03-08 22:48:31 +01:00
e9cf428dd2 ci: update runner label
Some checks failed
Continuous Integration / lint_n_build (push) Failing after 13s
2026-03-08 22:42:23 +01:00
5c2a5d0710 ci: improve workflows
Some checks failed
Continuous Integration / lint_n_build (push) Has been cancelled
2026-03-08 22:41:09 +01:00
6e7800721f feat: restrict access to postgres socket
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-24 13:37:10 +01:00
fe30792dbf fix: chown sock directory
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-23 00:16:05 +01:00
0483f61904 fix: create sock directory if not existing
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-23 00:05:14 +01:00
ac5a23350d fix: add systemctl restart
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:57:20 +01:00
5870da6249 fix: create db users after service start
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:42:53 +01:00
5bf84b3719 fix: add drop-in directory in spec file
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:35:06 +01:00
c55e4199e8 fix: postgresql conf quotes
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:28:21 +01:00
fde6b4b621 fix: override execstart
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 21:58:30 +01:00
98dbfe8da5 feat: add db users
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 16:24:16 +01:00
7 changed files with 166 additions and 59 deletions

View File

@@ -7,20 +7,14 @@ on:
jobs: jobs:
build_n_upload: build_n_upload:
runs-on: linux runs-on: self-hosted
steps: steps:
- name: Git checkout - uses: actions/checkout@v6
uses: actions/checkout@v6
with: with:
detch-depth: 0
fetch-tags: true fetch-tags: true
- name: Build tarball - run: make tarball
run: make tarball - run: rpmbuild -ba "$(make name).spec"
- run: make upload
env: env:
GIT_REFERENCE: ${{ github.ref }} PKG_TOKEN: ${{ secrets.PKG_TOKEN }}
- name: Build rpm package
run: rpmbuild -ba "%(make name).spec"
- name: Upload rpm package
run: make upload
env:
GIT_PACKAGES_USERNAME: ${{ vars.GIT_PACKAGES_USERNAME }}
GIT_PACKAGES_TOKEN: ${{ secrets.GIT_PACKAGES_TOKEN }}

View File

@@ -7,14 +7,11 @@ on:
jobs: jobs:
lint_n_build: lint_n_build:
runs-on: linux runs-on: self-hosted
steps: steps:
- name: Git checkout - uses: actions/checkout@v6
uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
fetch-tags: true fetch-tags: true
- name: Build tarball - run: make tarball
run: make tarball - run: rpmbuild -ba "$(make name).spec"
- name: Build rpm file
run: rpmbuild -ba "$(make name).spec"

View File

@@ -1,50 +1,87 @@
NAME = netoik-db NAME = netoik-db
VERSION = $(shell git describe --abbrev=0) VERSION = $(shell git describe --abbrev=0)
RELEASE = $(shell git rev-parse --short HEAD) RELEASE = $(shell git rev-parse --short HEAD)
REFERENCE = $(if $(GIT_REFERENCE),$(GIT_REFERENCE),$(shell git branch --show-current)) ARCH = noarch
BUILD_ARCH = noarch OWNER = samuel
SUMMARY = "Netoïk Database Management System"
LICENSE = "MIT"
URL = "https://git.netoik.io/$(OWNER)/$(NAME)"
SOURCE0 = "$(NAME)-$(VERSION)-$(RELEASE).tar.gz"
RPM_RPMDIR = $(shell rpm --eval '%{_rpmdir}') RPM_RPMDIR = $(shell rpm --eval '%{_rpmdir}')
RPM_RUNDIR = $(shell rpm --eval '%{_rundir}')
RPM_SBINDIR = $(shell rpm --eval '%{_sbindir}') RPM_SBINDIR = $(shell rpm --eval '%{_sbindir}')
RPM_SOURCEDIR = $(shell rpm --eval '%{_sourcedir}') RPM_SOURCEDIR = $(shell rpm --eval '%{_sourcedir}')
RPM_SYSCONFDIR = $(shell rpm --eval '%{_sysconfdir}') RPM_SYSCONFDIR = $(shell rpm --eval '%{_sysconfdir}')
RPM_UNITDIR = $(shell rpm --eval '%{_unitdir}') RPM_UNITDIR = $(shell rpm --eval '%{_unitdir}')
RPM_TARBALL_PATH = $(RPM_SOURCEDIR)/$(NAME)-$(VERSION).tar.gz
RPM_BUILD_PATH = $(RPM_RPMDIR)/$(BUILD_ARCH)/$(NAME)-$(VERSION)-$(RELEASE).$(BUILD_ARCH).rpm RPM_TARBALL_PATH = $(RPM_SOURCEDIR)/$(SOURCE0)
RPM_BUILD_PATH = $(RPM_RPMDIR)/$(ARCH)/$(NAME)-$(VERSION)-$(RELEASE).$(ARCH).rpm
.PHONY: help
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: name .PHONY: name
name: name: ## Show project name
@echo "$(NAME)" @echo "$(NAME)"
.PHONY: version .PHONY: version
version: version: ## Show current project version
@echo "$(VERSION)" @echo "$(VERSION)"
.PHONY: release .PHONY: release
release: release: ## Show current project release
@echo "$(RELEASE)" @echo "$(RELEASE)"
.PHONY: build_arch .PHONY: arch
build_arch: arch: ## Show rpm arch target
@echo "$(BUILD_ARCH)" @echo "$(ARCH)"
.PHONY: install .PHONY: owner
install: owner: ## Show project owner name
install --mode=755 --directory $(DESTDIR)$(RPM_SYSCONFDIR)/postgres $(DESTDIR)$(RPM_UNITDIR)/postgresql.service.d @echo "$(OWNER)"
install --mode=644 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/postgres files/postgres/postgresql.conf files/postgres/pg_hba.conf
install --mode=644 --target-directory=$(DESTDIR)$(RPM_UNITDIR)/postgresql.service.d files/systemd/postgres.conf .PHONY: summary
summary: ## Show project summary
@echo "$(SUMMARY)"
.PHONY: license
license: ## Show project license
@echo "$(LICENSE)"
.PHONY: url
url: ## Show project homepage URL
@echo "$(URL)"
.PHONY: source0
source0: ## Show rpm source0 file name
@echo "$(SOURCE0)"
$(RPM_TARBALL_PATH): * $(RPM_TARBALL_PATH): *
git archive --format=tar.gz \ git archive --format=tar.gz \
--output="$@" \ --output="$@" \
--prefix="$(NAME)-$(VERSION)/" \ --prefix="$(NAME)-$(VERSION)/" \
--verbose \ --verbose \
"$(REFERENCE)" HEAD
.PHONY: tarball .PHONY: tarball
tarball: $(RPM_TARBALL_PATH) tarball: $(RPM_TARBALL_PATH) ## Build rpm tarball
.PHONY: install
install: ## Install files into rpm dest (requires env var DESTDIR)
@if [ -z "$(DESTDIR)" ]; then \
printf "[CRITICAL] Missing env var DESTDIR\n[CRITICAL] This command is designed to be called by rpmbuild only!\n" 1>&2; \
exit 1; \
fi
install --mode=755 --directory $(DESTDIR)$(RPM_RUNDIR)/postgresql $(DESTDIR)$(RPM_SYSCONFDIR)/postgres $(DESTDIR)$(RPM_UNITDIR)/postgresql.service.d
install --mode=644 --target-directory=$(DESTDIR)$(RPM_SYSCONFDIR)/postgres files/postgres/postgresql.conf files/postgres/pg_hba.conf
install --mode=644 --target-directory=$(DESTDIR)$(RPM_UNITDIR)/postgresql.service.d files/systemd/postgres.conf
.PHONY: upload .PHONY: upload
upload: upload: ## Upload rpm package to Gitea repository (requires env var PKG_TOKEN)
curl --fail-with-body --upload-file "$(RPM_BUILD_PATH)" --user "$(GIT_PACKAGES_USERNAME):$(GIT_PACKAGES_TOKEN)" https://git.netoik.io/api/packages/$(GIT_PACKAGES_USERNAME)/rpm/upload @if [ -z "$(PKG_TOKEN)" ]; then \
printf "[CRITICAL] Missing env var PKG_TOKEN\n[CRITICAL] This command is designed to be called by Gitea Actions only!\n" 1>&2; \
exit 1; \
fi
curl --fail-with-body --upload-file "$(RPM_BUILD_PATH)" --user "$(OWNER):$(PKG_TOKEN)" https://git.netoik.io/api/packages/$(OWNER)/rpm/upload

View File

@@ -1,3 +1,80 @@
# Netoïk Database ![badge](https://git.netoik.io/samuel/netoik-db/actions/workflows/ci.yaml/badge.svg) # Netoïk Database ![badge](https://git.netoik.io/samuel/netoik-db/actions/workflows/ci.yaml/badge.svg)
Build an RPM package which will install the DBMS called Postgresql with custom configuration. Build an RPM package which will install the DBMS called Postgresql with custom configuration.
- listen only on a unix socket
- each user is authentified by its unix account
# Development
A `Makefile` is integrated to let you run some basic commands.
- Display some information about the project
```shell
make help
make name
make version
make release
make arch
```
- Build a tarball:
```shell
make tarball
```
- Build an rpm package:
```shell
rpmbuild -ba netoik-db.spec
```
- Upload rpm package to Gitea repository (env var `PKG_TOKEN` is required):
```shell
make upload
```
# CI / CD
Two workflows are set up.
- Continuous Integration:
- triggered by each push event on branch `main`
- builds tarball
- builds rpm package
- Continuous Delivery:
- triggered by each tag push event
- builds tarball
- builds rpm package
- uploads rpm package to repository
# Deployment
Some commands to deploy the RPM package on server
- Add Gitea repo to your repo list:
```shell
dnf config-manager --add-repo https://git.netoik.io/api/packages/samuel/rpm.repo
dnf repolist | grep gitea-samuel
```
- Show available versions:
```shell
dnf --showduplicates netoik-db
```
- Install or upgrade package:
```shell
dnf --nogpgcheck --refresh --assumeyes --best install netoik-db
```
# Security Notes
For security reasons, act runners does not have sudo privileges and so there is:
- **no** Continuous Deployment because act runners cannot use `dnf`
- **no** GPG signing because act runners cannot use `gpg`

View File

@@ -5,7 +5,7 @@
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Change pg_hba location # Change pg_hba location
hba_file = "/etc/postgres/pg_hba.conf" hba_file = '/etc/postgres/pg_hba.conf'
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -16,7 +16,10 @@ hba_file = "/etc/postgres/pg_hba.conf"
# Empty listen addresses to disable listening via TCP/IP # Empty listen addresses to disable listening via TCP/IP
# because we want only uni socket connections # because we want only uni socket connections
listen_addresses = "" listen_addresses = ''
# Forbide access to users not in group postgres
unix_socket_permissions = 0770
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -26,4 +29,4 @@ listen_addresses = ""
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Redirect logs to stderr to be managed by journald # Redirect logs to stderr to be managed by journald
log_destination = "stderr" log_destination = 'stderr'

View File

@@ -1,2 +1,3 @@
[Service] [Service]
ExecStart=
ExecStart=/usr/bin/postgres -D ${PGDATA} -c config_file=/etc/postgres/postgresql.conf ExecStart=/usr/bin/postgres -D ${PGDATA} -c config_file=/etc/postgres/postgresql.conf

View File

@@ -3,12 +3,12 @@
Name: %(make name) Name: %(make name)
Version: %(make version) Version: %(make version)
Release: %(make release) Release: %(make release)
Summary: Netoik Reverse Proxy Summary: %(make summary)
License: MIT License: %(make license)
URL: https://git.netoik.io/samuel/%(make name) URL: %(make url)
Source0: %{name}-%{version}.tar.gz Source0: %(make source0)
Buildarch: %(make build_arch) Buildarch: %(make arch)
BuildRequires: make BuildRequires: make
Requires: postgresql-server postgresql Requires: postgresql-server postgresql
@@ -22,25 +22,23 @@ Install the database management system called postgresql with a predefined confi
%make_install %make_install
%post %post
# Create databases and users from DB_USERS variable (separator is ",") if not existing # Create sock directory if not existing
echo "$DB_USERS" | IFS="," read -ra users chown postgres:postgres "%{_rundir}/postgresql"
for user in "${users[@]}"; do
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --invert-match postgres | grep --quiet "$user"; then
runuser --user=postgres -- createuser "$user"
runuser --user=postgres -- createdb --owner="$user" "$user"
fi
done
# Restart services # Restart services
systemctl daemon-reload systemctl daemon-reload
systemctl reenable --now postgresql.service systemctl reenable postgresql.service
systemctl restart postgresql.service
%files %files
%attr(755, root, root) %{_sysconfdir}/postgres %dir %attr(755, root, root) %{_sysconfdir}/postgres
%attr(644, root, root) %{_sysconfdir}/postgres/postgresql.conf %attr(644, root, root) %{_sysconfdir}/postgres/postgresql.conf
%attr(644, root, root) %{_sysconfdir}/postgres/pg_hba.conf %attr(644, root, root) %{_sysconfdir}/postgres/pg_hba.conf
%dir %attr(755, root, root) %{_unitdir}/postgresql.service.d
%attr(644, root, root) %{_unitdir}/postgresql.service.d/postgres.conf %attr(644, root, root) %{_unitdir}/postgresql.service.d/postgres.conf
%dir %attr(755, -, -) %{_rundir}/postgresql
%changelog %changelog
%autochangelog %autochangelog