Skip to content

Instantly share code, notes, and snippets.

@jhelmink
Created March 8, 2024 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhelmink/f8fe558a9f463a6a03de6e6091bdc174 to your computer and use it in GitHub Desktop.
Save jhelmink/f8fe558a9f463a6a03de6e6091bdc174 to your computer and use it in GitHub Desktop.
Dockerfile for dotnet 8 azure function docker container with project dependencies and playwright
# How to build from base project folder - to include local dependencies
# sudo docker build -f ServiceFunctions/SpecificFunction/Dockerfile --tag specificfunction:v1.0.0 .
# How to run from base folder (-d dettached mode, -p port mapping outside:inside)
# sudo docker run -d -p 7190:80 --name specificfunction specificfunction:v1.0.0
# Handy commands when debugging
# sudo docker build --no-cache --progress=plain -f ServiceFunctions/SpecificFunction/Dockerfile --tag specificfunction-debug:v1.0.0 .
# sudo docker run -p 7190:80 --name specificfunction-debug specificfunction-debug:v1.0.0
# http://localhost:7190/api/DoTheThing?code=localDebugging
# sudo docker ps -a
# sudo docker stop specificfunction-debug
# sudo docker rm specificfunction-debug
# Connect to container
# sudo docker attach specificfunction-debug
# Explore container filesystem
# sudo docker exec -it specificfunction-debug /bin/bash
# Use the latest version of .NET for build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
# Copy local dependecies (must keep same folder structure)
COPY /DependentProject /publish/DependentProject
COPY /ServiceFunctions/SpecificFunction /publish/ServiceFunctions/SpecificFunction
# Restore and Build testing (these are called by Publish)
# RUN dotnet restore /publish/ServiceFunctions/SpecificFunction/SpecificFunction.csproj
# RUN dotnet build /publish/ServiceFunctions/SpecificFunction/SpecificFunction.csproj
# Publish - Configuration Debug|Release
RUN cd /publish/ServiceFunctions/SpecificFunction/ && \
mkdir -p /home/site/wwwroot && \
dotnet publish SpecificFunction.csproj --configuration Release --output /home/site/wwwroot
# Get the base Azure Function image for deployment
# https://mcr.microsoft.com/en-us/product/azure-functions/dotnet-isolated/tags
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0
# Copy the final build output to deployment image
COPY --from=build-env ["/home/site/wwwroot", "/home/site/wwwroot"]
# Setup Azure Functions Environment
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# for local build testing - create a known key ('localDebugging') for x-functions-key
#ENV AzureWebJobsSecretStorageType=files
#RUN mkdir -p /azure-functions-host/Secrets/
#RUN echo '{"masterKey":{"name":"master","value":"localDebugging","encrypted":false},"functionKeys":[]}' > /azure-functions-host/Secrets/host.json
# Install powershell to run Playwright installation script
RUN apt-get update -yq \
&& apt-get install wget -yq \
&& wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& apt-get update -yq \
&& apt-get install powershell -yq
# Install Playwright and dependencies in the deployment image
RUN pwsh /home/site/wwwroot/playwright.ps1 install --with-deps chromium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment