diff --git a/.dockerignore b/.dockerignore index 0dae4a4..0f2181b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ -# Ignore everything -** - -## Except build folder -!/build/** +.github/ +build/ +deploy/ +test/ +tools/ +README.md +.golangci.yaml diff --git a/Dockerfile b/Dockerfile index 1511c28..f869b70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,27 @@ # syntax=docker/dockerfile:1 -FROM alpine:3.19 +FROM golang:1.22 AS builder + +ENV CGO_ENABLED=0 + +# copy manifest files only to cache layer with dependencies +WORKDIR /src/app/ +COPY go.mod go.sum /src/app/ +RUN go mod download +# copy source code +COPY cmd/ cmd/ +COPY internal/ internal/ + +# build +RUN go build -o xelon-csi -ldflags="-s -w" -trimpath cmd/xelon-csi/main.go + + + +FROM alpine:3.20 AS production ARG VERSION -LABEL org.opencontainers.image.ref.name="xelon-csi" \ +LABEL org.opencontainers.image.licenses="Apache-2.0" \ + org.opencontainers.image.ref.name="xelon-csi" \ org.opencontainers.image.source="https://github.com/Xelon-AG/xelon-csi" \ org.opencontainers.image.vendor="Xelon AG" \ org.opencontainers.image.version="${VERSION:-local}" @@ -20,40 +38,6 @@ RUN <