From ec3f5a5590fa1bbd1cff4f6e181c5914e4fb46e1 Mon Sep 17 00:00:00 2001 From: Arthur Le Bars <arthur.le-bars@sb-roscoff.fr> Date: Tue, 20 Apr 2021 16:53:12 +0200 Subject: [PATCH] galaxy_nginx.conf jinja2 template writing, moved configuration files from 'templates' to 'files' for clarity --- .../authelia_users_template.yml | 0 .../nginx_apollo_template.conf | 0 .../nginx_download_template.conf | 0 gga_init.py | 34 +++++-------------- templates/galaxy_nginx.conf.j2 | 19 +++++++++++ 5 files changed, 28 insertions(+), 25 deletions(-) rename {templates => files}/authelia_users_template.yml (100%) rename templates/nginx_apollo.conf => files/nginx_apollo_template.conf (100%) rename templates/nginx_download.conf => files/nginx_download_template.conf (100%) create mode 100644 templates/galaxy_nginx.conf.j2 diff --git a/templates/authelia_users_template.yml b/files/authelia_users_template.yml similarity index 100% rename from templates/authelia_users_template.yml rename to files/authelia_users_template.yml diff --git a/templates/nginx_apollo.conf b/files/nginx_apollo_template.conf similarity index 100% rename from templates/nginx_apollo.conf rename to files/nginx_apollo_template.conf diff --git a/templates/nginx_download.conf b/files/nginx_download_template.conf similarity index 100% rename from templates/nginx_download.conf rename to files/nginx_download_template.conf diff --git a/gga_init.py b/gga_init.py index 86e4c11..dbe4745 100755 --- a/gga_init.py +++ b/gga_init.py @@ -76,30 +76,6 @@ class DeploySpeciesStack(speciesData.SpeciesData): logging.debug("Using default banner for Tripal pages") self.config.pop("banner_path", None) - - # Write galaxy_nginx.conf - try: - with open(os.path.abspath(os.path.join(self.main_dir, "galaxy_nginx.conf")), "w") as galaxy_nginx_conf: - galaxy_nginx_conf.truncate(0) - galaxy_nginx_conf.write("uwsgi_param QUERY_STRING $query_string;") - galaxy_nginx_conf.write("uwsgi_param REQUEST_METHOD $request_method;") - galaxy_nginx_conf.write("uwsgi_param CONTENT_TYPE $content_type;") - galaxy_nginx_conf.write("uwsgi_param CONTENT_LENGTH $content_length;") - galaxy_nginx_conf.write("uwsgi_param REQUEST_URI $request_uri;") - galaxy_nginx_conf.write("uwsgi_param PATH_INFO $document_uri;") - galaxy_nginx_conf.write("uwsgi_param DOCUMENT_ROOT $document_root;") - galaxy_nginx_conf.write("uwsgi_param SERVER_PROTOCOL $server_protocol;") - galaxy_nginx_conf.write("uwsgi_param REQUEST_SCHEME $scheme;") - galaxy_nginx_conf.write("uwsgi_param HTTPS $https if_not_empty;") - galaxy_nginx_conf.write("uwsgi_param REMOTE_ADDR $remote_addr;") - galaxy_nginx_conf.write("uwsgi_param REMOTE_PORT $remote_port;") - galaxy_nginx_conf.write("uwsgi_param SERVER_PORT $server_port;") - galaxy_nginx_conf.write("uwsgi_param SERVER_NAME $server_name;") - galaxy_nginx_conf.write("uwsgi_param HTTP_REMOTE_USER gga;") - except OSError as exc: - logging.critical("Cannot write galaxy NginX conf file (%s)" % os.path.abspath(self.script_dir)) - sys.exit(exc) - # Create nginx dirs and write/re-write nginx conf make_dirs(dir_paths_li=["./nginx", "./nginx/conf"]) try: @@ -151,6 +127,14 @@ class DeploySpeciesStack(speciesData.SpeciesData): gspecies_compose_file.truncate(0) gspecies_compose_file.write(gspecies_compose_output) + + galaxy_nginx_conf_template = env.get_template("galaxy_nginx_conf.j2") + galaxy_nginx_conf_output = galaxy_nginx_conf_template.render(render_vars) + with open(os.path.join(self.main_dir, "galaxy_nginx.conf"), "w") as galaxy_nginx_conf_file: + logging.debug("Writing the galaxy_nginx.conf file for %s" % self.genus_species) + galaxy_nginx_conf_file.truncate(0) + galaxy_nginx_conf_file.write(galaxy_nginx_conf_output) + # Create the volumes (directory) of the species docker-compose file create_mounts(working_dir=".", main_dir=self.main_dir) @@ -248,7 +232,7 @@ def make_traefik_compose_files(config, main_dir): sys.exit() # Path to the authelia users in the repo - authelia_users_path = script_dir + "/templates/authelia_users_template.yml" + authelia_users_path = script_dir + "/files/authelia_users_template.yml" # Copy authelia "users" file if not os.path.isfile("./traefik/authelia/users.yml"): shutil.copy(authelia_users_path, "./traefik/authelia/users.yml") diff --git a/templates/galaxy_nginx.conf.j2 b/templates/galaxy_nginx.conf.j2 new file mode 100644 index 0000000..5d05b1f --- /dev/null +++ b/templates/galaxy_nginx.conf.j2 @@ -0,0 +1,19 @@ +#jinja2: lstrip_blocks: “Trueâ€, trim_blocks: "True" +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; + +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param REQUEST_SCHEME $scheme; +uwsgi_param HTTPS $https if_not_empty; + +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name; + +uwsgi_param HTTP_REMOTE_USER {% if https_port is defined %}$http_remote_user if_not_empty;{% elif galaxy_defaut_admin_user is defined %}{{ galaxy_defaut_admin_user }};{% else %}$http_remote_user if_not_empty;{% endif %} -- GitLab