|
| 1 | +# Copyright 2025 NVIDIA CORPORATION & AFFILIATES |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +# Note: This Dockerfile produces a container image that can be used to run the spdk-csi controller only. |
| 18 | +# It is not suitable for running the spdk-csi node. |
| 19 | + |
| 20 | +FROM --platform=${BUILDPLATFORM} golang:1.25 AS builder |
| 21 | +ARG TARGETOS |
| 22 | +ARG TARGETARCH |
| 23 | + |
| 24 | +WORKDIR /workspace |
| 25 | +# Copy the Go Modules manifests |
| 26 | +COPY go.mod go.mod |
| 27 | +COPY go.sum go.sum |
| 28 | + |
| 29 | +# Copy the go source |
| 30 | +COPY ./ ./ |
| 31 | + |
| 32 | +# Vendor dependencies to include source code in the final image |
| 33 | +RUN go mod vendor |
| 34 | + |
| 35 | +ARG gcflags |
| 36 | +ARG ldflags |
| 37 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 38 | + --mount=type=cache,target=/go/pkg/mod \ |
| 39 | + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ |
| 40 | + go build -trimpath \ |
| 41 | + -ldflags="${ldflags}" \ |
| 42 | + -gcflags="${gcflags}" \ |
| 43 | + -o _out/spdkcsi ./cmd/ |
| 44 | + |
| 45 | +# copy project sources into the container |
| 46 | +RUN mkdir __src && \ |
| 47 | + find . -type f -not -path "./.git/*" -not -path "./.gocache/*" -not -path "./_out/*" \ |
| 48 | + -exec cp --parents \{\} __src/ \; |
| 49 | + |
| 50 | + |
| 51 | +FROM nvcr.io/nvidia/doca/dpf_containers:1.0.2-ubuntu22.04-distroless |
| 52 | +COPY --from=builder /workspace/_out/spdkcsi /usr/local/bin/ |
| 53 | +COPY --from=builder /workspace/__src /src |
| 54 | + |
| 55 | +ENTRYPOINT ["/usr/local/bin/spdkcsi"] |
0 commit comments