From 9ee5a0dd155ab89c6ddf474d759fb2a761de12e6 Mon Sep 17 00:00:00 2001
From: Ernesto Puerta <epuertat@redhat.com>
Date: Tue, 1 Aug 2023 10:12:58 +0200
Subject: [PATCH] build: create stand-alone packages

Fixes: #168

Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
---
 Dockerfile.spdk     |  4 ++++
 Makefile            | 12 +++++++++++-
 docker-compose.yaml | 18 ++++++++++++++++--
 pyproject.toml      |  2 +-
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/Dockerfile.spdk b/Dockerfile.spdk
index ebcede8df..925f3302f 100644
--- a/Dockerfile.spdk
+++ b/Dockerfile.spdk
@@ -50,6 +50,10 @@ RUN \
     MAKEFLAGS=$SPDK_MAKEFLAGS \
     rpmbuild/rpm.sh $SPDK_CONFIGURE_ARGS
 
+#------------------------------------------------------------------------------
+FROM registry.access.redhat.com/ubi9/ubi AS rpm-export
+COPY --from=build /root/rpmbuild/rpm /rpm
+
 #------------------------------------------------------------------------------
 FROM registry.access.redhat.com/ubi9/ubi
 
diff --git a/Makefile b/Makefile
index 6a0bf1873..aacb187ef 100644
--- a/Makefile
+++ b/Makefile
@@ -34,11 +34,21 @@ up: override OPTS += --no-build --remove-orphans --scale nvmeof=$(SCALE)
 clean: override HUGEPAGES = 0
 clean: $(CLEAN) setup  ## Clean-up environment
 
-update-lockfile: SVC=nvmeof-builder
+update-lockfile: SVC=nvmeof-builder-base
 update-lockfile: override OPTS+=--entrypoint=pdm
 update-lockfile: CMD=update --no-sync --no-isolation --no-self --no-editable
 update-lockfile: pyproject.toml run ## Update dependencies in lockfile (pdm.lock)
 
+export-rpms: SVC=spdk-rpm-export
+export-rpms: OPTS=--entrypoint=cp -v /tmp:/tmp
+export-rpms: CMD=-r /rpm /tmp
+export-rpms: run ## Build SPDK RPMs and copy them to /tmp/rpm
+
+export-python: SVC=nvmeof-builder
+export-python: OPTS=--entrypoint=pdm -v /tmp:/tmp
+export-python: CMD=build -d /tmp
+export-python: run ## Build Ceph NVMe-oF Gateway Python package and copy it to /tmp
+
 help: AUTOHELP_SUMMARY = Makefile to build and deploy the Ceph NVMe-oF Gateway
 help: autohelp
 
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 0aed574d6..924a308fd 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -24,6 +24,12 @@ services:
         SPDK_GIT_COMMIT:
       labels:
         io.ceph.nvmeof:
+  # Used to export RPM packages externally (via bind mount)
+  spdk-rpm-export:
+    extends:
+      service: spdk
+    build:
+      target: rpm-export
   ceph:
     image: quay.io/ceph/vstart-cluster:$CEPH_CLUSTER_VERSION
     container_name: ceph
@@ -99,14 +105,22 @@ services:
     depends_on:
       ceph:
         condition: service_healthy
-  nvmeof-builder:
+  # Used to update lockfile (make update-lockfile)
+  nvmeof-builder-base:
     extends:
       service: nvmeof-base
-    image: nvmeof-builder
+    image: nvmeof-builder-base
     build:
       target: builder-base
     volumes:
       - .:/src
+  # Used to export Python package
+  nvmeof-builder:
+    extends:
+      service: nvmeof-base
+    image: nvmeof-builder
+    build:
+      target: builder
   nvmeof-devel:
     # Runs from source code in current dir
     extends:
diff --git a/pyproject.toml b/pyproject.toml
index 07a6bfbeb..710c97fca 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "pdm.backend"
 
 [project]
 name = "ceph-nvmeof"
-dynamic = ["version"]
+version = "0.0.1"
 description = "Service to provide Ceph storage over NVMe-oF protocol"
 readme = "README.md"
 requires-python = "~=3.9"