Skip to content

Commit

Permalink
Support for regular multistage docker
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 b8b9efb commit d478b0d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

FROM golang:1.21-alpine3.18 AS infra
ARG ARCH=amd64

RUN apk -U add bash coreutils git gcc musl-dev docker-cli vim less file curl wget ca-certificates
# go imports version gopls/v0.14.1
# https://github.com/golang/tools/releases/latest
RUN go install golang.org/x/tools/cmd/goimports@e985f842fa05caad2f3486f0711512aedffbcda8
RUN rm -rf /go/src /go/pkg
RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s; \
fi

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
FROM infra as validate
ARG SKIP_VALIDATE
ENV SKIP_VALIDATE=${SKIP_VALIDATE}
COPY . .

RUN ./scripts/validate

FROM infra AS build
ARG CROSS
ARG TAG
ARG DRONE_TAG
ARG ARCH=amd64
ENV ARCH=${ARCH}

COPY ./scripts/build ./scripts/version ./scripts/
COPY ./go.mod ./go.sum ./main.go ./
COPY ./pkg ./pkg
COPY ./.git ./.git
COPY ./.golangci.json ./.golangci.json

RUN ./scripts/build

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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ $(TARGETS): .dapper
./.dapper $@

.DEFAULT_GOAL := ci

ARCH ?= amd64
REPO ?= rancher
DEFAULT_BUILD_ARGS=--build-arg="REPO=$(REPO)" --build-arg="TAG=$(TAG)" --build-arg="ARCH=$(ARCH)"

.PHONY: no-dapper
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=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 kine-package

0 comments on commit d478b0d

Please sign in to comment.