From 2276dc53601a74b4529ad3f9b54261a65b79aab3 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Wed, 28 Feb 2024 00:39:58 +0100
Subject: [PATCH] refactor(spilo): Rework spilo image for multi-container build

---
 images/.utils/gitlab-ci.yaml               |  2 +-
 images/splio-vectorrs/.release             |  1 -
 images/splio/.release                      |  1 +
 images/{splio-vectorrs => splio}/Earthfile | 27 ++++++++++++++++++----
 4 files changed, 24 insertions(+), 7 deletions(-)
 delete mode 100644 images/splio-vectorrs/.release
 create mode 100644 images/splio/.release
 rename images/{splio-vectorrs => splio}/Earthfile (54%)

diff --git a/images/.utils/gitlab-ci.yaml b/images/.utils/gitlab-ci.yaml
index 0c3b8d4c7..1274eef81 100644
--- a/images/.utils/gitlab-ci.yaml
+++ b/images/.utils/gitlab-ci.yaml
@@ -15,7 +15,7 @@ container-build:
           - findmydevice-server
           - opentf
           - cowsay
-          - splio-vectorrs
+          - splio
   script:
     - cd images/${IMAGE}
     - |
diff --git a/images/splio-vectorrs/.release b/images/splio-vectorrs/.release
deleted file mode 100644
index 51cc74622..000000000
--- a/images/splio-vectorrs/.release
+++ /dev/null
@@ -1 +0,0 @@
-release=2
diff --git a/images/splio/.release b/images/splio/.release
new file mode 100644
index 000000000..74692a587
--- /dev/null
+++ b/images/splio/.release
@@ -0,0 +1 @@
+release=0
diff --git a/images/splio-vectorrs/Earthfile b/images/splio/Earthfile
similarity index 54%
rename from images/splio-vectorrs/Earthfile
rename to images/splio/Earthfile
index 85ce044d7..baa9ca7de 100644
--- a/images/splio-vectorrs/Earthfile
+++ b/images/splio/Earthfile
@@ -1,21 +1,38 @@
 VERSION 0.7
 
 container:
+    BUILD +container-spilo
+    BUILD +container-pgvectors
+
+container-spilo:
     FROM ghcr.io/zalando/spilo-15:3.0-p1
-    ARG registry=quay.io/shivering-isles/splio-vectorrs
+    ARG registry=quay.io/shivering-isles/splio
     COPY .release ./
+    ENV PG_VERSION=$(pg_config --version | sed -e 's/PostgreSQL //' -e 's/\..*//')
+    ENV SI_REVISION=$(awk -F'=' '$1 == "release" {print $2}' .release)
+    ARG tag=$PG_VERSION-$(echo $PATRONIVERSION | cut -d'.' -f 1-2)-r$SI_REVISION
+    DO ../.utils/+LABEL --image=spilo --version=main
+    IF [ $latest = "true" ]
+        SAVE IMAGE --push ${registry}:latest
+    ELSE
+        LABEL "quay.expires-after"="12w"
+    END
+    SAVE IMAGE --push ${registry}:${tag}
+
+container-pgvectors:
+    FROM +container-spilo
+    ARG registry=quay.io/shivering-isles/splio
     # renovate: datasource=github-releases depName=tensorchord/pgvecto.rs
     ARG PG_VECTORS_VERSION=v0.2.0
-    ENV PG_VERSION=$(pg_config --version | sed -e 's/PostgreSQL //' -e 's/\..*//')
-    ARG tag=$PG_VERSION-$(echo $PATRONIVERSION | cut -d'.' -f 1-2)-pg${PG_VECTORS_VERSION}-r$(awk -F'=' '$1 == "release" {print $2}' .release)
+    ARG tag=$PG_VERSION-$(echo $PATRONIVERSION | cut -d'.' -f 1-2)-pg${PG_VECTORS_VERSION}-r${SI_REVISION}
     ARG latest=false
     ARG VECTORS_DEB="./vectors-pg${PG_VERSION}_amd64.deb"
     RUN curl -L https://github.com/tensorchord/pgvecto.rs/releases/download/${PG_VECTORS_VERSION}/vectors-pg${PG_VERSION}_$(echo $PG_VECTORS_VERSION  | sed -e 's/^v//')_amd64.deb > "$VECTORS_DEB"
     RUN apt install "$VECTORS_DEB"
     RUN rm "$VECTORS_DEB"
-    DO ../.utils/+LABEL --image=postfix --version=main
+    DO ../.utils/+LABEL --image=spilo --version=main
     IF [ $latest = "true" ]
-        SAVE IMAGE --push ${registry}:latest
+        SAVE IMAGE --push ${registry}:latest-pg${PG_VECTORS_VERSION}
     ELSE
         LABEL "quay.expires-after"="12w"
     END
-- 
GitLab