From 5cda22dd480782568165aaaee19b6589385e56a4 Mon Sep 17 00:00:00 2001
From: fmareuil <fmareuil@pasteur.fr>
Date: Tue, 2 Feb 2021 17:51:31 +0100
Subject: [PATCH] fix url resolution filefield for API

---
 .gitlab-ci.yml                         | 6 +++---
 ansible/deploy.yaml                    | 6 ++++++
 ippisite/ippisite/settings.py          | 2 +-
 ippisite/ippisite/settings.template.py | 3 ++-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 67dc84c1..07ffa2ac 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -99,7 +99,7 @@ deploy-webserver-targetcentric:
     - cd ansible
     - whoami
     - ansible-playbook -vvv -i ./hosts_master deploy.yaml 
-      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_targetcentric galaxy_base_url=$GALAXY_BASE_URL_targetcentric galaxy_apikey=$GALAXY_APIKEY_targetcentric galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_targetcentric secret_key=$SECRET_KEY_targetcentric dbname=$DBNAME_targetcentric dbuser=$DBUSER_targetcentric dbpassword=$DBPASSWORD_targetcentric dbhost=$DBHOST_targetcentric dbport=$DBPORT_targetcentric http_port=$HTTP_PORT_targetcentric branch=$CI_COMMIT_REF_NAME gacode=$GACODE_targetcentric"
+      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_targetcentric galaxy_base_url=$GALAXY_BASE_URL_targetcentric galaxy_apikey=$GALAXY_APIKEY_targetcentric galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_targetcentric secret_key=$SECRET_KEY_targetcentric dbname=$DBNAME_targetcentric dbuser=$DBUSER_targetcentric dbpassword=$DBPASSWORD_targetcentric dbhost=$DBHOST_targetcentric dbport=$DBPORT_targetcentric http_port=$HTTP_PORT_targetcentric branch=$CI_COMMIT_REF_NAME gacode=$GACODE_targetcentric ippidb_media=$IPPIDB_MEDIA_targetcentric"
   only:
     - targetcentric
 
@@ -122,7 +122,7 @@ deploy-webserver-test:
     - cd ansible
     - whoami
     - ansible-playbook -vvv -i ./hosts_master deploy.yaml 
-      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_master galaxy_base_url=$GALAXY_BASE_URL_master galaxy_apikey=$GALAXY_APIKEY_master galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_master secret_key=$SECRET_KEY_master dbname=$DBNAME_master dbuser=$DBUSER_master dbpassword=$DBPASSWORD_master dbhost=$DBHOST_master dbport=$DBPORT_master http_port=$HTTP_PORT_master branch=$CI_COMMIT_REF_NAME gacode=$GACODE_master"
+      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_master galaxy_base_url=$GALAXY_BASE_URL_master galaxy_apikey=$GALAXY_APIKEY_master galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_master secret_key=$SECRET_KEY_master dbname=$DBNAME_master dbuser=$DBUSER_master dbpassword=$DBPASSWORD_master dbhost=$DBHOST_master dbport=$DBPORT_master http_port=$HTTP_PORT_master branch=$CI_COMMIT_REF_NAME gacode=$GACODE_master ippidb_media=$IPPIDB_MEDIA_master"
   only:
     - master
 
@@ -145,6 +145,6 @@ deploy-webserver-production:
     - cd ansible
     - whoami
     - ansible-playbook -vvv -i ./hosts_release deploy.yaml 
-      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_release galaxy_base_url=$GALAXY_BASE_URL_release galaxy_apikey=$GALAXY_APIKEY_release galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_release secret_key=$SECRET_KEY_release dbname=$DBNAME_release dbuser=$DBUSER_release dbpassword=$DBPASSWORD_release dbhost=$DBHOST_release dbport=$DBPORT_release http_port=$HTTP_PORT_release branch=$CI_COMMIT_REF_NAME  gacode=$GACODE_release"
+      --extra-vars "deploy_user_name=ippidb repo_api_token=JZS-4cH7bWkFkHa2rAVf marvinjs_apikey=$MARVINJS_APIKEY_release galaxy_base_url=$GALAXY_BASE_URL_release galaxy_apikey=$GALAXY_APIKEY_release galaxy_compoundproperties_workflowid=$GALAXY_COMPOUNDPROPERTIES_WORKFLOWID_release secret_key=$SECRET_KEY_release dbname=$DBNAME_release dbuser=$DBUSER_release dbpassword=$DBPASSWORD_release dbhost=$DBHOST_release dbport=$DBPORT_release http_port=$HTTP_PORT_release branch=$CI_COMMIT_REF_NAME  gacode=$GACODE_release ippidb_media=$IPPIDB_MEDIA_release"
   only:
     - release
diff --git a/ansible/deploy.yaml b/ansible/deploy.yaml
index 3d50d455..75355b76 100644
--- a/ansible/deploy.yaml
+++ b/ansible/deploy.yaml
@@ -231,6 +231,12 @@
           GA_CODE = "{{ gacode }}"
         marker: "# {mark} ANSIBLE MANAGED GOOGLE ANALYTICS ID"
       when: gacode is defined
+    - name: Add media_url setting to iPPI-DB settings
+      blockinfile:
+        path: "{{ checkout_path }}/ippisite/ippisite/{{ ansible_hostname }}_settings.py"
+        block: |
+          MEDIA_URL = "{{ ippidb_media }}"
+        marker: "# {mark} ANSIBLE MEDIA_URL SETTINGS"
     - name: Add email/debug settings to iPPI-DB settings
       blockinfile:
         path: "{{ checkout_path }}/ippisite/ippisite/{{ ansible_hostname }}_settings.py"
diff --git a/ippisite/ippisite/settings.py b/ippisite/ippisite/settings.py
index 30f909d8..eba17e7a 100644
--- a/ippisite/ippisite/settings.py
+++ b/ippisite/ippisite/settings.py
@@ -178,7 +178,7 @@ LOGIN_REDIRECT_URL = "/"
 LOGOUT_REDIRECT_URL = "/"
 
 MEDIA_URL = "/media/"
-MEDIA_ROOT = BASE_DIR + MEDIA_URL
+MEDIA_ROOT = BASE_DIR + "/media/"
 
 ################################################################################
 # fingerprints used to compute Drugbank similarity using openbabel
diff --git a/ippisite/ippisite/settings.template.py b/ippisite/ippisite/settings.template.py
index c4f1b3c9..bf31edfc 100644
--- a/ippisite/ippisite/settings.template.py
+++ b/ippisite/ippisite/settings.template.py
@@ -165,8 +165,9 @@ LOGIN_REDIRECT_URL = "/"
 
 LOGOUT_REDIRECT_URL = "/"
 
+# WARNING MEDIA_URL is surcharged by CI during deployment with ci variable IPPIDB_ROOT
 MEDIA_URL = "/media/"
-MEDIA_ROOT = BASE_DIR + MEDIA_URL
+MEDIA_ROOT = BASE_DIR + "/media/"
 
 ################################################################################
 # fingerprints used to compute Drugbank similarity using openbabel
-- 
GitLab