mirror of
https://github.com/Mesteriis/hassio-addons-avm.git
synced 2026-01-09 23:11:02 +01:00
WIP
This commit is contained in:
55
postgres/CHANGELOG.md
Normal file
55
postgres/CHANGELOG.md
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
## 15.5-7 (24-02-2024)
|
||||
|
||||
- Update pgvector to 0.2.0
|
||||
|
||||
## 15.5-6 (03-02-2024)
|
||||
|
||||
- Fix : use custom postgres username
|
||||
|
||||
## 15.5-5 (03-02-2024)
|
||||
|
||||
- Revert vector to 0.1.11 as only version supported by immich
|
||||
|
||||
## 15.5-4 (31-01-2024)
|
||||
|
||||
- ⚠ PLEASE BACKUP before updating! Non reversible changes
|
||||
- ⚠ WARNING : addition of pgvecto.rs extension, potentially breaking change ! Be sure to backup prior to update
|
||||
- ⚠ Database location changed from /data to /addon_configs/xxx-postgres : no expected user impact other that all configuration files will also be located in this folder accessible with addons such as Filebrowser
|
||||
|
||||
## 15.5 (11-11-2023)
|
||||
|
||||
- Update to latest version from postgres
|
||||
|
||||
## 15.4 (09-09-2023)
|
||||
|
||||
- Update to latest version from postgres
|
||||
|
||||
## 15.3-11 (08-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
|
||||
## 15.3-10 (08-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
## 15.3-9 (08-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
## 15.3-7 (07-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
## 15.3-6 (07-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
## 15.3-5 (07-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
## 15.3-2 (07-09-2023)
|
||||
|
||||
- Minor bugs fixed
|
||||
- Ensure postgres.conf persistcene
|
||||
|
||||
## 15.3
|
||||
|
||||
- Initial release
|
||||
- Removed useless webui button
|
||||
115
postgres/Dockerfile
Normal file
115
postgres/Dockerfile
Normal file
@@ -0,0 +1,115 @@
|
||||
#============================#
|
||||
# ALEXBELGIUM'S DOCKERFILE #
|
||||
#============================#
|
||||
# _.------.
|
||||
# _.-` ('>.-`"""-.
|
||||
# '.--'` _'` _ .--.)
|
||||
# -' '-.-';` `
|
||||
# ' - _.' ``'--.
|
||||
# '---` .-'""`
|
||||
# /`
|
||||
#=== Home Assistant Addon ===#
|
||||
|
||||
#################
|
||||
# 1 Build Image #
|
||||
#################
|
||||
|
||||
ARG BUILD_FROM
|
||||
ARG BUILD_VERSION
|
||||
FROM $BUILD_FROM
|
||||
|
||||
##################
|
||||
# 2 Modify Image #
|
||||
##################
|
||||
|
||||
# Set S6 wait time
|
||||
ENV S6_CMD_WAIT_FOR_SERVICES=1 \
|
||||
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
|
||||
S6_SERVICES_GRACETIME=0
|
||||
|
||||
|
||||
RUN \
|
||||
# Correct for access
|
||||
for file in /usr/share/postgresql/postgresql.conf.sample /usr/local/share/postgresql/postgresql.conf.sample; do \
|
||||
if [ -f "$file" ]; then sed -i "s|.*listen_addresses(.*)|listen_addresses = '*'(1)|g" "$file" && \
|
||||
sed -i "s|.*data_directory(.*)|data_directory = '/config/database'(1)|g" "$file"; fi; done
|
||||
|
||||
##################
|
||||
# 3 Install apps #
|
||||
##################
|
||||
|
||||
# Add rootfs
|
||||
COPY rootfs/ /
|
||||
|
||||
# Uses /bin for compatibility purposes
|
||||
# hadolint ignore=DL4005
|
||||
RUN if [ ! -f /bin/sh ] && [ -f /usr/bin/sh ]; then ln -s /usr/bin/sh /bin/sh; fi && \
|
||||
if [ ! -f /bin/bash ] && [ -f /usr/bin/bash ]; then ln -s /usr/bin/bash /bin/bash; fi
|
||||
|
||||
# Modules
|
||||
ARG MODULES="00-banner.sh 01-custom_script.sh 00-global_var.sh"
|
||||
|
||||
# Automatic modules download
|
||||
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automodules.sh" "/ha_automodules.sh"
|
||||
RUN chmod 744 /ha_automodules.sh && /ha_automodules.sh "$MODULES" && rm /ha_automodules.sh
|
||||
|
||||
# Manual apps
|
||||
ENV PACKAGES=""
|
||||
|
||||
# Automatic apps & bashio
|
||||
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_autoapps.sh" "/ha_autoapps.sh"
|
||||
RUN chmod 744 /ha_autoapps.sh && /ha_autoapps.sh "$PACKAGES" && rm /ha_autoapps.sh
|
||||
|
||||
################
|
||||
# 4 Entrypoint #
|
||||
################
|
||||
|
||||
# Add entrypoint
|
||||
ENV S6_STAGE2_HOOK=/ha_entrypoint.sh
|
||||
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_entrypoint.sh" "/ha_entrypoint.sh"
|
||||
|
||||
# Entrypoint modifications
|
||||
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_entrypoint_modif.sh" "/ha_entrypoint_modif.sh"
|
||||
RUN chmod 777 /ha_entrypoint.sh /ha_entrypoint_modif.sh && /ha_entrypoint_modif.sh && rm /ha_entrypoint_modif.sh
|
||||
|
||||
RUN chmod 777 /docker-entrypoint-initdb.d/*
|
||||
WORKDIR /config
|
||||
ENTRYPOINT [ "/usr/bin/env" ]
|
||||
CMD [ "/ha_entrypoint.sh" ]
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
############
|
||||
# 5 Labels #
|
||||
############
|
||||
|
||||
ARG BUILD_ARCH
|
||||
ARG BUILD_DATE
|
||||
ARG BUILD_DESCRIPTION
|
||||
ARG BUILD_NAME
|
||||
ARG BUILD_REF
|
||||
ARG BUILD_REPOSITORY
|
||||
ARG BUILD_VERSION
|
||||
LABEL \
|
||||
io.hass.name="${BUILD_NAME}" \
|
||||
io.hass.description="${BUILD_DESCRIPTION}" \
|
||||
io.hass.arch="${BUILD_ARCH}" \
|
||||
io.hass.type="addon" \
|
||||
io.hass.version=${BUILD_VERSION} \
|
||||
maintainer="alexbelgium (https://github.com/alexbelgium)" \
|
||||
org.opencontainers.image.title="${BUILD_NAME}" \
|
||||
org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
|
||||
org.opencontainers.image.vendor="Home Assistant Add-ons" \
|
||||
org.opencontainers.image.authors="alexbelgium (https://github.com/alexbelgium)" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.url="https://github.com/alexbelgium" \
|
||||
org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
|
||||
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
|
||||
org.opencontainers.image.created=${BUILD_DATE} \
|
||||
org.opencontainers.image.revision=${BUILD_REF} \
|
||||
org.opencontainers.image.version=${BUILD_VERSION}
|
||||
|
||||
####################
|
||||
# 6 HealthcheckNOT #
|
||||
####################
|
||||
|
||||
# Can't be implemented as container is optimized for memory usage, so the webserver and Node are spun down during idle
|
||||
65
postgres/README.md
Normal file
65
postgres/README.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Home assistant add-on: Postgres
|
||||
|
||||
[![Donate][donation-badge]](https://www.buymeacoffee.com/alexbelgium)
|
||||
[![Donate][paypal-badge]](https://www.paypal.com/donate/?hosted_button_id=DZFULJZTP3UQA)
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
[](https://www.codacy.com/gh/alexbelgium/hassio-addons/dashboard?utm_source=github.com&utm_medium=referral&utm_content=alexbelgium/hassio-addons&utm_campaign=Badge_Grade)
|
||||
[](https://github.com/alexbelgium/hassio-addons/actions/workflows/weekly-supelinter.yaml)
|
||||
[](https://github.com/alexbelgium/hassio-addons/actions/workflows/onpush_builder.yaml)
|
||||
|
||||
[donation-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee%20(no%20paypal)-%23d32f2f?logo=buy-me-a-coffee&style=flat&logoColor=white
|
||||
[paypal-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee%20with%20Paypal-0070BA?logo=paypal&style=flat&logoColor=white
|
||||
|
||||
_Thanks to everyone having starred my repo! To star it click on the image below, then it will be on top right. Thanks!_
|
||||
|
||||
[](https://github.com/alexbelgium/hassio-addons/stargazers)
|
||||
|
||||

|
||||
|
||||
## About
|
||||
|
||||
PostgreSQL, often simply "Postgres", is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance. As a database server, its primary function is to store data, securely and supporting best practices, and retrieve it later, as requested by other software applications, be it those on the same computer or those running on another computer across a network (including the Internet). It can handle workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users. Recent versions also provide replication of the database itself for security and scalability.
|
||||
|
||||
This addon is based on the official image : https://hub.docker.com/_/postgres
|
||||
|
||||
## Configuration
|
||||
|
||||
Postgres port is by default 5432 and is exposed to the host network.
|
||||
|
||||
default user: `postgres`
|
||||
password: `set by POSTGRES_PASSWORD`
|
||||
|
||||
You can configure this options:
|
||||
```yaml
|
||||
POSTGRES_PASSWORD
|
||||
POSTGRES_USER
|
||||
POSTGRES_DB
|
||||
POSTGRES_INITDB_ARGS
|
||||
POSTGRES_HOST_AUTH_METHOD
|
||||
```
|
||||
For more info check [base image docs](https://hub.docker.com/_/postgres).
|
||||
|
||||
By default `postgresql.conf` is stored in volume accessible by other addons and Home Assistant, so you can conviniently modify it by e.g. File Editor addon. If you prefer better security change `CONFIG_LOCATION` to e.g. `/data/orig/postgresql.conf`, so it will be acessible only to this addon, but you will have to modify it by the [Hassio SSH](https://developers.home-assistant.io/docs/operating-system/debugging/).
|
||||
|
||||
## Installation
|
||||
|
||||
The installation of this add-on is pretty straightforward and not different in comparison to installing any other add-on.
|
||||
|
||||
1. Add my add-ons repository to your home assistant instance (in supervisor addons store at top right, or click button below if you have configured my HA)
|
||||
[](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Falexbelgium%2Fhassio-addons)
|
||||
1. Install this add-on.
|
||||
1. Click the `Save` button to store your configuration.
|
||||
1. Set the add-on options to your preferences, at least POSTGRES_PASSWORD is required.
|
||||
1. Start the add-on.
|
||||
1. Check the logs of the add-on to see if everything went well.
|
||||
1. Use any Postgres client to connect, e.g. to `homeassistant.local:5432`
|
||||
|
||||
## Support
|
||||
|
||||
Create an issue on github
|
||||
|
||||
[repository]: https://github.com/alexbelgium/hassio-addons
|
||||
70
postgres/apparmor.txt
Normal file
70
postgres/apparmor.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <tunables/global>
|
||||
|
||||
profile postgres_addon flags=(attach_disconnected,mediate_deleted) {
|
||||
#include <abstractions/base>
|
||||
|
||||
capability,
|
||||
file,
|
||||
signal,
|
||||
mount,
|
||||
umount,
|
||||
remount,
|
||||
network udp,
|
||||
network tcp,
|
||||
network dgram,
|
||||
network stream,
|
||||
network inet,
|
||||
network inet6,
|
||||
network netlink raw,
|
||||
network unix dgram,
|
||||
|
||||
capability setgid,
|
||||
capability setuid,
|
||||
capability sys_admin,
|
||||
capability dac_read_search,
|
||||
capability dac_override,
|
||||
# capability sys_rawio,
|
||||
|
||||
# S6-Overlay
|
||||
/init ix,
|
||||
/run/{s6,s6-rc*,service}/** ix,
|
||||
/package/** ix,
|
||||
/command/** ix,
|
||||
/run/{,**} rwk,
|
||||
/dev/tty rw,
|
||||
/bin/** ix,
|
||||
/usr/bin/** ix,
|
||||
/usr/lib/bashio/** ix,
|
||||
/etc/s6/** rix,
|
||||
/run/s6/** rix,
|
||||
/etc/services.d/** rwix,
|
||||
/etc/cont-init.d/** rwix,
|
||||
/etc/cont-finish.d/** rwix,
|
||||
/init rix,
|
||||
/var/run/** mrwkl,
|
||||
/var/run/ mrwkl,
|
||||
/dev/i2c-1 mrwkl,
|
||||
# Files required
|
||||
/dev/fuse mrwkl,
|
||||
/dev/sda1 mrwkl,
|
||||
/dev/sdb1 mrwkl,
|
||||
/dev/nvme0 mrwkl,
|
||||
/dev/nvme1 mrwkl,
|
||||
/dev/mmcblk0p1 mrwkl,
|
||||
/dev/* mrwkl,
|
||||
/udev/* mrwkl,
|
||||
/tmp/** mrkwl,
|
||||
/dev/fuse/** mrkwl,
|
||||
/dev/** mrkwl,
|
||||
/sys/firmware/** mrkwl,
|
||||
|
||||
# Data access
|
||||
/data/** rw,
|
||||
|
||||
# suppress ptrace denials when using 'docker ps' or using 'ps' inside a container
|
||||
ptrace (trace,read) peer=docker-default,
|
||||
|
||||
# docker daemon confinement requires explict allow rule for signal
|
||||
signal (receive) set=(kill,term) peer=/usr/bin/docker,
|
||||
|
||||
}
|
||||
10
postgres/build.json
Normal file
10
postgres/build.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"build_from": {
|
||||
"aarch64": "tensorchord/pgvecto-rs:pg15-v0.2.0",
|
||||
"amd64": "tensorchord/pgvecto-rs:pg15-v0.2.0",
|
||||
"armv7": "postgres:15-alpine"
|
||||
},
|
||||
"codenotary": {
|
||||
"signer": "alexandrep.github@gmail.com"
|
||||
}
|
||||
}
|
||||
41
postgres/config.json
Normal file
41
postgres/config.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"arch": [
|
||||
"aarch64",
|
||||
"amd64",
|
||||
"armv7"
|
||||
],
|
||||
"backup": "cold",
|
||||
"codenotary": "alexandrep.github@gmail.com",
|
||||
"description": "Postgres 15 with pgvecto.rs support",
|
||||
"environment": {
|
||||
"CONFIG_LOCATION": "/config/postgresql.conf",
|
||||
"PGDATA": "/config/database"
|
||||
},
|
||||
"image": "ghcr.io/alexbelgium/postgres-{arch}",
|
||||
"map": [
|
||||
"addon_config:rw",
|
||||
"homeassistant_config:rw",
|
||||
"media:rw"
|
||||
],
|
||||
"name": "Postgres 15",
|
||||
"options": {
|
||||
"POSTGRES_PASSWORD": "homeassistant"
|
||||
},
|
||||
"ports": {
|
||||
"5432/tcp": 5432
|
||||
},
|
||||
"ports_description": {
|
||||
"5432/tcp": "Postgres"
|
||||
},
|
||||
"schema": {
|
||||
"POSTGRES_DB": "str?",
|
||||
"POSTGRES_HOST_AUTH_METHOD": "str?",
|
||||
"POSTGRES_INITDB_ARGS": "str?",
|
||||
"POSTGRES_PASSWORD": "str",
|
||||
"POSTGRES_USER": "str?"
|
||||
},
|
||||
"slug": "postgres",
|
||||
"udev": true,
|
||||
"url": "https://github.com/alexbelgium/hassio-addons",
|
||||
"version": "15.5-7"
|
||||
}
|
||||
BIN
postgres/icon.png
Normal file
BIN
postgres/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
postgres/logo.png
Normal file
BIN
postgres/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
27
postgres/rootfs/docker-entrypoint-initdb.d/10-vector.sh
Executable file
27
postgres/rootfs/docker-entrypoint-initdb.d/10-vector.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
bashio::log.info "Waiting for port 5432 to open..."
|
||||
|
||||
# Wait for transmission to become available
|
||||
bashio::net.wait_for 5432 localhost 900
|
||||
|
||||
bashio::log.info "Enabling vector.rs"
|
||||
|
||||
# Set variables for vector.rs
|
||||
DB_PORT=5432
|
||||
DB_HOSTNAME=localhost
|
||||
DB_PASSWORD="$(bashio::config 'POSTGRES_PASSWORD')"
|
||||
if bashio::config.has_value "POSTGRES_USER"; then DB_USERNAME="$(bashio::config "POSTGRES_USER")"; else DB_USERNAME=postgres; fi
|
||||
|
||||
export DB_PORT
|
||||
export DB_HOSTNAME
|
||||
export DB_USERNAME
|
||||
export DB_PASSWORD
|
||||
echo "DROP EXTENSION IF EXISTS vectors;
|
||||
CREATE EXTENSION vectors;
|
||||
\q"> setup_postgres.sql
|
||||
|
||||
# Enable vectors
|
||||
psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" < setup_postgres.sql || true
|
||||
17
postgres/rootfs/etc/cont-init.d/20-folders.sh
Executable file
17
postgres/rootfs/etc/cont-init.d/20-folders.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Migration
|
||||
if [ -d /data/database ]; then
|
||||
bashio::log.warning "Database migrated to /config"
|
||||
mv /data/database /config
|
||||
fi
|
||||
|
||||
if [ -f /homeassistant/addons_config/postgres/config.yaml ]; then
|
||||
bashio::log.warning "Config migrated to /config"
|
||||
mv /homeassistant/addons_config/postgres/* /config/
|
||||
rm -r /homeassistant/addons_config/postgres
|
||||
# Correct database location
|
||||
sed -i "s|/data/database|/config/database|g" /config/postgresql.conf
|
||||
fi
|
||||
50
postgres/rootfs/etc/cont-init.d/99-run.sh
Executable file
50
postgres/rootfs/etc/cont-init.d/99-run.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Use new config file
|
||||
CONFIG_HOME="/config"
|
||||
mkdir -p "$CONFIG_HOME"
|
||||
if [ ! -f "$CONFIG_HOME"/postgresql.conf ]; then
|
||||
# Copy default config.env
|
||||
if [ -f /usr/local/share/postgresql/postgresql.conf.sample ]; then
|
||||
cp /usr/local/share/postgresql/postgresql.conf.sample "$CONFIG_HOME"/postgresql.conf
|
||||
elif [ -f /usr/share/postgresql/postgresql.conf.sample ]; then
|
||||
cp /usr/share/postgresql/postgresql.conf.sample "$CONFIG_HOME"/postgresql.conf
|
||||
else
|
||||
bashio::exit.nok "Config file not found, please ask maintainer"
|
||||
fi
|
||||
bashio::log.warning "A default config.env file was copied in $CONFIG_HOME. Please customize according to https://hub.docker.com/_/postgres and restart the add-on"
|
||||
else
|
||||
bashio::log.warning "The config.env file found in $CONFIG_HOME will be used (mapped to /addon_configs/xxx-postgres when accessing from Filebrowser). Please customize according to https://hub.docker.com/_/postgres and restart the add-on"
|
||||
fi
|
||||
|
||||
# Define home
|
||||
# Creating config location
|
||||
mkdir -p "$PGDATA"
|
||||
chown -R postgres:postgres "$PGDATA"
|
||||
chmod 777 "$PGDATA"
|
||||
|
||||
# Permissions
|
||||
chmod -R 777 "$CONFIG_HOME"
|
||||
|
||||
##############
|
||||
# Launch App #
|
||||
##############
|
||||
|
||||
# Go to folder
|
||||
cd /config || true
|
||||
|
||||
echo " "
|
||||
bashio::log.info "Starting the app"
|
||||
echo " "
|
||||
|
||||
# Add docker-entrypoint command
|
||||
if [ "$(bashio::info.arch)" != "armv7" ]; then
|
||||
# Exec vecto modification
|
||||
/./docker-entrypoint-initdb.d/10-vector.sh & \
|
||||
docker-entrypoint.sh postgres -c shared_preload_libraries=vectors.so
|
||||
else
|
||||
bashio::log.warning "Your architecture is armv7, pgvecto.rs is disabled as not supported"
|
||||
docker-entrypoint.sh postgres
|
||||
fi
|
||||
12
postgres/updater.json
Normal file
12
postgres/updater.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"dockerhub_by_date": true,
|
||||
"dockerhub_list_size": 2,
|
||||
"github_tagfilter": "15",
|
||||
"last_update": "11-11-2023",
|
||||
"paused": true,
|
||||
"repository": "Mesteriis/hassio-addons-avm",
|
||||
"slug": "postgres",
|
||||
"source": "github",
|
||||
"upstream_repo": "tensorchord/pgvecto.rs",
|
||||
"upstream_version": "15.5"
|
||||
}
|
||||
Reference in New Issue
Block a user