Skip to content

Commit aa69031

Browse files
authored
feat: Added entrypoint for tools to perform initialization. (#20)
1 parent 0192fe0 commit aa69031

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

Dockerfile.tools

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ FROM senzing/senzingsdk-tools:4.0.0
22

33
USER root
44

5+
# Add the PostgreSQL APT repository.
6+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
7+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
8+
59
# Update packages and install additional dependencies.
610
RUN apt-get update && \
711
apt-get upgrade -y && \
8-
apt-get install --no-install-recommends -y awscli pipx && \
12+
apt-get install --no-install-recommends -y awscli pipx postgresql-client senzingsdk-poc && \
913
apt-get autoremove \
1014
&& apt-get clean
1115

16+
# Copy entrypoint scripts.
17+
COPY docker/entrypoint.sh /entrypoint.sh
18+
COPY docker/entrypoint.d /entrypoint.d
19+
1220
# Add a new user and switch to it.
1321
RUN useradd -m -u 1001 senzing
1422
USER senzing
@@ -17,4 +25,9 @@ USER senzing
1725
ENV PATH="$PATH:/home/senzing/.local/bin"
1826
RUN pipx install awscli-local
1927

28+
# Define volumes necessary to support a read-only root filesystem on ECS
29+
# Fargate.
30+
VOLUME ["/home/senzing", "/var/lib/amazon", "/var/log"]
31+
2032
WORKDIR /home/senzing
33+
ENTRYPOINT ["/entrypoint.sh"]

docker-compose.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
services:
22
db:
3-
image: bitnamisecure/postgresql:latest
3+
image: postgres:17.6
44
environment:
5-
# See https://github.com/bitnami/bitnami-docker-postgresql#configuration
6-
POSTGRESQL_DATABASE: ${POSTGRES_DB:-G2}
7-
POSTGRESQL_PASSWORD: ${POSTGRES_PASSWORD:-senzing}
8-
POSTGRESQL_POSTGRES_PASSWORD: ${POSTGRESQL_POSTGRES_PASSWORD:-postgres}
9-
POSTGRESQL_USERNAME: ${POSTGRES_USERNAME:-senzing}
5+
# See https://hub.docker.com/_/postgres
6+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-senzing}
7+
POSTGRES_USER: ${POSTGRES_USERNAME:-senzing}
108
healthcheck:
119
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USERNAME:-senzing}" ]
1210
interval: 10s
1311
timeout: 5s
1412
retries: 5
1513
ports:
1614
- 5432:5432
17-
user: "${SENZING_UID:-504}:0"
1815
restart: always
1916
volumes:
20-
- postgres:/bitnami/postgresql
17+
- postgres:/var/lib/postgresql/data
2118

2219
init-db:
2320
image: senzing/init-database:latest
@@ -61,6 +58,10 @@ services:
6158
- db
6259
environment:
6360
AWS_ENDPOINT_URL: http://localstack:4566
61+
PGHOST: db
62+
PGUSER: ${POSTGRES_USERNAME:-senzing}
63+
PGPASSWORD: ${POSTGRES_PASSWORD:-senzing}
64+
SENZING_DATASOURCES: PEOPLE CUSTOMERS
6465
SENZING_ENGINE_CONFIGURATION_JSON: >-
6566
{
6667
"PIPELINE": {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Create the database and import the Senzing schema if it doesn't already exist.
4+
if psql -lqt | cut -d \| -f 1 | grep -qw G2; then
5+
echo "Database has already been initialized"
6+
else
7+
echo "Initializing Senzing database"
8+
createdb G2
9+
psql -d G2 -f /opt/senzing/er/resources/schema/szcore-schema-postgresql-create.sql
10+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Create data sources if SENZING_DATASOURCES environment variable is set.
4+
if [[ -n "${SENZING_DATASOURCES}" ]]; then
5+
echo "Creating data sources"
6+
> /home/senzing/data-sources.txt
7+
8+
IFS=" " read -r -a data_sources <<< "$SENZING_DATASOURCES"
9+
for ds in "${data_sources[@]}"; do
10+
echo "addDataSource ${ds}" >> /home/senzing/data-sources.txt
11+
done
12+
13+
echo "save" >> /home/senzing/data-sources.txt
14+
sz_configtool -f /home/senzing/data-sources.txt
15+
rm /home/senzing/data-sources.txt
16+
fi

docker/entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Execute scripts in /entrypoint.d/
4+
for f in /entrypoint.d/*; do
5+
case "$f" in
6+
*.sh) echo "$0: running $f"; . "$f" ;;
7+
*) echo "$0: ignoring $f" ;;
8+
esac
9+
echo
10+
done
11+
12+
# Execute the main command passed to the script.
13+
echo "Running as user: $(whoami)"
14+
echo "Executing command: $@"
15+
exec "$@"

0 commit comments

Comments
 (0)