Skip to content

Commit

Permalink
Optimize caching for code change and tagging
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Dec 8, 2023
1 parent 870ee0f commit de5dc23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ RUN if [ "${ARCH}" == "amd64" ]; then \
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
WORKDIR ${SRC_DIR}/

# Validate needs everything in the project, so we seperate it out better caching
# Validate needs everything in the project, so we separate it out better caching
FROM infra as validate
ARG SKIP_VALIDATE
ENV SKIP_VALIDATE=${SKIP_VALIDATE}
COPY . .

RUN ./scripts/validate
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
--mount=type=cache,id=lint,target=/root/.cache/golangci-lint \
./scripts/validate

FROM infra AS build
ARG CROSS
Expand All @@ -35,13 +37,14 @@ COPY ./pkg ./pkg
COPY ./.git ./.git
COPY ./.golangci.json ./.golangci.json

RUN ./scripts/build
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
./scripts/build

COPY ./scripts/package ./scripts/entry ./scripts/
COPY ./package ./package
CMD ./scripts/entry package

FROM scratch as binary
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
COPY --from=build ${SRC_DIR}/bin /bin

FROM build as package
COPY ./scripts/package ./scripts/package
COPY ./package ./package
CMD ./scripts/package
COPY --from=build ${SRC_DIR}/bin /bin
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ no-dapper:
DOCKER_BUILDKIT=1 docker build \
$(DEFAULT_BUILD_ARGS) --build-arg="SKIP_VALIDATE=$(SKIP_VALIDATE)" \
--target=validate -f Dockerfile .
DOCKER_BUILDKIT=1 docker build \
$(DEFAULT_BUILD_ARGS) --build-arg="DRONE_TAG=$(DRONE_TAG)" --build-arg="CROSS=$(CROSS)" \
-f Dockerfile --target=build -t kine-build .
DOCKER_BUILDKIT=1 docker build \
$(DEFAULT_BUILD_ARGS) --build-arg="DRONE_TAG=$(DRONE_TAG)" --build-arg="CROSS=$(CROSS)" \
-f Dockerfile --target=binary --output=. .
DOCKER_BUILDKIT=1 docker build -t kine-package -f Dockerfile --target=package .
DOCKER_BUILDKIT=1 docker run -v /var/run/docker.sock:/var/run/docker.sock -v ./dist:/go/src/github.com/k3s-io/kine/dist \
-e IMAGE_NAME -e DRONE_TAG -e DIRTY=$(DIRTY) kine-package
-e DAPPER_UID=1000 -e DAPPER_GID=1000 -e IMAGE_NAME -e DRONE_TAG -e DIRTY=$(DIRTY) kine-build

0 comments on commit de5dc23

Please sign in to comment.