nimbleways / dotnet-subset

A .NET tool that copies a subset of files from a repository to a directory. The tool is mainly used in Dockerfiles to optimize the docker build caching for "dotnet restore" instructions.
MIT License
84 stars 3 forks source link

Added CopySubset command #3

Open deeja opened 2 years ago

deeja commented 2 years ago

Added a copy subset for use in our company. This is super useful for our docker files that rely on a large context but don't want to lose the caching when nothing relevant has changed. We use multibuild stages to help with this

FROM mcr.microsoft.com/dotnet/sdk:6.0 as src
WORKDIR /src
COPY custom-packages custom-packages
RUN dotnet tool install dotnet-subset --global --no-cache --version 0.4.0 --add-source custom-packages
# the copy may copy files that are irrelevant to our build
COPY . . 
# group only the files we need for the build
RUN dotnet subset copy /src/ProjectA/ProjectA.csproj --root-directory /src --output /outgoing

# If the none of the ProjectA or related project files have changed, then all the following will use the cached layers
FROM mcr.microsoft.com/dotnet/sdk:6.0 as src as build
WORKDIR /src
COPY --from=src /outgoing/ .
COPY --from=src /src/custom-packages
RUN dotnet restore /ProjectA/ProjectA.csproj
RUN dotnet build --no-restore /ProjectA/ProjectA.csproj
othmane-kinane-nw commented 2 years ago

Thank you for your contribution !

Can you please document in a issue the specification used for the copy command so that we can discuss it ?

By the way, this is what I called the "build algorithm" in the roadmap. The tool will copy all the file needed for the supported dotnet operations. For example: