Containerised Flask app not working as expected












2















I have created sample flask application in which end user will upload jar file (contains bunch of XML files) using HTML form. Once user submits the form, in backend, I am reading the jar file content without saving it any target location by using Flask's FileStorage API and zipfile. And iterating over each xml files and performing some custom action and returning the data back to the user as a result.



I have the created a docker container for this application, but now application is not working as expected as shown in below image:



Results From not not containerized app:
Results From not not containerized app



Results from Container App:
Results from Container App



In both the results, I can see the uploaded file name i.e "SampleJar", but the number of xml files(flows) count is 0 in containerized app.



Below is the code used for this app:



app.py



from flask import Flask, render_template, jsonify, request
...
...
@APP.route("/parse", methods = ['POST'])
def parse():
"""
Parse the Uploaded jar file
"""
form = get_request_data(request)
proj_parser = ProjectParser(form)
json_result = proj_parser.process_project()

context = {}

context['title'] = proj_parser.project_name
context['flows_count'] = len(json_result)
context['flows'] = json_result
context['sys_props'] = proj_parser.sys_props_list
context['sys_accts'] = proj_parser.sys_accts_list

return render_template('report.html', context=context)

def get_request_data(request):
"""
Get the data from the request post
"""
jar_file = request.files['project_file']
steps_to_ignore = request.form.get('steps_to_ignore')
vars_to_ignore = request.form.get('vars_to_ignore')

if steps_to_ignore:
steps_to_ignore = steps_to_ignore.replace('r', '').strip().split('n')
else:
steps_to_ignore =

if vars_to_ignore:
vars_to_ignore = vars_to_ignore.replace('r', '').strip().split('n')
else:
vars_to_ignore =

return {
'jar_file': jar_file,
'steps_to_ignore': steps_to_ignore,
'only_errors': request.form.get("only_errors"),
'ignore_scriptlets_in_filters': request.form.get('ignore_scriptlets_in_filters'),
'ignore_flow_output_vars_in_steps': request.form.get("ignore_flow_output_vars_in_steps"),
'vars_to_ignore' : vars_to_ignore,
}


project_parser.py



import os
from xml.etree import ElementTree
import zipfile
from pprint import pprint

from flow_parser import(
FlowParser
)

class ProjectParser():

def __init__(self, form):
self.zf_ref = zipfile.ZipFile(form['jar_file'])
self.form = form
self.sys_props_usage_list =
self.project_name = form['jar_file'].filename.split('-')[0]
self.set_flws_and_cfgs()

def set_flws_and_cfgs(self):
self.flows =
self.sys_props =
self.sys_accts =
self.file_size = self.zf_ref.infolist()
for file_ref in self.zf_ref.infolist():
if file_ref.filename.endswith('.xml'):
if file_ref.filename.startswith('Content/Library/'):
self.flows.append(file_ref)
elif file_ref.filename.startswith('Content/Configuration/'):
if 'System Properties' in file_ref.filename:
self.sys_props.append(file_ref)
elif 'System Accounts' in file_ref.filename:
self.sys_accts.append(file_ref)

def parse_flows(self, flow_ref):
flow_parser = FlowParser(self.zf_ref, flow_ref, self.form)

sys_props_info = {
"flow_name" : flow_parser.name,
"sys_props" : flow_parser.sys_props
}

self.sys_props_usage_list.append(sys_props_info)

return flow_parser.json()

def process_project(self):

results =
for flow in self.flows:
results.append(self.parse_flows(flow))

return results


Dockerfile:



# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Run app.py when the container launches
CMD ["gunicorn", "--workers=2", "--bind=0.0.0.0:80", "app:APP"]









