The following is an example showing how to develop python scripts for Senzing on macOS with the help of a Docker container.
The goal is to allow a user to use their macOS Integrated Development Environment (IDE) on macOS natively, but test the running of the scripts in a Linux Docker container.
-
Identify SENZING_DIR. Example:
export SENZING_DIR=/opt/senzing
-
Identify the directory that holds the python scripts. This can be a new or existing directory. Example:
export MY_DATA_DIR=~/example-senzing-python-project
-
If the directory doesn't exist, create the directory. Example:
mkdir -p ${MY_DATA_DIR}
-
Optional. For testing purposes, a test python script can be created. Example:
cat <<EOT > ${MY_DATA_DIR}/example-python.py #!/usr/bin/env python import os import json import sys debug = False # Establish directories and paths senzing_directory = os.environ.get("SENZING_DIR", "/opt/senzing") senzing_python_directory = "{0}/g2/python".format(senzing_directory) g2module_ini_pathname = "{0}/G2Module.ini".format(senzing_python_directory) # Add python directory to System Path sys.path.append(senzing_python_directory) # Initialize Senzing G2 modules. from G2Product import G2Product g2_product = G2Product() g2_product.init('pyG2Product', g2module_ini_pathname, debug) # Print Senzing version. version_string = g2_product.version() version_dictionary = json.loads(version_string) print(json.dumps(version_dictionary, sort_keys=True, indent=4)) EOT
-
Run the docker container using a SQLite database. Example:
sudo docker run \ --interactive \ --rm \ --tty \ --volume ${SENZING_DIR}:/opt/senzing \ --volume ${MY_DATA_DIR}:/data \ senzing/senzing-base
-
To use other databases, see senzing/docker-senzing-base.
-
The
${MY_DATA_DIR}/example-python.py
script sitting on macOS is accessible inside the running container as/data/example-python.py
. It can be run inside the container. Example:# cd /data # python example-python.py { "BUILD_DATE": "2019-06-04", "BUILD_NUMBER": "2019_06_04__02_00", "COMPATIBILITY_VERSION": { "CONFIG_VERSION": "2" }, "VERSION": "1.9.19155"
- Because the files in the docker container at
/data
are actually on macOS at${MY_DATA_DIR}
, they can be edited on macOS and run inside the Docker container.
-
If additional
apt-get
orpip
installs are needed, create a new Dockerfile using the followingFROM
statement.FROM senzing/senzing-base
or a more recent style:
ARG BASE_IMAGE=senzing/senzing-base FROM ${BASE_IMAGE}
-
An example of this can be found in senzing/docker-senzing-poc-utility. View the
Dockerfile
.