diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index de20631c..0fcd1558 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -24,9 +24,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Create .secret file - run: | - echo "${{ secrets.PORTAL_USERDB_SECRET }}" > server/.secret + - name: Run Tests run: | python3.9 manage.py test diff --git a/Dockerfile b/Dockerfile index cb994a0c..5574addf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,6 @@ LABEL org.opencontainers.image.source=https://github.com/octocat/my-repo LABEL org.opencontainers.image.description="My container image" LABEL org.opencontainers.image.licenses=MIT -# Note that this is just for debug / test purposes; should not be set via the setup for production -# ENV DJANGO_SUPERUSER_PASSWORD="BioCompute123" -# ENV DJANGO_SUPERUSER_USERNAME="BioComputeSuperUser" -# ENV DJANGO_SUPERUSER_EMAIL="BioComputeSuperUser@gwu.edu" RUN apt-get -qq update && apt-get install -y python3.9 python3-dev python3-pip @@ -17,18 +13,15 @@ RUN python3 -m pip install --upgrade pip WORKDIR /biocompute_api -COPY requirements.txt . - +COPY requirements.txt /biocompute_api/ RUN python3 -m pip install -r requirements.txt -COPY . ./ - -WORKDIR /biocompute_api/ +COPY . /biocompute_api/ -# RUN python3 manage.py migrate -# RUN python3 manage.py createsuperuser --no-input +WORKDIR /biocompute_api EXPOSE 8000 -#CMD ["bash"] -ENTRYPOINT ["python3", "manage.py", "runserver"] -CMD ["0.0.0.0:8000"] \ No newline at end of file + +ENTRYPOINT ["./entrypoint.sh"] + +CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/biocompute/apis.py b/biocompute/apis.py index 8b66fc21..58f93f74 100644 --- a/biocompute/apis.py +++ b/biocompute/apis.py @@ -244,7 +244,6 @@ def post(self, request) -> Response: data=bco_results ) - import pdb; pdb.set_trace() return Response(status=status.HTTP_200_OK, data=response_data) # for index, object in enumerate(data): @@ -307,7 +306,6 @@ def post(self, request) -> Response: # continue # bco_results = validator.parse_and_validate(bco_instance.contents) - # import pdb; pdb.set_trace() # identifier, results = bco_results.popitem() # if results["number_of_errors"] > 0: @@ -499,7 +497,7 @@ def post(self, request) -> Response: message=message, data=results )) - + status_code = response_status(accepted_requests, rejected_requests) return Response(status=status_code, data=response_data) diff --git a/biocompute/models.py b/biocompute/models.py index 274b81be..bc2a7014 100644 --- a/biocompute/models.py +++ b/biocompute/models.py @@ -19,7 +19,7 @@ ] class Bco(models.Model): - """BioComput Object Model. + """BioCompute Object Model. Attributes: ----------- diff --git a/biocompute/services.py b/biocompute/services.py index 95cb4159..01192e75 100644 --- a/biocompute/services.py +++ b/biocompute/services.py @@ -50,12 +50,25 @@ def load_schema(schema_uri): Returns: - dict: The loaded JSON schema. """ + schema_mapping = { + "https://w3id.org/ieee/ieee-2791-schema/2791object.json": f"{BASE_DIR}/config/schemas/2791/2791object.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.1.0/dataset/dataset_extension.json": f"{BASE_DIR}/config/schemas/1.1.0/dataset_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.1.0/fhir/fhir_extension.json": f"{BASE_DIR}/config/schemas/1.1.0/fhir_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.1.0/galaxy/galaxy_extension.json": f"{BASE_DIR}/config/schemas/1.1.0/galaxy_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.1.0/license/license_extension.json": f"{BASE_DIR}/config/schemas/1.1.0/license_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.1.0/scm/scm_extension.json": f"{BASE_DIR}/config/schemas/1.1.0/scm_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.2.0/dataset/dataset_extension.json": f"{BASE_DIR}/config/schemas/1.2.0/dataset_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.2.0/fhir/fhir_extension.json": f"{BASE_DIR}/config/schemas/1.2.0/fhir_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.2.0/galaxy/galaxy_extension.json": f"{BASE_DIR}/config/schemas/1.2.0/galaxy_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.2.0/license/license_extension.json": f"{BASE_DIR}/config/schemas/1.2.0/license_extension.json", + "https://raw.githubusercontent.com/biocompute-objects/extension_domain/1.2.0/scm/scm_extension.json": f"{BASE_DIR}/config/schemas/1.2.0/scm_extension.json" + } - if schema_uri == \ - "https://w3id.org/ieee/ieee-2791-schema/2791object.json": - return jsonref.load_uri( - f"file://{BASE_DIR}/config/IEEE/2791object.json" - ) + if schema_uri in schema_mapping: + print(schema_uri in schema_mapping, schema_uri) + return jsonref.load_uri(f"file://{schema_mapping[schema_uri]}") + else: + print(schema_uri in schema_mapping, schema_uri) try: return jsonref.load_uri(schema_uri) except (JSONDecodeError, TypeError, RequestsConnectionError) as e: diff --git a/config/schemas/1.1.0/dataset_extension.json b/config/schemas/1.1.0/dataset_extension.json new file mode 100644 index 00000000..00ad6677 --- /dev/null +++ b/config/schemas/1.1.0/dataset_extension.json @@ -0,0 +1,86 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/dataset/dataset_extension.json", + "title": "dataset_extension", + "type": "object", + "description": "The external references extension to list additional licenses and dataset catagories for a dataset BCO (dsBCO).", + "required": ["dataset_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "dataset_extension": { + "type": "object", + "additionalProperties": false, + "required": ["dataset_categories"], + "properties": { + "additional_license": { + "type": "object", + "description": "The additional license property contains the details about the licenses applied to the dataset and the script or tool/software used to process the given dataset.", + "additionalProperties": false, + "properties": { + "data_license": { + "title": "data_license", + "type": "string", + "description": "The license applied to the data or the dataset by the author", + "examples": [ + "https://creativecommons.org/licenses/by/4.0/" + ] + }, + "script_license": { + "title": "script_license", + "type": "string", + "description": "The license applied to the computational script or the tool/software developed to process (parse, QC, align) the input dataset for a final output dataset.", + "examples": [ + "https://www.gnu.org/licenses/gpl-3.0.en.html" + ] + } + } + }, + "dataset_categories": { + "title": "dataset_categories", + "type": "array", + "description": "Dataset categories describe and provide more information about the dataset which can be used to classify, group, sort and filter datasets.", + "items": { + "required": [ + "category_value", + "category_name" + ], + "additionalProperties": false, + "properties": { + "category_value": { + "type": "string", + "title": "category_value", + "description": "An explanation about the purpose of this instance.", + "examples": [ + "Homo sapiens" + ] + }, + "category_name": { + "type": "string", + "title": "category_name", + "description": "An explanation about the purpose of this instance.", + "enum": [ + "species", + "molecule", + "tag", + "file_type", + "status", + "scope" + ] + } + } + } + } + } + }, + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + + } + } +} diff --git a/config/schemas/1.1.0/fhir_extension.json b/config/schemas/1.1.0/fhir_extension.json new file mode 100644 index 00000000..383169ed --- /dev/null +++ b/config/schemas/1.1.0/fhir_extension.json @@ -0,0 +1,67 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://w3id.org/biocompute/extension_domain/1.1.0/fhir/fhir_extension.json", + "title": "fhir_extension", + "type": "object", + "description": "The external references extension to FHIR resource", + "required": ["fhir_extension", "extension_schema"], + "additionalProperties": false, + "properties":{ + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + + }, + "fhir_extension":{ + "title": "", + "type": "array", + "decription": "", + "items": { + "required": [ + "fhir_endpoint", + "fhir_version", + "fhir_resources" + ], + "properties": { + "fhir_endpoint": { + "type": "string", + "description": "Base URI of FHIR server where the resources are stored", + "examples": [ + "http://fhirtest.uhn.ca/baseDstu3" + ], + "format": "uri" + }, + "fhir_version": { + "type": "string", + "description": "FHIR version of the server endpoint" + }, + "fhir_resources": { + "type": "array", + "items": { + "type": "object", + "required": [ + "fhir_resource", + "fhir_id" + ], + "properties": { + "fhir_resource": { + "type": "string", + "description": "Type of FHIR resource used" + }, + "fhir_id": { + "type": "string", + "description": "Server-specific identifier string" + } + } + } + } + } + } + } + } +} diff --git a/config/schemas/1.1.0/galaxy_extension.json b/config/schemas/1.1.0/galaxy_extension.json new file mode 100644 index 00000000..eb59a870 --- /dev/null +++ b/config/schemas/1.1.0/galaxy_extension.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/galaxy/galaxy_extension.json", + "title": "galaxy_extension", + "type": "object", + "description": "The external references **example** extension for a Galaxy BCO.", + "required": ["galaxy_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "extension_schema": { + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + + }, + "galaxy_extension": { + "type": "object", + "required": [ + "galaxy_url", + "galaxy_version" + ], + "properties": { + "galaxy_url": { + "type": "string", + "description": "The base url for the galaxy instance used to create the BioCompute Object.", + "examples": [ + "https://galaxy.aws.biochemistry.gwu.edu/" + ], + "format": "uri" + }, + "galaxy_version": { + "type": "string", + "description": "The specific version of the Galaxy software used to generate the BioCompute Object.", + "examples": [ + "20.01" + ] + } + } + } + } +} diff --git a/config/schemas/1.1.0/license_extension.json b/config/schemas/1.1.0/license_extension.json new file mode 100644 index 00000000..dabe9024 --- /dev/null +++ b/config/schemas/1.1.0/license_extension.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/license/license_extension.json", + "type": "object", + "description": "The extension to add additional licenses.", + "required": ["licence_extension", "extension_schema"], + "additionalProperties": false, + "properties":{ + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + }, + "licence_extension":{ + "required": [ + "data_license", + "scripts_license" + ], + "properties": { + "data_license": { + "type": "string", + "examples": [ + "https://github.com/example/repo1" + ], + "format": "uri" + }, + "scripts_license": { + "type": "string", + "examples": [ + "https://github.com/example/repo1" + ], + "format": "uri" + } + } + } + } +} diff --git a/config/schemas/1.1.0/scm_extension.json b/config/schemas/1.1.0/scm_extension.json new file mode 100644 index 00000000..ed29c550 --- /dev/null +++ b/config/schemas/1.1.0/scm_extension.json @@ -0,0 +1,67 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://w3id.org/biocompute/extension_domain/1.1.0/scm/scm_extension.json", + "title": "scm_extension", + "type": "object", + "description": "The external references extension to a SCM repository", + "required": ["scm_extension", "extension_schema"], + "additionalProperties": false, + "properties":{ + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + + }, + "scm_extension":{ + "required": [ + "scm_repository", + "scm_type", + "scm_commit", + "scm_path" + ], + "properties": { + "scm_repository": { + "type": "string", + "examples": [ + "https://github.com/example/repo1" + ], + "format": "uri" + }, + "scm_type": { + "type": "string", + "enum": [ + "git", + "svn", + "hg", + "other" + ] + }, + "scm_commit": { + "type": "string", + "examples": [ + "c9ffea0b60fa3bcf8e138af7c99ca141a6b8fb21" + ] + }, + "scm_path": { + "type": "string", + "examples": [ + "workflow/hive-viral-mutation-detection.cwl" + ], + "format": "string" + }, + "scm_preview": { + "type": "string", + "examples": [ + "https://github.com/example/repo1/blob/c9ffea0b60fa3bcf8e138af7c99ca141a6b8fb21/workflow/hive-viral-mutation-detection.cwl" + ], + "format": "uri" + } + } + } + } +} diff --git a/config/schemas/1.2.0/dataset_extension.json b/config/schemas/1.2.0/dataset_extension.json new file mode 100644 index 00000000..f71efaa4 --- /dev/null +++ b/config/schemas/1.2.0/dataset_extension.json @@ -0,0 +1,78 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/dataset/dataset_extension.json", + "title": "dataset_extension", + "type": "object", + "description": "The external references extension to list additional licenses and dataset catagories for a dataset BCO (dsBCO).", + "required": ["dataset_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "dataset_extension": { + "type": "object", + "additionalProperties": false, + "required": ["dataset_categories"], + "properties": { + "additional_license": { + "type": "object", + "description": "The additional license property contains the details about the licenses applied to the dataset and the script or tool/software used to process the given dataset.", + "additionalProperties": false, + "properties": { + "data_license": { + "title": "data_license", + "type": "string", + "description": "The license applied to the data or the dataset by the author", + "examples": ["https://creativecommons.org/licenses/by/4.0/"] + }, + "script_license": { + "title": "script_license", + "type": "string", + "description": "The license applied to the computational script or the tool/software developed to process (parse, QC, align) the input dataset for a final output dataset.", + "examples": ["https://www.gnu.org/licenses/gpl-3.0.en.html"] + } + } + }, + "dataset_categories": { + "title": "dataset_categories", + "type": "array", + "description": "Dataset categories describe and provide more information about the dataset which can be used to classify, group, sort and filter datasets.", + "items": { + "required": ["category_value", "category_name"], + "additionalProperties": false, + "properties": { + "category_value": { + "type": "string", + "title": "category_value", + "description": "An explanation about the purpose of this instance.", + "examples": ["Homo sapiens"] + }, + "category_name": { + "type": "string", + "title": "category_name", + "description": "An explanation about the purpose of this instance.", + "enum": [ + "species", + "molecule", + "tag", + "tags", + "priority", + "file_type", + "status", + "scope" + ] + } + } + } + } + } + }, + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + } + } +} diff --git a/config/schemas/1.2.0/fhir_extension.json b/config/schemas/1.2.0/fhir_extension.json new file mode 100644 index 00000000..0eb9da95 --- /dev/null +++ b/config/schemas/1.2.0/fhir_extension.json @@ -0,0 +1,57 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://w3id.org/biocompute/extension_domain/1.1.0/fhir/fhir_extension.json", + "title": "fhir_extension", + "type": "object", + "description": "The external references extension to FHIR resource", + "required": ["fhir_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + }, + "fhir_extension": { + "title": "", + "type": "array", + "decription": "", + "items": { + "required": ["fhir_endpoint", "fhir_version", "fhir_resources"], + "properties": { + "fhir_endpoint": { + "type": "string", + "description": "Base URI of FHIR server where the resources are stored", + "examples": ["http://fhirtest.uhn.ca/baseDstu3"], + "format": "uri" + }, + "fhir_version": { + "type": "string", + "description": "FHIR version of the server endpoint" + }, + "fhir_resources": { + "type": "array", + "items": { + "type": "object", + "required": ["fhir_resource", "fhir_id"], + "properties": { + "fhir_resource": { + "type": "string", + "description": "Type of FHIR resource used" + }, + "fhir_id": { + "type": "string", + "description": "Server-specific identifier string" + } + } + } + } + } + } + } + } +} diff --git a/config/schemas/1.2.0/galaxy_extension.json b/config/schemas/1.2.0/galaxy_extension.json new file mode 100644 index 00000000..7367d546 --- /dev/null +++ b/config/schemas/1.2.0/galaxy_extension.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/galaxy/galaxy_extension.json", + "title": "galaxy_extension", + "type": "object", + "description": "The external references **example** extension for a Galaxy BCO.", + "required": ["galaxy_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "extension_schema": { + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + }, + "galaxy_extension": { + "type": "object", + "required": ["galaxy_url", "galaxy_version"], + "properties": { + "galaxy_url": { + "type": "string", + "description": "The base url for the galaxy instance used to create the BioCompute Object.", + "examples": ["https://galaxy.aws.biochemistry.gwu.edu/"], + "format": "uri" + }, + "galaxy_version": { + "type": "string", + "description": "The specific version of the Galaxy software used to generate the BioCompute Object.", + "examples": ["20.01"] + } + } + } + } +} diff --git a/config/schemas/1.2.0/license_extension.json b/config/schemas/1.2.0/license_extension.json new file mode 100644 index 00000000..118c7585 --- /dev/null +++ b/config/schemas/1.2.0/license_extension.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://www.w3id.org/biocompute/extension_domain/1.1.0/license/license_extension.json", + "type": "object", + "description": "The extension to add additional licenses.", + "required": ["licence_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + }, + "licence_extension": { + "required": ["data_license", "scripts_license"], + "properties": { + "data_license": { + "type": "string", + "examples": ["https://github.com/example/repo1"], + "format": "uri" + }, + "scripts_license": { + "type": "string", + "examples": ["https://github.com/example/repo1"], + "format": "uri" + } + } + } + } +} diff --git a/config/schemas/1.2.0/scm_extension.json b/config/schemas/1.2.0/scm_extension.json new file mode 100644 index 00000000..af0f8c7f --- /dev/null +++ b/config/schemas/1.2.0/scm_extension.json @@ -0,0 +1,50 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://w3id.org/biocompute/extension_domain/1.1.0/scm/scm_extension.json", + "title": "scm_extension", + "type": "object", + "description": "The external references extension to a SCM repository", + "required": ["scm_extension", "extension_schema"], + "additionalProperties": false, + "properties": { + "extension_schema": { + "title": "extension_schema", + "type": "string", + "format": "uri", + "description": "The schema applied to the extension object", + "examples": [ + "http://www.w3id.org/biocompute/extension_domain/example.json" + ] + }, + "scm_extension": { + "required": ["scm_repository", "scm_type", "scm_commit", "scm_path"], + "properties": { + "scm_repository": { + "type": "string", + "examples": ["https://github.com/example/repo1"], + "format": "uri" + }, + "scm_type": { + "type": "string", + "enum": ["git", "svn", "hg", "other"] + }, + "scm_commit": { + "type": "string", + "examples": ["c9ffea0b60fa3bcf8e138af7c99ca141a6b8fb21"] + }, + "scm_path": { + "type": "string", + "examples": ["workflow/hive-viral-mutation-detection.cwl"], + "format": "string" + }, + "scm_preview": { + "type": "string", + "examples": [ + "https://github.com/example/repo1/blob/c9ffea0b60fa3bcf8e138af7c99ca141a6b8fb21/workflow/hive-viral-mutation-detection.cwl" + ], + "format": "uri" + } + } + } + } +} diff --git a/config/IEEE/2791object.json b/config/schemas/2791/2791object.json similarity index 100% rename from config/IEEE/2791object.json rename to config/schemas/2791/2791object.json diff --git a/config/IEEE/description_domain.json b/config/schemas/2791/description_domain.json similarity index 100% rename from config/IEEE/description_domain.json rename to config/schemas/2791/description_domain.json diff --git a/config/IEEE/error_domain.json b/config/schemas/2791/error_domain.json similarity index 100% rename from config/IEEE/error_domain.json rename to config/schemas/2791/error_domain.json diff --git a/config/IEEE/execution_domain.json b/config/schemas/2791/execution_domain.json similarity index 100% rename from config/IEEE/execution_domain.json rename to config/schemas/2791/execution_domain.json diff --git a/config/IEEE/io_domain.json b/config/schemas/2791/io_domain.json similarity index 100% rename from config/IEEE/io_domain.json rename to config/schemas/2791/io_domain.json diff --git a/config/IEEE/parametric_domain.json b/config/schemas/2791/parametric_domain.json similarity index 100% rename from config/IEEE/parametric_domain.json rename to config/schemas/2791/parametric_domain.json diff --git a/config/IEEE/provenance_domain.json b/config/schemas/2791/provenance_domain.json similarity index 100% rename from config/IEEE/provenance_domain.json rename to config/schemas/2791/provenance_domain.json diff --git a/config/IEEE/usability_domain.json b/config/schemas/2791/usability_domain.json similarity index 100% rename from config/IEEE/usability_domain.json rename to config/schemas/2791/usability_domain.json diff --git a/config/settings.py b/config/settings.py index 42adc2f6..52ed91dd 100644 --- a/config/settings.py +++ b/config/settings.py @@ -9,29 +9,35 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # --- SECURITY SETTINGS --- # -# Load the server config file. -secrets = configparser.ConfigParser() -secrets.read(BASE_DIR + "/.secrets") -DEBUG = secrets["SERVER"]["DEBUG"] -VERSION = secrets["SERVER"]["SERVER_VERSION"] -# Set the anonymous user's key. -ANON_KEY = secrets["DJANGO_KEYS"]["ANON_KEY"] -ALLOWED_HOSTS = secrets["SERVER"]["ALLOWED_HOSTS"].split(',') -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = secrets["DJANGO_KEYS"]["SECRET_KEY"] - -# SECURITY WARNING: don't run with debug turned on in production! - -# The publicly accessible hostname. -HOSTNAME = secrets["SERVER"]["HOSTNAME"] -# The human-readable hostname. -HUMAN_READABLE_HOSTNAME = secrets["SERVER"]["HUMAN_READABLE_HOSTNAME"] -# The publicly accessible hostname. -PUBLIC_HOSTNAME = secrets["SERVER"]["PUBLIC_HOSTNAME"] - - -CORS_ORIGIN_ALLOW_ALL = True -CORS_ORIGIN_WHITELIST = ["*"] +# Load the server .secrets file. +try: + secrets = configparser.ConfigParser() + secrets.read(BASE_DIR + "/.secrets") + DEBUG = secrets["SERVER"]["DEBUG"] + SERVER_VERSION = secrets["SERVER"]["SERVER_VERSION"] + ANON_KEY = secrets["DJANGO_KEYS"]["ANON_KEY"] + ALLOWED_HOSTS = secrets["SERVER"]["ALLOWED_HOSTS"].split(',') + SECRET_KEY = secrets["DJANGO_KEYS"]["SECRET_KEY"] + HOSTNAME = secrets["SERVER"]["HOSTNAME"] + DATABASE=secrets["SERVER"]["DATABASE"] + HUMAN_READABLE_HOSTNAME = secrets["SERVER"]["HUMAN_READABLE_HOSTNAME"] + PUBLIC_HOSTNAME = secrets["SERVER"]["PUBLIC_HOSTNAME"] + EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"] + +except KeyError: + SECRET_KEY="^2uql114+yy0d$xv6+lm8*#1=uxs_oa0zw0bvu^fpi4tc9x0i" + ANON_KEY="627626823549f787c3ec763ff687169206626149" + DEBUG=True + ALLOWED_HOSTS="*" + SERVER_VERSION="24.08.08" + HOSTNAME="127.0.0.1:8000" + HUMAN_READABLE_HOSTNAME="Local Test BCODB" + PUBLIC_HOSTNAME="http://127.0.0.1:8000" + SERVER_URL="http://localhost:3000" + DATABASE="db.sqlite3" + EMAIL_BACKEND="django.core.mail.backends.console.EmailBackend" + CORS_ORIGIN_ALLOW_ALL = True + CORS_ORIGIN_WHITELIST = ["*"] # Use the REST framework REST_FRAMEWORK = { @@ -144,7 +150,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": secrets["SERVER"]["DATABASE"], + "NAME": DATABASE, } } @@ -178,7 +184,7 @@ # Make the object naming accessible as a dictionary. # emailing notifications -EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"] +EMAIL_BACKEND = EMAIL_BACKEND EMAIL_HOST = "localhost" EMAIL_PORT = 25 DEFAULT_AUTO_FIELD = "django.db.models.AutoField" diff --git a/config/urls.py b/config/urls.py index fc7add75..cf9b78a9 100755 --- a/config/urls.py +++ b/config/urls.py @@ -11,7 +11,7 @@ from rest_framework import permissions from biocompute.apis import DraftRetrieveApi, PublishedRetrieveApi -VERSION = settings.VERSION +VERSION = settings.SERVER_VERSION ShcemaView = get_schema_view( openapi.Info( diff --git a/docker-compose.yml b/docker-compose.yml index 78ece6f2..5535b497 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,18 @@ -#cat docker-compose.yml - -version: '3.4' services: bco-api: platform: linux/amd64 build: . - image: ghcr.io/biocompute-objects/bco_api:23.07 container_name: bco-api - volumes: - - ./data/db.sqlite3:/biocompute_api/db.sqlite3 - - ./data/server.conf:/biocompute_api/server.conf + # volumes: + # - ./db.sqlite3:/biocompute_api/db.sqlite3 + # - ./.secrets:/biocompute_api/.secrets environment: TZ: 'America/New_York' - ENV DJANGO_SUPERUSER_PASSWORD: "BioCompute123" - ENV DJANGO_SUPERUSER_USERNAME: "BioComputeSuperUser" - ENV DJANGO_SUPERUSER_EMAIL: "BioComputeSuperUser@gwu.edu" + ports: - "8000:8000" - read_only: true + tmpfs: - /tmp restart: unless-stopped diff --git a/docs/deployment/dockerDeployment.md b/docs/deployment/dockerDeployment.md index e69de29b..2440a7ac 100644 --- a/docs/deployment/dockerDeployment.md +++ b/docs/deployment/dockerDeployment.md @@ -0,0 +1,88 @@ +# BCODB Docker Deployment + + +### Requirements +- Python 3: [3.10.6 reccomended](https://www.python.org/downloads/release/python-3106/) +- [PyEnv](https://github.com/pyenv/pyenv) (optional but recommended for Mac/Linux) +- Docker: + - [Docker Desktop for Linux](https://docs.docker.com/desktop/install/linux-install/) + - [Docker Desktop for Mac (macOS)](https://docs.docker.com/desktop/install/mac-install/) + - [Docker Desktop for Windows](https://docs.docker.com/desktop/install/windows-install/) + + +## Clone the repository +``` +git clone https://github.com/biocompute-objects/bco_api +``` + +**Make sure you are on the desired branch (Check for latest branch):** + +``` +git switch [DESIRED BRANCH TAG] +``` + +## Enter the repository +``` +cd bco_api +``` +## Configure the DB settings using the `.secrets` file: + +### OPTION 1: Generate the secrets file + +In the project root copy the `.secrets.example` to `.secrets` + +``` +cp .secrets.example .secrets +``` +#### Generate the DJANGO_KEY +Generate a 32-bytes long PSK key using the `openssl` command or `PowerShell` command. + +##### Mac/Linux: +``` +openssl rand -base64 32 +``` +##### Windows: +``` +[Convert]::ToBase64String((1..32 | ForEach-Object { Get-Random -Minimum 0 -Maximum 256 }) -as [byte[]]) +``` + +Use a text editor to open the `.secrets` file and update the rest of the variables. For details on each of the variables see the [configuration](/docs/config.md) documentation. + +### OPTION 2: Use the `local_deployment.secrets` file +Fromt the project root: +``` +cp admin_only/local_deployment.secrets .secrets +``` + +### Building the BCO API via Docker + +A docker file is provided to allow easy building of the BCO API. This can be done from the root directory (the directory with Dockerfile in it) by running: + +`docker build -t bco_api:latest .` + +This will build a container named `bco_api` with the tag `latest`. + +The build process (via the `entrypoint.sh` script) will check for an existing database in the repository and run migrations. If no database is present one will be created and the test data will be loaded (taken from `config/fixtures/local_data.json`). + +### Running the container via Docker + +The BCO Api container can be run via docker on the command line in Linux/Windows by running: + +`docker run --rm --network host -it bco_api:latest` + +The BCO Api container can be run via docker on the command line in MacOS by running: + +`docker run --rm -p 8000:8000 -it bco_api:latest` + +This will expose the server at `http://127.0.0.1:8000`, whitch is where all of the default settings will expect to find the BCODB. + +#### Overriding the port + +It is possible to override the port 8000 to whatever port is desired. This is done by running the container with 8080 representing the desired port. + +`docker run --rm --network host -it bco_api:latest 0.0.0.0:8080` + + +NOTE: The ip address of 0.0.0.0 is to allow the web serer to properly associate with 127.0.0.1 - if given 127.0.0.1 it will not allow communications outside of the container! + +You can also give it a specific network created with `docker network create` if you wanted to give assigned IP addresses. diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..80cf23a6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# entrypoint.sh + +# Check if the SQLite database file exists and run migrations if it doesn't +if [ ! -f "db.sqlite3" ]; then + echo "Database not found. Running migrations..." + python3 manage.py migrate + python3 manage.py loaddata config/fixtures/local_data.json +else + echo "Database exists. Running migrations." + python3 manage.py migrate +fi + +# Start the Django server +exec "$@"