Skip to content

Commit 2f860c6

Browse files
authored
Merge pull request #2 from ykulazhenkov/pr-build-script
chore: add automation to build spdk-csi controller image
2 parents 18c1ee4 + dc58656 commit 2f860c6

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Push images on merge to master"
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
build-and-push-image:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set repository as lower-case output variable
12+
id: repo_name
13+
run: |
14+
echo "repository=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"-controller >> "$GITHUB_OUTPUT"
15+
- name: Check out code
16+
uses: actions/checkout@v4
17+
- name: Extract metadata
18+
id: docker_meta
19+
uses: docker/metadata-action@v5
20+
with:
21+
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
22+
tags: |
23+
type=ref,event=branch
24+
type=sha,prefix={{branch}}-
25+
- name: Set up QEMU
26+
uses: docker/setup-qemu-action@v3
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
- name: Login to GitHub Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.repository_owner }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
- name: Build and push multiarch container image
36+
uses: docker/build-push-action@v6
37+
with:
38+
push: true
39+
platforms: linux/amd64,linux/arm64
40+
tags: |
41+
ghcr.io/${{ steps.repo_name.outputs.repository }}:latest
42+
ghcr.io/${{ steps.repo_name.outputs.repository }}:${{ github.sha }}
43+
labels: ${{ steps.docker_meta.outputs.labels }}
44+
file: ./deploy/image/Dockerfile.nvidia

deploy/image/Dockerfile.nvidia

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)