Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Replace moto server with Minio (#254)
Madison Swain-Bowdena5c2ee98a799
diff --git a/README.md b/README.mdindex e2fe79cca..a9fb4ffcd 100644--- a/README.md+++ b/README.md@@ -169,6 +169,12 @@ and some networking setup so that they can communicate. Note:in the container `openverse_catalog_webserver_1`. On production, only the DAGs folderwill be mounted, e.g. `/usr/local/airflow/openverse_catalog/dags`.+The various services can be accessed using these links:++- Airflow: `localhost:9090` (The default username and password are both `airflow`.)+- Minio Console: `localhost:5001` (The default username and password are `test_key` and `test_secret`)+- Postgres: `localhost:5434` (using a database connector)+At this stage, you can run the tests via:```shell@@ -196,8 +202,6 @@ To follow the logs of the running container:just logs```-To see the Airflow web UI, point your browser to `localhost:9090`. The default user name and password for the airflow UI are both `airflow`.-To begin an interactive [`pgcli` shell](https://www.pgcli.com/) on the database container, run:```shelldiff --git a/docker-compose.override.yml b/docker-compose.override.ymlindex a9a84fa8c..edef313ff 100644--- a/docker-compose.override.yml+++ b/docker-compose.override.yml@@ -14,13 +14,37 @@ services:ports:- "5434:5432"volumes:- - postgres-volume:/var/lib/postgresql/data+ - postgres:/var/lib/postgresql/datas3:- build:- context: docker/local_s3+ image: minio/minio:latestports:- "5000:5000"+ - "5001:5001"+ env_file:+ - .env+ environment:+ MINIO_ROOT_USER: ${AWS_ACCESS_KEY}+ MINIO_ROOT_PASSWORD: ${AWS_SECRET_KEY}+ # Comma separated list of buckets to create on startup+ BUCKETS_TO_CREATE: ${OPENVERSE_BUCKET},openverse-airflow-logs,commonsmapper-v2,commonsmapper+ # Create the buckets on every container startup+ # Note: $0 is included in the exec because "/bin/bash -c" swallows the first+ # argument, so it must be re-added at the beginning of the exec call+ entrypoint: >-+ /bin/bash -c+ "for b in $${BUCKETS_TO_CREATE//,/ }; do+ echo \"Making bucket $$b\" && mkdir -p /data/$$b;+ done &&+ exec $$0 \"$$@\""+ command: minio server /data --address :5000 --console-address :5001+ volumes:+ - minio:/data+ healthcheck:+ test: ["CMD", "curl", "-f", "http://localhost:5000/minio/health/live"]+ interval: 30s+ timeout: 20s+ retries: 3# Dev changes for the webserver containerwebserver:@@ -33,8 +57,9 @@ services:# Volume override to include *all* of openverse_catalog, not just the DAGs folder# Note, this overrides the whole block, so existing volumes must be duplicatedvolumes:- - airflow-volume:/var/workflow_output+ - airflow:/var/workflow_output- ./openverse_catalog:/usr/local/airflow/openverse_catalogvolumes:- postgres-volume:+ postgres:+ minio:diff --git a/docker-compose.yml b/docker-compose.ymlindex 74af7c2c2..7e094d058 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -11,8 +11,8 @@ services:ports:- "${AIRFLOW_PORT}:8080"volumes:- - airflow-volume:/var/workflow_output+ - airflow:/var/workflow_output- ./openverse_catalog/dags:/usr/local/airflow/openverse_catalog/dagsvolumes:- airflow-volume:+ airflow:diff --git a/docker/airflow/Dockerfile b/docker/airflow/Dockerfileindex 754eabfd5..b6981f6c8 100644--- a/docker/airflow/Dockerfile+++ b/docker/airflow/Dockerfile@@ -20,9 +20,10 @@ ENV OUTPUT_DIR=/var/workflow_output/ENV AIRFLOW__CORE__DAGS_FOLDER=${AIRFLOW_HOME}/openverse_catalog/dagsENV AIRFLOW__CORE__LOAD_EXAMPLES=FalseENV AIRFLOW__CORE__LOAD_DEFAULT_CONNECTIONS=False+# TODO: Test if moving this to .env changes anything!ENV AIRFLOW__LOGGING__REMOTE_LOGGING=TrueENV AIRFLOW__LOGGING__REMOTE_LOG_CONN_ID=aws_default-ENV AIRFLOW__LOGGING__REMOTE_BASE_LOG_FOLDER=s3://openverse-airflow-logs/logs+ENV AIRFLOW__LOGGING__REMOTE_BASE_LOG_FOLDER=s3://openverse-airflow-logsRUN apt-get update && apt-get -yqq upgrade && apt-get -yqq install \diff --git a/docker/local_s3/Dockerfile b/docker/local_s3/Dockerfiledeleted file mode 100644index 37531c691..000000000--- a/docker/local_s3/Dockerfile+++ /dev/null@@ -1,10 +0,0 @@-FROM python:3.9--ARG OPENVERSE_BUCKET-ENV SCRIPT_DIR=/app--WORKDIR ${SCRIPT_DIR}-ADD create_bucket.py ${SCRIPT_DIR}-RUN pip install moto[server]--CMD python create_bucket.py & moto_server s3 -H 0.0.0.0diff --git a/docker/local_s3/create_bucket.py b/docker/local_s3/create_bucket.pydeleted file mode 100644index c7f5d3def..000000000--- a/docker/local_s3/create_bucket.py+++ /dev/null@@ -1,72 +0,0 @@-import logging-import sys-import time--import boto3-from botocore.httpsession import EndpointConnectionError---logging.basicConfig(- format="%(asctime)s - %(name)s - %(levelname)s: %(message)s",- level=logging.INFO,-)--logger = logging.getLogger(__file__)--TRIES = 10-S3 = boto3.resource(- service_name="s3",- region_name="us-east-1",- endpoint_url="http://localhost:5000",- aws_access_key_id="test_key",- aws_secret_access_key="test_secret",-)-BUCKET_LIST = [- "openverse-airflow-logs",- "openverse-storage",- "commonsmapper-v2",- "commonsmapper",-]---def main():- success = _create_local_s3_buckets()- if not success:- logger.error("Could not create bucket in local S3")- sys.exit(1)- else:- sys.exit(0)---def _create_local_s3_buckets(bucket_list=None):- if bucket_list is None:- bucket_list = BUCKET_LIST.copy()- success = True- for bucket in bucket_list:- success = min(success, _create_local_s3_bucket(bucket_name=bucket))- return success---def _create_local_s3_bucket(tries=TRIES, s3=S3, bucket_name=BUCKET_LIST[0]):- success = False- for i in range(1, tries + 1):- try:- logger.info(- f"Attempting to create bucket {bucket_name}"- " using local s3 connection"- )- s3.create_bucket(Bucket=bucket_name)- success = True- break- except EndpointConnectionError as conn_e:- logger.info("S3 not yet available")- logger.debug(f"Error was: {conn_e}")- logger.info(f"Waiting {i} seconds...")- # Back off with each loop to give the S3 container a chance to- # start.- time.sleep(i)- return success---if __name__ == "__main__":- main()diff --git a/env.template b/env.templateindex 89bfaae0e..2ecdb9740 100644--- a/env.template+++ b/env.template@@ -47,11 +47,7 @@ OPENLEDGER_CONN_ID=postgres_openledger_upstreamTEST_CONN_ID=postgres_openledger_testingS3_LOCAL_ENDPOINT=http://s3:5000-AIRFLOW_CONN_AWS_PROD=aws://test_key:test_secret@?region_name=us-east-1&host=http://s3:5000-AIRFLOW_CONN_AWS_TEST=aws://test_key:test_secret@?region_name=us-east-1&host=http://s3:5000--AWS_CONN_ID=aws_prod-AWS_TEST_CONN_ID=aws_test+AWS_CONN_ID=aws_defaultAIRFLOW_CONN_EMR_EMPTY=emr://AIRFLOW_CONN_EMR_TEST=emr://?host=http://s3:5000@@ -75,10 +71,7 @@ OUTPUT_DIR=/tmp/# AWS/S3 configuration - does not need to be changed for developmentAWS_ACCESS_KEY=test_keyAWS_SECRET_KEY=test_secret-TEST_ACCESS_KEY=test_key-TEST_SECRET_KEY=test_secret# General bucket used for TSV->DB ingestion and logging-# TODO: Might need a separate bucket for loggingOPENVERSE_BUCKET=openverse-storage# Used only for commoncrawl parsingS3_BUCKET=not_setdiff --git a/tests/dags/util/loader/test_s3.py b/tests/dags/util/loader/test_s3.pyindex 76a6d7ac5..820aa4503 100644--- a/tests/dags/util/loader/test_s3.py+++ b/tests/dags/util/loader/test_s3.py@@ -11,11 +11,11 @@ from util.loader import s3TEST_ID = "testing"TEST_MEDIA_PREFIX = "media"TEST_STAGING_PREFIX = "test_staging"-AWS_CONN_ID = os.getenv("AWS_TEST_CONN_ID")+AWS_CONN_ID = os.getenv("AWS_CONN_ID")S3_LOCAL_ENDPOINT = os.getenv("S3_LOCAL_ENDPOINT")S3_TEST_BUCKET = f"cccatalog-storage-{TEST_ID}"-ACCESS_KEY = os.getenv("TEST_ACCESS_KEY")-SECRET_KEY = os.getenv("TEST_SECRET_KEY")+ACCESS_KEY = os.getenv("AWS_ACCESS_KEY")+SECRET_KEY = os.getenv("AWS_SECRET_KEY")S3_HOST = socket.gethostbyname(urlparse(S3_LOCAL_ENDPOINT).hostname)diff --git a/tests/dags/util/loader/test_sql.py b/tests/dags/util/loader/test_sql.pyindex e04f54387..c35b176d4 100644--- a/tests/dags/util/loader/test_sql.py+++ b/tests/dags/util/loader/test_sql.py@@ -27,8 +27,8 @@ TEST_LOAD_TABLE = f"provider_data_image_{TEST_ID}"TEST_IMAGE_TABLE = f"image_{TEST_ID}"S3_LOCAL_ENDPOINT = os.getenv("S3_LOCAL_ENDPOINT")S3_TEST_BUCKET = f"cccatalog-storage-{TEST_ID}"-ACCESS_KEY = os.getenv("TEST_ACCESS_KEY")-SECRET_KEY = os.getenv("TEST_SECRET_KEY")+ACCESS_KEY = os.getenv("AWS_ACCESS_KEY")+SECRET_KEY = os.getenv("AWS_SECRET_KEY")S3_HOST = socket.gethostbyname(urlparse(S3_LOCAL_ENDPOINT).hostname)RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)), "test_resources")