Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 052d7e9

Browse files
committedFeb 27, 2025·
chore(Dockerfile): refactor Dockerfile.dapper
Longhorn 10497 Signed-off-by: Derek Su <[email protected]>
1 parent f8566f9 commit 052d7e9

File tree

4 files changed

+32
-55
lines changed

4 files changed

+32
-55
lines changed
 

‎Dockerfile.dapper

+22-44
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ARG DAPPER_HOST_ARCH
44
ARG http_proxy
55
ARG https_proxy
66
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
7+
ARG SRC_BRANCH=main
8+
ARG SRC_TAG
79

810
# Setup environment
911
ENV PATH /go/bin:$PATH
@@ -12,25 +14,22 @@ ENV DAPPER_ENV TAG REPO DRONE_REPO DRONE_PULL_REQUEST DRONE_COMMIT_REF
1214
ENV DAPPER_OUTPUT bin coverage.out
1315
ENV DAPPER_RUN_ARGS --privileged -v /dev:/host/dev -v /proc:/host/proc -v /sys:/host/sys
1416
ENV DAPPER_SOURCE /go/src/github.com/longhorn/go-spdk-helper
17+
ENV SRC_BRANCH ${SRC_BRANCH}
18+
ENV SRC_TAG ${SRC_TAG}
1519

1620
ENV GOLANGCI_LINT_VERSION="v1.60.3"
1721

1822
WORKDIR ${DAPPER_SOURCE}
1923

20-
ENV SPDK_COMMIT_ID a7421a6e59f1d099294af6f65d73ebec4afebfc5
21-
ENV LIBJSONC_COMMIT_ID b4c371fa0cbc4dcbaccc359ce9e957a22988fb34
22-
# Build nvme-cli 2.10.2
23-
ENV NVME_CLI_COMMIT_ID eeaa08c9a0e9184f3889df0bff3d2a23db6d6294
24-
2524
RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/SLE_15/system:snappy.repo && \
2625
zypper -n addrepo --refresh https://download.opensuse.org/repositories/network:/utilities/SLE_15/network:utilities.repo && \
2726
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:libraries:c_c++/15.6/devel:libraries:c_c++.repo && \
2827
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:languages:python:Factory/15.6/devel:languages:python:Factory.repo && \
2928
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:languages:python:backports/SLE_15/devel:languages:python:backports.repo && \
3029
zypper --gpg-auto-import-keys ref
3130

32-
RUN zypper -n install cmake wget unzip xsltproc docbook-xsl-stylesheets python311 python311-pip fuse3 libfuse3-3 \
33-
e2fsprogs xfsprogs util-linux-systemd device-mapper
31+
RUN zypper -n install cmake wget unzip xsltproc docbook-xsl-stylesheets python311 python311-pip fuse3-devel \
32+
e2fsprogs xfsprogs util-linux-systemd device-mapper jq
3433

3534
# Install Go & tools
3635
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
@@ -40,48 +39,27 @@ RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/i
4039
RUN ln -sf /usr/bin/python3.11 /usr/bin/python3 & \
4140
ln -sf /usr/bin/pip3.11 /usr/bin/pip3
4241

43-
# Build SPDK
44-
ENV SPDK_DIR /usr/src/spdk
45-
RUN git clone https://github.com/longhorn/spdk.git ${SPDK_DIR} --recursive && \
46-
cd ${SPDK_DIR} && \
47-
git checkout ${SPDK_COMMIT_ID} && \
48-
git submodule update --init && \
49-
sed -i '/python3-pyelftools/d' ./scripts/pkgdep/sles.sh && \
50-
sed -i 's/python3-/python311-/g' ./scripts/pkgdep/sles.sh && \
51-
./scripts/pkgdep.sh && \
52-
pip3 install -r ./scripts/pkgdep/requirements.txt && \
53-
if [ ${ARCH} = "amd64" ]; then \
54-
./configure --target-arch=nehalem --disable-tests --disable-unit-tests --disable-examples --without-nvme-cuse && \
55-
make -j$(nproc) && \
56-
make install; \
57-
elif [ ${ARCH} = "arm64" ]; then \
58-
./configure --target-arch=native --disable-tests --disable-unit-tests --disable-examples --without-nvme-cuse && \
59-
DPDKBUILD_FLAGS="-Dplatform=generic" make -j$(nproc) && \
60-
make install; \
61-
else \
62-
echo "Unsupported architecture: ${ARCH}"; \
63-
exit 1; \
42+
RUN git clone https://github.com/longhorn/dep-versions.git -b ${SRC_BRANCH} /usr/src/dep-versions && \
43+
cd /usr/src/dep-versions && \
44+
if [ -n "${SRC_TAG}" ] && git show-ref --tags ${SRC_TAG} > /dev/null 2>&1; then \
45+
echo "Checking out tag ${SRC_TAG}"; \
46+
cd /usr/src/dep-versions && git checkout tags/${SRC_TAG}; \
6447
fi
6548

