From a3414c37dd5f02fff07fbfc63220a8ada47cd83c Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 26 Aug 2024 21:44:35 +0200 Subject: [PATCH] Move build-system to mutli-stage build-container --- Dockerfile | 22 +++++++++++++++++----- Makefile | 17 ----------------- 2 files changed, 17 insertions(+), 22 deletions(-) delete mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile index 851d651..85ca66d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM debian:bullseye +# ---- Build ---- +FROM golang:1.23-alpine AS build +WORKDIR /build +# Copy sources +ADD . . +# Get dependencies +RUN make go-build +# Compile +RUN CGO_ENABLED=0 go build -a -o webdavplugin ./cmd/webdav -ARG binary=./bin/webdavplugin -COPY ${binary} /webdavplugin -RUN apt update && apt install -y davfs2 +# ---- Release ---- +FROM alpine AS release +# Install required packages +RUN apk add --no-cache davfs2 -ENTRYPOINT ["/webdavplugin"] \ No newline at end of file +# Copy build-target +COPY --from=build /build/webdavplugin . + +ENTRYPOINT ["/webdavplugin"] diff --git a/Makefile b/Makefile deleted file mode 100644 index 7ca9b1c..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -GIT_COMMIT = $(shell git rev-parse HEAD) -BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") - -PKG = github.com/sys-liqian/csi-driver-webdav -LDFLAGS = -X ${PKG}/pkg/webdav.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/webdav.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/webdav.buildDate=${BUILD_DATE} -EXT_LDFLAGS = -s -w -extldflags "-static" - -IMAGE_VERSION ?= v0.0.1 -LOCAL_REPOSITORY ?= localhost:5000 - -.PHONY: go-build -go-build: - CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -a -ldflags "${LDFLAGS} ${EXT_LDFLAGS}" -o bin/webdavplugin ./cmd/webdav - -.PHONY: docker-build -docker-build: go-build - docker build --network host -t $(LOCAL_REPOSITORY)/webdavplugin:$(IMAGE_VERSION) . \ No newline at end of file