how to deploy python with all dependencies in App service which inside ASE(app service environment)

mzheng1985 20 Reputation points
2023-03-17T00:50:43.02+00:00

I am using azure devops to deploy my python flask app into app service, which sit inside app service environment(ASE), NSG of subnet for ASE only allow certain outbound IPs, those PYPI url are blocked. I know I can use container option to pack everything into the image and deploy with container option, but how to do the same using zip deploy? I am trying to add dependencies into the zip, but no luck, the app service still try to install dependences by checking the requirements.txt file, which is fail of course due to unreachable to pypi.

thanks in advance!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,877 questions
0 comments No comments
{count} votes

Accepted answer
  1. Grmacjon-MSFT 15,856 Reputation points
    2023-03-23T21:19:22.9633333+00:00

    Hi @mzheng1985 thanks for the question. how did you try to add dependencies into the zip? what are those dependencies/requirements?

    Since you are using Azure DevOps for your deployment, you can consider the following options to deploy your Flask app with its dependencies using zip deploy:

    1. Pre-install Dependencies: You can pre-install the required dependencies in your deployment environment before deploying the Flask app. You can create a custom Docker image or use a pre-built Docker image that already has the required dependencies installed. This approach is similar to the container option, but instead of deploying a container, you can extract the required files from the image and deploy them using zip deploy.
    2. Include Dependencies in the Zip File: You can include the required dependencies in the zip file along with your Flask app code. This can be done by creating a virtual environment, installing the dependencies in the virtual environment, and including the virtual environment folder in the zip file. When you deploy the zip file, the virtual environment folder will be extracted to the deployment environment, and the Flask app will use the dependencies installed in the virtual environment.

    To create a virtual environment and install dependencies, you can use the following commands:

    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    

    To include the virtual environment folder in the zip file, you can use the following command:

    zip -r app.zip app.py venv
    

0 additional answers

Sort by: Most helpful