Skip to content

Docker image build from official Postgres image #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM postgres:16.2-bookworm

ENV MQTT_BROKER 127.0.0.1
ENV POSTGRES_PASSWORD 123password

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y python3 python3-pip python3-venv \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /mqtt-pg-logger
COPY . /mqtt-pg-logger/
COPY sql/table.sql /docker-entrypoint-initdb.d/00_table.sql
COPY sql/convert.sql /docker-entrypoint-initdb.d/01_convert.sql
COPY sql/trigger.sql /docker-entrypoint-initdb.d/02_trigger.sql

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

WORKDIR /mqtt-pg-logger
RUN python3 -m venv venv \
&& . ./venv/bin/activate \
&& pip install -r requirements.txt

EXPOSE 5432

ENTRYPOINT ["/entrypoint.sh"]

22 changes: 22 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

[ -n "${MQTT_BROKER}" ] || exit 1

USER=${POSTGRES_USER:-postgres}
NAME=${POSTGRES_DB:-$USER}

cd /mqtt-pg-logger
cp mqtt-pg-logger.yaml.sample mqtt-pg-logger.yaml
chmod 600 mqtt-pg-logger.yaml
sed -i -e "s/<your[_ ]broker>/${MQTT_BROKER}/g" \
-e "s/<your[_ ]database[_ ]password>/${POSTGRES_PASSWORD}/g" \
-e "s/<your[_ ]database[_ ]user>/${USER}/g" \
-e "s/<your[_ ]database[_ ]name>/${NAME}/g" \
mqtt-pg-logger.yaml

docker-entrypoint.sh postgres &

until runuser -l postgres -c 'pg_isready -q'; do sleep 1; done

start-stop-daemon -S -x /mqtt-pg-logger/mqtt-pg-logger.sh -- --config-file /mqtt-pg-logger/mqtt-pg-logger.yaml

2 changes: 1 addition & 1 deletion mqtt-pg-logger.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mqtt:

database:
host: "localhost"
port: 5435
port: 5432
user: "<your database user>"
password: "<your database password>"
database: "<your database name>"
Expand Down