A generalised Dockerfile for building ASP.NET Core apps using Cake
808
This repo contains a Dockerfile that can be used to build ASP.NET Core images using Cake, where they conform to a standard layout:
The image uses Docker's ONBUILD command to execute the following in your project's directory:
dotnet restore using Cake (to take advantage of Docker's layer caching mechanism)dotnet build using Cakedotnet test on every project in the test folder using CakeA Cake build file is included for restoring, building and testing your app. You can overwrite the build.cake file by including a replacement in your project folder if it doesn't meet your requirements. Either way, you will need to include a Cake build file for publishing your app. This includes invoking the publish command.
For example, the following small would be a publish target:
var target = Argument("Target", "Default");
var configuration = Argument("Configuration", "Release");
var distDirectory = Directory("./dist");
// Publish the app to the /dist folder
Task("PublishWeb")
.Does(() =>
{
DotNetCorePublish(
"./src/AspNetCoreInDocker.Web/AspNetCoreInDocker.Web.csproj",
new DotNetCorePublishSettings()
{
Configuration = configuration,
OutputDirectory = distDirectory,,
ArgumentCustomization = args => args.Append("--no-restore"),
});
});
Task("Default")
.IsDependentOn("BuildAndTest")
.IsDependentOn("PublishWeb");
// Executes the task specified in the target argument.
RunTarget(target);
You can then use the Docker image and publish your app using a Docker image similar to the following:
# Build image
FROM andrewlock/aspnetcore-cakebuild:2.0.7-2.1.105 as builder
# Publish
ONBUILD RUN sh ./build.sh build.cake --target=Restore
#App image
FROM microsoft/aspnetcore:2.0.7
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT Local
ENTRYPOINT ["dotnet", "AspNetCoreInDocker.Web.dll"]
COPY --from=builder /sln/dist .
Content type
Image
Digest
Size
683.5 MB
Last updated
over 8 years ago
docker pull andrewlock/aspnetcore-cakebuild