share|improve this question





























    2















    I have created sample flask application in which end user will upload jar file (contains bunch of XML files) using HTML form. Once user submits the form, in backend, I am reading the jar file content without saving it any target location by using Flask's FileStorage API and zipfile. And iterating over each xml files and performing some custom action and returning the data back to the user as a result.



    I have the created a docker container for this application, but now application is not working as expected as shown in below image:



    Results From not not containerized app:
    Results From not not containerized app



    Results from Container App:
    Results from Container App



    In both the results, I can see the uploaded file name i.e "SampleJar", but the number of xml files(flows) count is 0 in containerized app.



    Below is the code used for this app:



    app.py



    from flask import Flask, render_template, jsonify, request
    ...
    ...
    @APP.route("/parse", methods = ['POST'])
    def parse():
    """
    Parse the Uploaded jar file
    """
    form = get_request_data(request)
    proj_parser = ProjectParser(form)
    json_result = proj_parser.process_project()

    context = {}

    context['title'] = proj_parser.project_name
    context['flows_count'] = len(json_result)
    context['flows'] = json_result
    context['sys_props'] = proj_parser.sys_props_list
    context['sys_accts'] = proj_parser.sys_accts_list

    return render_template('report.html', context=context)

    def get_request_data(request):
    """
    Get the data from the request post
    """
    jar_file = request.files['project_file']
    steps_to_ignore = request.form.get('steps_to_ignore')
    vars_to_ignore = request.form.get('vars_to_ignore')

    if steps_to_ignore:
    steps_to_ignore = steps_to_ignore.replace('r', '').strip().split('n')
    else:
    steps_to_ignore =

    if vars_to_ignore:
    vars_to_ignore = vars_to_ignore.replace('r', '').strip().split('n')
    else:
    vars_to_ignore =

    return {
    'jar_file': jar_file,
    'steps_to_ignore': steps_to_ignore,
    'only_errors': request.form.get("only_errors"),
    'ignore_scriptlets_in_filters': request.form.get('ignore_scriptlets_in_filters'),
    'ignore_flow_output_vars_in_steps': request.form.get("ignore_flow_output_vars_in_steps"),
    'vars_to_ignore' : vars_to_ignore,
    }


    project_parser.py



    import os
    from xml.etree import ElementTree
    import zipfile
    from pprint import pprint

    from flow_parser import(
    FlowParser
    )

    class ProjectParser():

    def __init__(self, form):
    self.zf_ref = zipfile.ZipFile(form['jar_file'])
    self.form = form
    self.sys_props_usage_list =
    self.project_name = form['jar_file'].filename.split('-')[0]
    self.set_flws_and_cfgs()

    def set_flws_and_cfgs(self):
    self.flows =
    self.sys_props =
    self.sys_accts =
    self.file_size = self.zf_ref.infolist()
    for file_ref in self.zf_ref.infolist():
    if file_ref.filename.endswith('.xml'):
    if file_ref.filename.startswith('Content/Library/'):
    self.flows.append(file_ref)
    elif file_ref.filename.startswith('Content/Configuration/'):
    if 'System Properties' in file_ref.filename:
    self.sys_props.append(file_ref)
    elif 'System Accounts' in file_ref.filename:
    self.sys_accts.append(file_ref)

    def parse_flows(self, flow_ref):
    flow_parser = FlowParser(self.zf_ref, flow_ref, self.form)

    sys_props_info = {
    "flow_name" : flow_parser.name,
    "sys_props" : flow_parser.sys_props
    }

    self.sys_props_usage_list.append(sys_props_info)

    return flow_parser.json()

    def process_project(self):

    results =
    for flow in self.flows:
    results.append(self.parse_flows(flow))

    return results


    Dockerfile:



    # Use an official Python runtime as a parent image
    FROM python:3.7-slim

    # Set the working directory to /app
    WORKDIR /app

    # Copy the current directory contents into the container at /app
    COPY . /app

    # Install any needed packages specified in requirements.txt
    RUN pip install --trusted-host pypi.python.org -r requirements.txt

    # Make port 80 available to the world outside this container
    EXPOSE 80

    # Run app.py when the container launches
    CMD ["gunicorn", "--workers=2", "--bind=0.0.0.0:80", "app:APP"]









    share|improve this question



























      2












      2








      2


      1






      I have created sample flask application in which end user will upload jar file (contains bunch of XML files) using HTML form. Once user submits the form, in backend, I am reading the jar file content without saving it any target location by using Flask's FileStorage API and zipfile. And iterating over each xml files and performing some custom action and returning the data back to the user as a result.



      I have the created a docker container for this application, but now application is not working as expected as shown in below image:



      Results From not not containerized app:
      Results From not not containerized app



      Results from Container App:
      Results from Container App



      In both the results, I can see the uploaded file name i.e "SampleJar", but the number of xml files(flows) count is 0 in containerized app.



      Below is the code used for this app:



      app.py



      from flask import Flask, render_template, jsonify, request
      ...
      ...
      @APP.route("/parse", methods = ['POST'])
      def parse():
      """
      Parse the Uploaded jar file
      """
      form = get_request_data(request)
      proj_parser = ProjectParser(form)
      json_result = proj_parser.process_project()

      context = {}

      context['title'] = proj_parser.project_name
      context['flows_count'] = len(json_result)
      context['flows'] = json_result
      context['sys_props'] = proj_parser.sys_props_list
      context['sys_accts'] = proj_parser.sys_accts_list

      return render_template('report.html', context=context)

      def get_request_data(request):
      """
      Get the data from the request post
      """
      jar_file = request.files['project_file']
      steps_to_ignore = request.form.get('steps_to_ignore')
      vars_to_ignore = request.form.get('vars_to_ignore')

      if steps_to_ignore:
      steps_to_ignore = steps_to_ignore.replace('r', '').strip().split('n')
      else:
      steps_to_ignore =

      if vars_to_ignore:
      vars_to_ignore = vars_to_ignore.replace('r', '').strip().split('n')
      else:
      vars_to_ignore =

      return {
      'jar_file': jar_file,
      'steps_to_ignore': steps_to_ignore,
      'only_errors': request.form.get("only_errors"),
      'ignore_scriptlets_in_filters': request.form.get('ignore_scriptlets_in_filters'),
      'ignore_flow_output_vars_in_steps': request.form.get("ignore_flow_output_vars_in_steps"),
      'vars_to_ignore' : vars_to_ignore,
      }


      project_parser.py



      import os
      from xml.etree import ElementTree
      import zipfile
      from pprint import pprint

      from flow_parser import(
      FlowParser
      )

      class ProjectParser():

      def __init__(self, form):
      self.zf_ref = zipfile.ZipFile(form['jar_file'])
      self.form = form
      self.sys_props_usage_list =
      self.project_name = form['jar_file'].filename.split('-')[0]
      self.set_flws_and_cfgs()

      def set_flws_and_cfgs(self):
      self.flows =
      self.sys_props =
      self.sys_accts =
      self.file_size = self.zf_ref.infolist()
      for file_ref in self.zf_ref.infolist():
      if file_ref.filename.endswith('.xml'):
      if file_ref.filename.startswith('Content/Library/'):
      self.flows.append(file_ref)
      elif file_ref.filename.startswith('Content/Configuration/'):
      if 'System Properties' in file_ref.filename:
      self.sys_props.append(file_ref)
      elif 'System Accounts' in file_ref.filename:
      self.sys_accts.append(file_ref)

      def parse_flows(self, flow_ref):
      flow_parser = FlowParser(self.zf_ref, flow_ref, self.form)

      sys_props_info = {
      "flow_name" : flow_parser.name,
      "sys_props" : flow_parser.sys_props
      }

      self.sys_props_usage_list.append(sys_props_info)

      return flow_parser.json()

      def process_project(self):

      results =
      for flow in self.flows:
      results.append(self.parse_flows(flow))

      return results


      Dockerfile:



      # Use an official Python runtime as a parent image
      FROM python:3.7-slim

      # Set the working directory to /app
      WORKDIR /app

      # Copy the current directory contents into the container at /app
      COPY . /app

      # Install any needed packages specified in requirements.txt
      RUN pip install --trusted-host pypi.python.org -r requirements.txt

      # Make port 80 available to the world outside this container
      EXPOSE 80

      # Run app.py when the container launches
      CMD ["gunicorn", "--workers=2", "--bind=0.0.0.0:80", "app:APP"]









      share|improve this question
















      I have created sample flask application in which end user will upload jar file (contains bunch of XML files) using HTML form. Once user submits the form, in backend, I am reading the jar file content without saving it any target location by using Flask's FileStorage API and zipfile. And iterating over each xml files and performing some custom action and returning the data back to the user as a result.



      I have the created a docker container for this application, but now application is not working as expected as shown in below image:



      Results From not not containerized app:
      Results From not not containerized app



      Results from Container App:
      Results from Container App



      In both the results, I can see the uploaded file name i.e "SampleJar", but the number of xml files(flows) count is 0 in containerized app.



      Below is the code used for this app:



      app.py



      from flask import Flask, render_template, jsonify, request
      ...
      ...
      @APP.route("/parse", methods = ['POST'])
      def parse():
      """
      Parse the Uploaded jar file
      """
      form = get_request_data(request)
      proj_parser = ProjectParser(form)
      json_result = proj_parser.process_project()

      context = {}

      context['title'] = proj_parser.project_name
      context['flows_count'] = len(json_result)
      context['flows'] = json_result
      context['sys_props'] = proj_parser.sys_props_list
      context['sys_accts'] = proj_parser.sys_accts_list

      return render_template('report.html', context=context)

      def get_request_data(request):
      """
      Get the data from the request post
      """
      jar_file = request.files['project_file']
      steps_to_ignore = request.form.get('steps_to_ignore')
      vars_to_ignore = request.form.get('vars_to_ignore')

      if steps_to_ignore:
      steps_to_ignore = steps_to_ignore.replace('r', '').strip().split('n')
      else:
      steps_to_ignore =

      if vars_to_ignore:
      vars_to_ignore = vars_to_ignore.replace('r', '').strip().split('n')
      else:
      vars_to_ignore =

      return {
      'jar_file': jar_file,
      'steps_to_ignore': steps_to_ignore,
      'only_errors': request.form.get("only_errors"),
      'ignore_scriptlets_in_filters': request.form.get('ignore_scriptlets_in_filters'),
      'ignore_flow_output_vars_in_steps': request.form.get("ignore_flow_output_vars_in_steps"),
      'vars_to_ignore' : vars_to_ignore,
      }


      project_parser.py



      import os
      from xml.etree import ElementTree
      import zipfile
      from pprint import pprint

      from flow_parser import(
      FlowParser
      )

      class ProjectParser():

      def __init__(self, form):
      self.zf_ref = zipfile.ZipFile(form['jar_file'])
      self.form = form
      self.sys_props_usage_list =
      self.project_name = form['jar_file'].filename.split('-')[0]
      self.set_flws_and_cfgs()

      def set_flws_and_cfgs(self):
      self.flows =
      self.sys_props =
      self.sys_accts =
      self.file_size = self.zf_ref.infolist()
      for file_ref in self.zf_ref.infolist():
      if file_ref.filename.endswith('.xml'):
      if file_ref.filename.startswith('Content/Library/'):
      self.flows.append(file_ref)
      elif file_ref.filename.startswith('Content/Configuration/'):
      if 'System Properties' in file_ref.filename:
      self.sys_props.append(file_ref)
      elif 'System Accounts' in file_ref.filename:
      self.sys_accts.append(file_ref)

      def parse_flows(self, flow_ref):
      flow_parser = FlowParser(self.zf_ref, flow_ref, self.form)

      sys_props_info = {
      "flow_name" : flow_parser.name,
      "sys_props" : flow_parser.sys_props
      }

      self.sys_props_usage_list.append(sys_props_info)

      return flow_parser.json()

      def process_project(self):

      results =
      for flow in self.flows:
      results.append(self.parse_flows(flow))

      return results


      Dockerfile:



      # Use an official Python runtime as a parent image
      FROM python:3.7-slim

      # Set the working directory to /app
      WORKDIR /app

      # Copy the current directory contents into the container at /app
      COPY . /app

      # Install any needed packages specified in requirements.txt
      RUN pip install --trusted-host pypi.python.org -r requirements.txt

      # Make port 80 available to the world outside this container
      EXPOSE 80

      # Run app.py when the container launches
      CMD ["gunicorn", "--workers=2", "--bind=0.0.0.0:80", "app:APP"]






      python flask containers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 11:00









      Adam Mitchell

      7581627




      7581627










      asked Nov 13 '18 at 10:22









      Thejesh PRThejesh PR

      339310




      339310
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278801%2fcontainerised-flask-app-not-working-as-expected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278801%2fcontainerised-flask-app-not-working-as-expected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