diff --git a/Dockerfile b/Dockerfile index 35db4119..6ee741f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 \ No newline at end of file +COPY --from=build ${SRC_DIR}/bin /bin \ No newline at end of file diff --git a/Makefile b/Makefile index 0bb2269b..bc851a4e 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file + -e DAPPER_UID=1000 -e DAPPER_GID=1000 -e IMAGE_NAME -e DRONE_TAG -e DIRTY=$(DIRTY) kine-build \ No newline at end of file