49+
# Build spdk
50+
RUN export REPO_OVERRIDE="" && \
51+
export COMMIT_ID_OVERRIDE="" && \
52+
bash /usr/src/dep-versions/scripts/build-spdk.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}" "${ARCH}"
53+
6654
# Build libjson-c-devel
67-
RUN cd /usr/src && \
68-
git clone https://github.com/json-c/json-c.git && \
69-
cd json-c && \
70-
git checkout ${LIBJSONC_COMMIT_ID} && \
71-
mkdir .build && \
72-
cd .build && \
73-
cmake ../ && \
74-
make && \
75-
make install
55+
RUN export REPO_OVERRIDE="" && \
56+
export COMMIT_ID_OVERRIDE="" && \
57+
bash /usr/src/dep-versions/scripts/build-libjsonc.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}"
7658

7759
# Build nvme-cli
78-
ENV NVME_CLI_DIR /usr/src/nvme-cli
79-
RUN git clone https://github.com/linux-nvme/nvme-cli.git ${NVME_CLI_DIR} && \
80-
cd ${NVME_CLI_DIR} && \
81-
git checkout ${NVME_CLI_COMMIT_ID} && \
82-
meson setup --force-fallback-for=libnvme .build && \
83-
meson compile -C .build && \
84-
meson install -C .build
60+
RUN export REPO_OVERRIDE="" && \
61+
export COMMIT_ID_OVERRIDE="" && \
62+
bash /usr/src/dep-versions/scripts/build-nvme-cli.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}"
8563

8664
RUN ldconfig
8765

‎Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TARGETS := $(shell ls scripts)
2+
export SRC_BRANCH := main
3+
export SRC_TAG := $(shell git tag --points-at HEAD | head -n 1)
24

35
.dapper:
46
@echo Downloading dapper

‎pkg/spdk/spdk_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ type TestSuite struct{}
3939

4040
var _ = Suite(&TestSuite{})
4141

42-
func GetSPDKDir() string {
43-
spdkDir := os.Getenv("SPDK_DIR")
44-
if spdkDir != "" {
45-
return spdkDir
46-
}
47-
return filepath.Join(os.Getenv("GOPATH"), "src/github.com/longhorn/spdk")
48-
}
49-
5042
func LaunchTestSPDKTarget(c *C, execute func(envs []string, binary string, args []string, timeout time.Duration) (string, error)) {
5143
targetReady := false
5244
if spdkCli, err := client.NewClient(context.Background()); err == nil {
@@ -57,7 +49,7 @@ func LaunchTestSPDKTarget(c *C, execute func(envs []string, binary string, args
5749

5850
if !targetReady {
5951
go func() {
60-
err := target.StartTarget(GetSPDKDir(), []string{"2>&1 | tee /tmp/spdk_tgt.log"}, 60*time.Minute, execute)
52+
err := target.StartTarget("", []string{"2>&1 | tee /tmp/spdk_tgt.log"}, 60*time.Minute, execute)
6153
c.Assert(err, IsNil)
6254
}()
6355

‎pkg/spdk/target/target.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
const (
1616
SPDKScriptsDir = "scripts"
1717
SPDKSetupScript = "setup.sh"
18-
SPDKTGTBinary = "build/bin/spdk_tgt"
18+
SPDKTGTBinary = "spdk_tgt"
1919
)
2020

2121
// SetupTarget setups the spdk_tgt with the given args
@@ -59,9 +59,14 @@ func StartTarget(spdkDir string, args []string, timeout time.Duration, execute f
5959
for _, arg := range args {
6060
argsInStr = fmt.Sprintf("%s %s", argsInStr, arg)
6161
}
62+
63+
binary := SPDKTGTBinary
64+
if spdkDir == "" {
65+
binary = filepath.Join(spdkDir, SPDKTGTBinary)
66+
}
6267
tgtOpts := []string{
6368
"-c",
64-
fmt.Sprintf("%s %s", filepath.Join(spdkDir, SPDKTGTBinary), argsInStr),
69+
fmt.Sprintf("%s %s", binary, argsInStr),
6570
}
6671

6772
_, err = execute(nil, "sh", tgtOpts, timeout)

0 commit comments

Comments
 (0)
Please sign in to comment.