# Custom MongoDB Package Builder

## Overview

This project builds a custom MongoDB 8.0.17 server `.deb` package for **Ubuntu Jammy (22.04)** and **Ubuntu Noble (24.04)**. It uses the `mongod` binary from the `axcient/mongo-avx` repository and applies specific metadata and configuration adjustments to create a distributable package.

**Nehalem** variants ship a full replacement package (`mongodb-8.0-jammy-server` or `mongodb-8.0-noble-server`) suited for CPUs without AVX or AVX2. **Core2** variants add `mongodb-8.0-jammy-server-core2` or `mongodb-8.0-noble-server-core2`, which depends on the nehalem package and swaps in a Core2-targeted `mongod` via maintainer scripts (see `core2/`).

---

## Source

The mongod source code, `mongod` binary and its patches are sourced from the following repositories:

- **Axcient Mongo-AVX Repository**: [https://github.com/Axcient/mongo-avx](https://github.com/Axcient/mongo-avx)
- **Official MongoDB Repository**: https://github.com/mongodb/mongo. The source code is licensed under the Server Side Public License (SSPL) v1.

---

## Prerequisites

Place the official MongoDB server package for your target Ubuntu release in the project root (same directory as the Dockerfiles), using MongoDB’s naming convention:

- Jammy: `mongodb-org-server_jammy_<version>_amd64.deb`
- Noble: `mongodb-org-server_noble_<version>_amd64.deb`

The custom `mongod` zip for each series must be reachable at the `wget` URL in the matching Dockerfile (often a release asset from [mongo-avx releases](https://github.com/Axcient/mongod-avx/releases), or a branch/raw URL while iterating).

---

## Metadata Files

The following metadata files are included in the package:

- **`DEBIAN/control`**: Defines package metadata such as name, version, dependencies, and description.
- **`DEBIAN/copyright`**: Contains copyright and licensing information.
- **`usr/share/doc/mongodb-org-server/LICENSE-Community.txt`**: The license file for the MongoDB Community Edition.
- **`usr/share/doc/mongodb-org-server/README`**: A README file with additional information about the package.

---

## Dockerfiles

| File | Description |
|------|-------------|
| **`Dockerfile-jammy`** | Ubuntu 22.04 (Jammy); nehalem-class `mongod` replacement. |
| **`Dockerfile-jammy-core2`** | Jammy; Core2 binary + companion package depending on `mongodb-8.0-jammy-server`. |
| **`Dockerfile-noble`** | Ubuntu 24.04 (Noble); nehalem-class `mongod` replacement. |
| **`Dockerfile-noble-core2`** | Noble; Core2 binary + companion package depending on `mongodb-8.0-noble-server`. |

---

## Build Instructions

```sh
./build.sh "<REVISION>" <ubuntu-codename> [cpu-arch] [mongodb-version]
```

- **`<REVISION>`**: Replibit/package revision string (e.g. `"1"` or GitLab CI pipeline IID).
- **`<ubuntu-codename>`**: `jammy` or `noble`.
- **`[cpu-arch]`**: `nehalem` (default) or `core2`.
- **`[mongodb-version]`**: Optional, defaults to `8.0.17`.

Examples:

```sh
./build.sh "1" jammy nehalem 8.0.17
./build.sh "1" noble core2 8.0.17
```

Output `.deb` files are written under `<codename>-<cpu-arch>-mongodb-upload/` (for example `noble-nehalem-mongodb-upload/` or `noble-core2-mongodb-upload/`).
