From 3599d5cf01f4b9175d513ea9fd09c00c7564b6e2 Mon Sep 17 00:00:00 2001 From: Ming Ho Date: Fri, 4 Sep 2026 16:28:54 -0700 Subject: [PATCH] CBD-6817, docker script and template for rosetta-mdb. -Ming --- generate/generator/generate.go | 23 +++++++++- .../couchbase-mongodb-compatibility/README.md | 1 + .../Dockerfile.template | 43 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 generate/resources/couchbase-mongodb-compatibility/README.md create mode 100644 generate/templates/couchbase-mongodb-compatibility/Dockerfile.template diff --git a/generate/generator/generate.go b/generate/generator/generate.go index 2ee6c28b..168cd009 100644 --- a/generate/generator/generate.go +++ b/generate/generator/generate.go @@ -40,6 +40,7 @@ const ( ProductEdgeServer = Product("couchbase-edge-server") ProductEnterpriseAnalytics = Product("enterprise-analytics") ProductEnterpriseAnalyticsUdf = Product("enterprise-analytics-udf") + ProductMongoDBCompatibility = Product("couchbase-mongodb-compatibility") ) // These are Docker's idea of architecture names, eg. amd64, arm64. @@ -101,6 +102,7 @@ func init() { ProductEdgeServer, ProductEnterpriseAnalytics, ProductEnterpriseAnalyticsUdf, + ProductMongoDBCompatibility, } // TODO: Read the version_customizations.json file into map @@ -252,7 +254,7 @@ func generateOneDockerfile( // 7.1.0 and higher also support arm64 variant.Arches = append(variant.Arches, Archarm64) } - } else if product == ProductColumnar || product == ProductEnterpriseAnalytics || product == ProductEnterpriseAnalyticsUdf { + } else if product == ProductColumnar || product == ProductEnterpriseAnalytics || product == ProductEnterpriseAnalyticsUdf || product == ProductMongoDBCompatibility { variant.Arches = append(variant.Arches, Archarm64) } @@ -378,6 +380,13 @@ func generateDockerfile(variant DockerfileVariant) error { "CB_PACKAGE_NAME": variant.edgeServerPackageFile(Archgeneric), "DOCKER_BASE_IMAGE": variant.dockerBaseImage(), } + } else if variant.Product == ProductMongoDBCompatibility { + params = map[string]any{ + "CB_VERSION": variant.VersionWithSubstitutions(), + "CB_PACKAGE": variant.mongoCompatibilityPackageFile(Archgeneric), + "DOCKER_BASE_IMAGE": variant.dockerBaseImage(), + "CB_MULTIARCH": len(variant.Arches) > 1, + } } // Apply any user-requested template overrides @@ -612,6 +621,8 @@ func (variant DockerfileVariant) dockerBaseImage() string { return fmt.Sprintf("ubuntu:%s", variant.ubuntuVersion()) case ProductEnterpriseAnalyticsUdf: return "debian:12-slim" + case ProductMongoDBCompatibility: + return "debian:12-slim" default: log.Printf("Failed %v", variant.Product) panic("Unexpected product") @@ -911,6 +922,16 @@ func (variant DockerfileVariant) columnarPackageFile(arch Arch) string { ) } +// Generate the package filename for this variant: +// eg: cbmcd-arm64_1.0.0 +func (variant DockerfileVariant) mongoCompatibilityPackageFile(arch Arch) string { + return fmt.Sprintf( + "cbmcd-%v_%v", + arch, + variant.Version, + ) +} + // Generate the package filename for this variant: // eg: enterprise-analytics_2.0.0-linux_arm64.deb func (variant DockerfileVariant) enterpriseAnalyticsPackageFile(arch Arch) string { diff --git a/generate/resources/couchbase-mongodb-compatibility/README.md b/generate/resources/couchbase-mongodb-compatibility/README.md new file mode 100644 index 00000000..c7562d80 --- /dev/null +++ b/generate/resources/couchbase-mongodb-compatibility/README.md @@ -0,0 +1 @@ +# Couchbase MongoDB Compatibility (cbmcd) diff --git a/generate/templates/couchbase-mongodb-compatibility/Dockerfile.template b/generate/templates/couchbase-mongodb-compatibility/Dockerfile.template new file mode 100644 index 00000000..431ab186 --- /dev/null +++ b/generate/templates/couchbase-mongodb-compatibility/Dockerfile.template @@ -0,0 +1,43 @@ +FROM {{ .DOCKER_BASE_IMAGE }} + +LABEL maintainer="docker@couchbase.com" + +# Create couchbase user/group with fixed UID/GID 1000 for consistency across environments +# (modifies existing user/group in images which already have UID/GID 1000) +RUN set -x \ + && if getent group 1000 >/dev/null; then \ + existing_group=$(getent group 1000 | cut -d: -f1); \ + groupmod --new-name couchbase "${existing_group}"; \ + else \ + groupadd -g 1000 couchbase; \ + fi \ + && if getent passwd 1000 >/dev/null; then \ + existing_user=$(getent passwd 1000 | cut -d: -f1); \ + usermod --login couchbase -d /home/couchbase -m -g couchbase -s /bin/sh "${existing_user}"; \ + else \ + useradd couchbase -u 1000 -g couchbase -M -s /bin/sh; \ + fi + +# curl + ca-certificates: for downloading the cbmcd binary below over HTTPS +RUN set -x \ + && apt-get update -y -q \ + && apt-get install -y -q --no-install-recommends curl ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ARG CB_VERSION={{ .CB_VERSION }} +ARG CB_RELEASE_URL=https://packages.couchbase.com/releases/rosetta-mdb/${CB_VERSION} +ARG CB_PACKAGE={{ .CB_PACKAGE }} +RUN set -x \ + && CB_BINARY="$(echo "${CB_PACKAGE}" | cut -d'-' -f1)" \ + && curl --fail -o "/usr/local/bin/${CB_BINARY}" \ + "${CB_RELEASE_URL}/${CB_PACKAGE}" \ + && chmod +x "/usr/local/bin/${CB_BINARY}" + +USER couchbase + +ENTRYPOINT ["cbmcd"] + +# --mongo-port (default 27017): the MongoDB wire-protocol port cbmcd serves. +# All other configuration is via CLI flags / ROSETTA_* env vars - see --help. +EXPOSE 27017