import docker data to netdisco repo
This commit is contained in:
29
docker/netdisco-postgresql/Dockerfile
Normal file
29
docker/netdisco-postgresql/Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# vim: ft=Dockerfile
|
||||
FROM docker.io/postgres:9.6.6-alpine
|
||||
|
||||
ARG TAG
|
||||
ENV TAG ${TAG:-master}
|
||||
|
||||
RUN apk add --no-cache \
|
||||
curl \
|
||||
jq \
|
||||
tar
|
||||
|
||||
WORKDIR /var/lib/postgresql/netdisco-sql
|
||||
RUN curl -sL "https://api.github.com/repos/netdisco/netdisco/tarball/${TAG}" | \
|
||||
tar --wildcards -zt '*App-Netdisco-DB-*' | xargs -n1 basename | sort -n -t '-' -k4 | \
|
||||
while read file; \
|
||||
do curl -sLO "https://raw.githubusercontent.com/netdisco/netdisco/${TAG}/share/schema_versions/$file"; \
|
||||
done && \
|
||||
curl -sLO "https://raw.githubusercontent.com/netdisco/upstream-sources/master/ieee/oui.sql" && \
|
||||
curl -sLO "https://raw.githubusercontent.com/netdisco/netdisco/master/lib/App/Netdisco/DB.pm"
|
||||
|
||||
RUN PGDATA=/var/lib/postgresql/netdisco-pgdata /usr/local/bin/docker-entrypoint.sh postgres --version
|
||||
|
||||
COPY netdisco-db-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/netdisco-db-entrypoint.sh
|
||||
|
||||
WORKDIR /
|
||||
VOLUME /var/lib/postgresql/data
|
||||
ENTRYPOINT ["/usr/local/bin/netdisco-db-entrypoint.sh"]
|
||||
CMD ["postgres"]
|
||||
2
docker/netdisco-postgresql/hooks/build
Executable file
2
docker/netdisco-postgresql/hooks/build
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
docker build --build-arg TAG=$SOURCE_BRANCH -t $IMAGE_NAME .
|
||||
47
docker/netdisco-postgresql/netdisco-db-entrypoint.sh
Normal file
47
docker/netdisco-postgresql/netdisco-db-entrypoint.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
su=( su-exec "${PGUSER:-postgres}" )
|
||||
psql=( psql -X -v ON_ERROR_STOP=0 -v ON_ERROR_ROLLBACK=on )
|
||||
psql+=( --username netdisco --dbname netdisco )
|
||||
|
||||
if [ "$1" = 'postgres' ]; then
|
||||
if [ ! -s "$PGDATA/PG_VERSION" ]; then
|
||||
echo >&2 "netdisco-db-entrypoint: copying initial database files"
|
||||
chmod 700 /var/lib/postgresql/data
|
||||
chown postgres /var/lib/postgresql/data
|
||||
cp -a /var/lib/postgresql/netdisco-pgdata/* /var/lib/postgresql/data/
|
||||
fi
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: starting pg privately to container"
|
||||
"${su[@]}" pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w start
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: configuring Netdisco db user"
|
||||
echo "*:*:netdisco:netdisco:netdisco" > ~/.pgpass
|
||||
chmod 0600 ~/.pgpass
|
||||
"${su[@]}" createuser -DRSw netdisco
|
||||
"${su[@]}" createdb -O netdisco netdisco
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: bringing schema up-to-date"
|
||||
ls -1 /var/lib/postgresql/netdisco-sql/App-Netdisco-DB-* | \
|
||||
xargs -n1 basename | sort -n -t '-' -k4 | \
|
||||
while read file; do
|
||||
"${psql[@]}" -f "/var/lib/postgresql/netdisco-sql/$file"
|
||||
done
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: importing OUI"
|
||||
NUMOUI=$("${psql[@]}" -A -t -c "SELECT count(oui) FROM oui")
|
||||
if [ "$NUMOUI" -eq 0 ]; then
|
||||
"${psql[@]}" -f /var/lib/postgresql/netdisco-sql/oui.sql
|
||||
fi
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: marking schema as up-to-date"
|
||||
MAXSCHEMA=$(grep VERSION /var/lib/postgresql/netdisco-sql/DB.pm | sed 's/[^0-9]//g')
|
||||
STAMP=$(date '+v%Y%m%d_%H%M%S.000')
|
||||
"${psql[@]}" -c "CREATE TABLE dbix_class_schema_versions (version varchar(10) PRIMARY KEY, installed varchar(20) NOT NULL)"
|
||||
"${psql[@]}" -c "INSERT INTO dbix_class_schema_versions VALUES ('${MAXSCHEMA}', '${STAMP}')"
|
||||
|
||||
echo >&2 "netdisco-db-entrypoint: shutting down pg (will restart listening for clients)"
|
||||
"${su[@]}" pg_ctl -D "$PGDATA" -m fast -w stop
|
||||
fi
|
||||
|
||||
exec /usr/local/bin/docker-entrypoint.sh "$@"
|
||||
Reference in New Issue
Block a user