Skip to content

Commit da30b44

Browse files
authored
Add Dockerfile
1 parent 957d81b commit da30b44

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2021-2022 Cisco Systems, Inc. and others.
2+
# All rights reserved.
3+
FROM timescale/timescaledb-ha:pg14-ts2.8-latest
4+
5+
ARG VERSION=0.0.0
6+
7+
ENV PGDATA=/var/lib/postgresql/data
8+
ENV PGDATA_TS=/var/lib/postgresql/ts/data
9+
10+
# Expected data locations for base tables and timeseries
11+
VOLUME ["/var/lib/postgresql/data"]
12+
VOLUME ["/var/lib/postgresql/ts"]
13+
14+
ADD --chmod=755 scripts/004_obmp_psql_cfg.sh /docker-entrypoint-initdb.d/004_obmp_psql_cfg.sh
15+
ADD --chmod=755 scripts/005_obmp_init.sh /docker-entrypoint-initdb.d/005_obmp_init.sh
16+
17+
USER root
18+
19+
RUN rm -rf /usr/lib/postgresql/12 /usr/lib/postgresql/13 \
20+
&& mkdir -p /var/lib/postgresql/data /var/lib/postgresql/ts/data \
21+
&& chown -R postgres /var/lib/postgresql/data /var/lib/postgresql/ts/data \
22+
&& mkdir -p /usr/local/openbmp \
23+
&& touch /usr/local/openbmp/version-${VERSION}
24+
25+
USER postgres

scripts/004_obmp_psql_cfg.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# OpenBMP Postgres configuration
4+
#
5+
# Copyright (c) 2022 Cisco Systems, Inc. and Tim Evens. All rights reserved.
6+
#
7+
8+
9+
# Create SSL cert
10+
openssl req -x509 -newkey rsa:4096 -nodes -subj "/C=US/ST=CA/L=Seattle/O=OpenBMP/CN=localhost" \
11+
-keyout $PGDATA/psql_server.key -out $PGDATA/psql_server.crt -days 2048 \
12+
13+
# Init timeseries location
14+
mkdir -p $PGDATA_TS
15+
chmod 0700 $PGDATA_TS
16+
psql -U $POSTGRES_USER -c "CREATE TABLESPACE timeseries LOCATION '$PGDATA_TS';" $POSTGRES_DB
17+
18+
# Update postgres conf
19+
sed -i -e "s/^\#*listen_addresses.*=.*/listen_addresses = '*'/" $PGDATA/postgresql.conf
20+
sed -i -e "s/^\#*ssl[ ]*=.*/ssl = on/" $PGDATA/postgresql.conf
21+
sed -i -e "s/^\#*ssl_cert_file.*=.*/ssl_cert_file = '${PGDATA//\//\\\/}\/psql_server.crt'/" $PGDATA/postgresql.conf
22+
sed -i -e "s/^\#*ssl_key_file.*=.*/ssl_key_file = '${PGDATA//\//\\\/}\/psql_server.key'/" $PGDATA/postgresql.conf
23+
24+
sed -i -e "s/^shared_preload_libraries.*/shared_preload_libraries = 'timescaledb,pg_cron'/g" $PGDATA/postgresql.conf
25+
26+
echo "cron.database_name = 'openbmp'" >> $PGDATA/postgresql.conf
27+
28+
egrep -q -e '^hostssl( |\t)+all' $PGDATA/pg_hba.conf
29+
if [[ $? ]]; then
30+
echo 'hostssl all all 0.0.0.0/0 md5' >> $PGDATA/pg_hba.conf
31+
fi
32+
33+
34+
pg_ctl -D "$PGDATA" -m fast -w restart

scripts/005_obmp_init.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# postgres: Init script
4+
#
5+
# Copyright (c) 2021-2022 Cisco Systems, Inc. and Tim Evens. All rights reserved.
6+
#
7+
8+
# >> NOTE, before adding extensions, required preload/config should be done first in 004_obmp_psql_cfg.sh
9+
10+
# Add extensions
11+
psql -U $POSTGRES_USER -c "CREATE EXTENSION IF NOT EXISTS postgis CASCADE;" $POSTGRES_DB
12+
psql -U $POSTGRES_USER -c "CREATE EXTENSION IF NOT EXISTS pgrouting CASCADE;" $POSTGRES_DB
13+
14+
# Add cron extension and config
15+
psql -U $POSTGRES_USER -c "CREATE EXTENSION IF NOT EXISTS pg_cron;" $POSTGRES_DB
16+
psql -U $POSTGRES_USER -c "GRANT USAGE ON SCHEMA cron TO $POSTGRES_USER;" $POSTGRES_DB
17+

0 commit comments

Comments
 (0)