Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion generate/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -101,6 +102,7 @@ func init() {
ProductEdgeServer,
ProductEnterpriseAnalytics,
ProductEnterpriseAnalyticsUdf,
ProductMongoDBCompatibility,
}

// TODO: Read the version_customizations.json file into map
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
}
Comment on lines +384 to +389
}

// Apply any user-requested template overrides
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Couchbase MongoDB Compatibility (cbmcd)
Original file line number Diff line number Diff line change
@@ -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}"
Comment on lines +28 to +35

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