Anupam Chand
Anupam Chand

Reputation: 2662

html to pdf on Azure using pdfkit with wkhtmltopdf

I'm attempting to write an Azure function which converts an html input to pdf and either writes this to a blob and/or returns the pdf to the client. I'm using the pdfkit python library. This requires the wkhtmltopdf executable to be available.

To test this locally on my windows machine, I installed the windows version of wkhtmltopdf and this works completely fine.

When I deployed this function on a Linux app service on Azure, I could still execute the function successfully only after I execute the sudo command on kudo tools to install wkhtmltopdf on the app service.

sudo apt-get install wkhtmltopdf 

I'm also aware that I can write this start up script on the app service itself.

My question is : Is there something I can do on my local windows machine so I can just deploy the the azure function along with the linux version of wkhtmltopdf directly from my vscode without having to execute another script on the app service itself?

Upvotes: 0

Views: 895

Answers (1)

Rajesh  Mopati
Rajesh Mopati

Reputation: 1506

By setting the below commands in the App configuration will work.

Thanks to @pamelafox for the comments.

Commands

PRE_BUILD_COMMAND or POST_BUILD_COMMAND

The following process is applied for each build.

  1. Run custom command or script if specified by PRE_BUILD_COMMAND or PRE_BUILD_SCRIPT_PATH.
  2. Create python virtual environment if specified by VIRTUALENV_NAME.
  3. Run python -m pip install --cache-dir /usr/local/share/pip-cache --prefer-binary -r requirements.txt if requirements.txt exists in the root of repo or specified by CUSTOM_REQUIREMENTSTXT_PATH.
  4. Run python setup.py install if setup.py exists.
  5. Run python package commands and determine python package wheel.
  6. If manage.py is found in the root of the repo manage.py collectstatic is run. However, if DISABLE_COLLECTSTATIC is set to true this step is skipped.
  7. Compress virtual environment folder if specified by compress_virtualenv property key.
  8. Run custom command or script if specified by POST_BUILD_COMMAND or POST_BUILD_SCRIPT_PATH.

Build Conda environment and Python JupyterNotebook

The following process is applied for each build.

  1. Run custom command or script if specified by PRE_BUILD_COMMAND or PRE_BUILD_SCRIPT_PATH.
  2. Set up Conda virtual environemnt conda env create --file $envFile.
  3. If requirment.txt exists in the root of repo or specified by CUSTOM_REQUIREMENTSTXT_PATH, activate environemnt conda activate $environmentPrefix and run pip install --no-cache-dir -r requirements.txt.
  4. Run custom command or script if specified by POST_BUILD_COMMAND or POST_BUILD_SCRIPT_PATH.

Package manager

The latest version of pip is used to install dependencies.

Run

The below process is applied to know how to start an app.

  1. If user has specified a start script, run it.
  2. Else, find a WSGI module and run with gunicorn.
    1. Look for and run a directory containing a wsgi.py file (for Django).
    2. Look for the following files in the root of the repo and an app class within them (for Flask and other WSGI frameworks).
      • application.py
      • app.py
      • index.py
      • server.py

Gunicorn multiple workers support

To enable running gunicorn with multiple workers strategy and fully utilize the cores to improve performance and prevent potential timeout/blocks from sync workers, add and set the environment variable PYTHON_ENABLE_GUNICORN_MULTIWORKERS=true into the app settings.

In Azure Web Apps the version of the Python runtime which runs your app is determined by the value of LinuxFxVersion in your site config. See ../base_images.md for how to modify this.

References taken from

Python runtime on App Service

Upvotes: 0

Related Questions