First, I decoupled "injection" and "push" in the "build" process:
graph LR;
subgraph Build
direction LR
buildkit[Use buildkit to build a Docker image] -- If serverless --> serverless[Transform to serverless]
buildkit -- If not serverless --> tar[Output as Docker TAR]
end
S((Start)) --> IEV[Inject environment variable]
IEV --> Build
tar -.->|If push| skopeo[Upload to registry with skopeo]
Second, I leveraged ARG, target, and the combination of Docker images to simplify the Dockerfile construction. By combining the Docker images, we accelerate the build process.
FROM zeabur/zbpack-dart-flutter-base AS build
ARG build
WORKDIR /app
COPY . .
RUN flutter clean
RUN flutter pub get
RUN ${build}
FROM scratch AS target-static
LABEL com.zeabur.image-type="static"
COPY --from=build /app/build/web /
FROM docker.io/library/caddy AS target-containerized
LABEL com.zeabur.image-type="containerized"
COPY --from=build /app/build/web /usr/share/caddy
Description (required)
I rewrote the image build logic.
First, I decoupled "injection" and "push" in the "build" process:
Second, I leveraged
ARG
,target
, and the combination of Docker images to simplify the Dockerfile construction. By combining the Docker images, we accelerate the build process.Third, I utilized the
LABEL
in the Dockerfile to select the transformer for serverless functions. For example:Finally, I leverage
dockerfile/parser
to parse the Dockerfile, ensuring more reliable parsing.Demo:
WIPs:
Related issues & labels (optional)