-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
I have a project that uses an intermediate artifact. Here's an example:
FROM mcr.microsoft.com/dotnet/sdk:8.0-azurelinux3.0 AS build
USER root
COPY . /app
WORKDIR /app
RUN dotnet restore && \
ls /root/.nuget/packagesThis then gets used as a base image for my actual application Dockerfiles:
ARG BUILD_IMAGE
FROM $BUILD_IMAGE AS build
WORKDIR /app/
COPY ./src/MyApp ./src/MyApp
WORKDIR /app/src/MyApp
RUN dotnet publish --no-restore --no-dependencies -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:8.0-azurelinux3.0 AS final
USER app
WORKDIR /app
COPY --from=build /app/src/MyApp/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]And I build it using skaffold:
apiVersion: skaffold/v4beta8
kind: Config
metadata:
name: dotnet-restore
build:
local:
push: false
useBuildkit: true
artifacts:
- image: myapp-dotnet-restore
context: .
docker:
dockerfile: ./intermediate-images/dotnet-restore/Dockerfile
---
apiVersion: skaffold/v4beta8
kind: Config
requires:
- configs: [dotnet-restore]
build:
local:
push: false
useBuildkit: true
artifacts:
- image: my-app
context: .
docker:
dockerfile: ./src/MyApp/Dockerfile
requires:
- image: myapp-dotnet-restore
alias: BUILD_IMAGEI'm using this intermediate image because the dotnet restore step downloads lots of nuget packages, and I want to minimise the number of times this image gets rebuilt (and maximise the number of times the layer cache can be reused when it does get rebuilt).
The same pattern applies to using intermediate images for dependency caching cross-language - e.g. modules in js, go, python, java, etc.
I've noticed that skaffold tries to load the intermediate image onto my local k8s cluster - because it has push: false. This image contains all the package dependencies for the entire solution, so loading it into the local k8s cluster takes significant time and isn't necessary as it isn't used in any actual running containers.
I'd love to be able to mark an artifact as buildOnly or intermediate or similar, to tell skaffold that this artifact is an intermediate part of the build process and not part of the build output, and so doesn't ever need loaded into the local cluster or pushed to a remote repo.