Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Last active January 4, 2019 05:38
Show Gist options
  • Save sjwaight/e0047a235790b2d7489428ea5c750eb7 to your computer and use it in GitHub Desktop.
Save sjwaight/e0047a235790b2d7489428ea5c750eb7 to your computer and use it in GitHub Desktop.
Inline Shell script to build and deploy Azure Functions v2 Python preview apps
#
# Build and deploy Python Azure Function v2 (preview) on Azure DevOps
#
# Paste this as an inline script into an "Azure CLI" Build Task running on an Ubuntu 16.04 managed host.
#
# Set Build Variables:
#
# FunctionFolder = name of folder containing your Function
# FunctionAppName = name of the target Azure Function that will receive the deployment.
# Step 1: Install Python 3.6 & Functions Core tools
# Functions source
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
# Python 3.6 package for Ubuntu 16.04
sudo add-apt-repository ppa:deadsnakes/ppa
# Update packages list
sudo apt-get update
# Install Azure Functions Core Tools
sudo apt-get install azure-functions-core-tools
# install Python3 and Virtual Environment support
sudo apt-get install python3.6
sudo apt-get install python3.6-venv
# Step 2: Initialise Python Virtual Environment (venv)
python3.6 -m venv .env
source .env/bin/activate
# Step 3: Initialise and build Function App
# Backup our source requirements.txt file
mv $(FunctionFolder)/requirements.txt $(FunctionFolder)/requirements.orig.txt
# Initialise Function environment locally so it sets runtime to Python
# Note: this also overwrites requirements.txt
func init $(FunctionFolder) --worker-runtime python
# Delete the newly created requirements.txt file
rm $(FunctionFolder)/requirements.txt
# Restore our original requirements.txt file
mv $(FunctionFolder)/requirements.orig.txt $(FunctionFolder)/requirements.txt
# Install Functions extensions for Function
cd $(FunctionFolder)
func extensions install
# Step 4: Deploy (uses Docker) - FunctionAppName should be an existing Linux Consumption App Plan
func azure functionapp publish $(FunctionAppName) --build-native-deps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment