Skip to content

Templating Dockerfiles with a Shared Host Image

CooperLink edited this page Nov 18, 2021 · 9 revisions

Functions Appservice images all rely upon the same base image to compile the Functions Host and to download Function Extension Bundles. This repository supports this base image re-use by collating language specific templates with the base, shared, host Dockerfile. To achieve this, a script in the /host/ directory (generate-composite.sh) concatenates language and version specific files to the end of the host Dockerfile and takes care of necessary steps like globalizing ARGs where needed.

Re-using the same base image has two major benefits. The most pronounced is to reduce the need for huge PRs with many changes in this repository. With our previous configuration, changes to the base image required over 50 file changes just to maintain consistency between images. This was dangerous as there is not an automated method to change all files at once in most cases and it is easy to miss one or two files while trying to alter all of them. Consistency is important in reducing unique image size.

Another major benefit of this approach is breaking apart multi-stage builds. This makes it easier to produce early stages as images which can allow us to cut down on image size by inspecting the Host base image file system and ensuring we are only copying over what is needed.

Using Function Images

If you would like to consume Functions images for some downstream use consider building your image from the published Function images that should be updated every two weeks by using FROM mcr.microsoft.com/azure-functions/:tag

If you would like to consume the Dockerfiles themselves, the generated Dockerfiles are uploaded as an zipped asset on each release beginning with our next release cycle (>3.4.1/>4.0.1.16815).

If you must access the Dockerfiles directly from this repository with the absolute latest changes, please refer to the next section on how you can generate Dockerfiles.

How to generate appservice Dockerfiles

Generating AppService files requires a Linux/Unix shell. This is necessary to prevent CRLF/LF related issues in the Dockerfiles. Do not try to run this script from a windows bash environment. See the following for instructions on setting up WSL2 on Windows: https://docs.microsoft.com/en-us/windows/wsl/about !!! Make sure that you run from an admin window !!!

The compilation script provides final Dockerfile images in the /out/ directory of its associated version. To generate v3 appservice Dockerfiles for all languages, please run the following command in a Linux shell from the /host/ directory

./generate-composite.sh -3 all

Options :

Flags to target version (-3 or -4)

Release mode. Used to generate release artifacts. Changes output directory to /release/ (-r)

Language to generate. Currently supports all, dotnet, python, java, and node

Associated PRs

https://github.com/Azure/azure-functions-docker/pull/516

https://github.com/Azure/azure-functions-docker/pull/542

https://github.com/Azure/azure-functions-docker/pull/551