{"id":16542294,"url":"https://github.com/brantburnett/couchbasefakeit","last_synced_at":"2025-10-28T15:30:56.234Z","repository":{"id":23899743,"uuid":"85092021","full_name":"brantburnett/couchbasefakeit","owner":"brantburnett","description":"Docker scripts for a base Couchbase Server image for testing/development, with support for fakeit for data generation","archived":false,"fork":false,"pushed_at":"2024-10-23T21:20:32.000Z","size":401,"stargazers_count":16,"open_issues_count":5,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-02-01T15:40:52.914Z","etag":null,"topics":["couchbase","docker","docker-image","fakeit","ha","hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brantburnett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-15T15:51:51.000Z","updated_at":"2024-10-23T21:20:37.000Z","dependencies_parsed_at":"2023-12-03T01:23:09.222Z","dependency_job_id":"5235a345-fd97-4745-99d9-7722d04fd101","html_url":"https://github.com/brantburnett/couchbasefakeit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2Fcouchbasefakeit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2Fcouchbasefakeit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2Fcouchbasefakeit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2Fcouchbasefakeit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brantburnett","download_url":"https://codeload.github.com/brantburnett/couchbasefakeit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238671983,"owners_count":19511190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["couchbase","docker","docker-image","fakeit","ha","hacktoberfest"],"created_at":"2024-10-11T18:57:07.542Z","updated_at":"2025-10-28T15:30:50.899Z","avatar_url":"https://github.com/brantburnett.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CouchbaseFakeIt\n\n## Overview\n\ncouchbasefakeit is a Docker image designed for testing and local development.  It starts up a single, standalone [Couchbase Server](http://couchbase.com) instance within a Docker container and initializes it with buckets, indexes, and fake data that you define.  Fake data is generated using [FakeIt](https://www.npmjs.com/package/fakeit).\n\nThis can be very useful in reducing developer friction, providing a way to quickly and easily spin up a Couchbase server preinitialized for your application.  By including an Dockerfile and associated configuration files within your source control repo, you can version your development data definitions along with your application.\n\n\u003e **NOTE:** couchbasefakeit is built on top of [couchbase-quickinit](https://github.com/brantburnett/couchbase-quickinit), adding support for data generation using FakeIt. If you do not require data generation, simply use `couchbase-quickinit` directly.\n\n## Pulling\n\nThe latest version can be pulled using:\n\n```sh\ndocker pull btburnett3/couchbasefakeit:enterprise-7.2.3\n```\n\nOther may also be available, such as `community-7.0.2`.  This would be the Community edition of Couchbase, version 7.0.2.\n\n## Using couchbasefakeit\n\nTo use couchbasefakeit, create your own Dockerfile that uses couchbasefakeit as its base image.  Then add configuration files to the /startup directory of the new image.  You may also override environment variables to change the Couchbase Server configuration.\n\n```dockerfile\nFROM btburnett3/couchbasefakeit:latest\n\n# Customize environment\nENV CB_DATARAM=256 \\\n    CB_PASSWORD=mypassword\n\n# Copy files\nCOPY . /startup/\n```\n\n### Environment Variables\n\nThe following environment variables can be set to change the Couchbase Server configuration:\n\n| Env Variable    | Description                                                                                |\n| ------------    | -----------                                                                                |\n| CB_CLUSTER_NAME | Specify the name of the cluster                                                            |\n| CB_DATARAM      | Data service RAM in megabytes, default `512`                                               |\n| CB_INDEXRAM     | Index service RAM in megabytes, default `256`                                              |\n| CB_SEARCHRAM    | Search (FTS) service RAM in megabytes, default `256`                                       |\n| CB_ANALYTICSRAM | Analytics service RAM in megabytes. Only applicable if `cbas` is added to `CB_SERVICES`    |\n| CB_EVENTINGRAM  | Eventing service RAM in megabytes. Only applicable if `eventing` is added to `CB_SERVICES` |\n| CB_SERVICES     | Services to enable, default `kv,n1ql,index,fts`                                            |\n| CB_INDEXSTORAGE | Index storage mode, `forestdb` (default) or `memory_optimized`                             |\n| CB_USERNAME     | Couchbase user name, default `Administrator`                                               |\n| CB_PASSWORD     | Couchbase password, default `password`                                                     |\n\nValues for CB_SERVICES and CB_INDEXSTORAGE correspond to parameters for the [Couchbase REST API](https://docs.couchbase.com/server/current/rest-api/rest-node-provisioning.html).\n\n**NOTE:** If you configure `CB_SERVICES` to create the `cbas` analytics service, make sure you set `CB_ANALYTICSRAM` to a minimum of `1024`.\n\n### Bucket Configuration\n\nTo configure your buckets, simply place a `buckets.json` file in the `/startup` directory of your image.  This file should contain an array of bucket definition objects.\n\n```json\n[\n  {\n    \"name\": \"sample\",\n    \"ramQuotaMB\": 100,\n    \"bucketType\": \"couchbase\",\n    \"authType\": \"sasl\",\n    \"saslPassword\": \"\",\n    \"evictionPolicy\": \"fullEviction\",\n    \"replicaNumber\": 0,\n    \"flushEnabled\": 1\n  },\n  {\n    \"name\": \"default\",\n    \"ramQuotaMB\": 100,\n    \"bucketType\": \"couchbase\",\n    \"authType\": \"sasl\",\n    \"saslPassword\": \"\",\n    \"evictionPolicy\": \"fullEviction\",\n    \"replicaNumber\": 0,\n    \"flushEnabled\": 1\n  }\n]\n```\n\nAttribute names and values in this file correspond with the [Couchbase REST API create bucket endpoint](https://docs.couchbase.com/server/current/rest-api/rest-bucket-create.html).\n\nIf this file is not overridden in your image, it will create a single bucket named `default` with a RAM quota of 100MB.\n\n### Scopes and Collections\n\n**NOTE:** Only applicable for Couchbase Server 7+\n\nTo create scopes and collections, create a file underneath `/startup` with the name of your bucket, and a file with the following name: `collections.json`. For example, `/startup/sample/collections.json`. **Note** Names are case sensitive.\n\nThe format of the `collections.json` file should be as follows:\n\n```json\n{\n  \"scopes\": {\n    \"your_scope_name\": {\n      \"collections\": [\n        \"your_collection_name_1\",\n        \"your_collection_name_2\",\n        \"your_collection_name_3\"\n      ]\n    }\n  }\n}\n```\n\nThe values to replace are `your_scope_name` and the values in the `collections` array. **Note:** You can use the `_default` scope if you'd like by replacing `your_scope_name` with `_default`. The `_default` scope is automatically created in all buckets and cannot be deleted. You can add multiple scopes each having their own collections. For example:\n\n```json\n{\n  \"scopes\": {\n    \"_default\": {\n      \"collections\": [\n        \"default_collection_name_1\",\n        \"default_collection_name_2\"\n      ]\n    },\n    \"my_scope\": {\n      \"collections\": [\n        \"default_collection_name_1\",\n        \"default_collection_name_2\"\n      ]\n    }\n  }\n}\n```\n\n### RBAC Configuration\n\n To configure RBAC users for Couchbase Server versions 5+, simply place a `rbac-users.json` file in the `/startup` directory of your image. This file should be an array of JSON objects that define the various users and roles that need to be associated with each user. See the following example on how to structure the file:\n\n ```json\n[\n  {\n    \"rbacName\": \"App User\",\n    \"rbacUsername\": \"app-user\",\n    \"rbacPassword\": \"password\",\n    \"roles\": [\n      \"bucket_full_access[sample]\"\n    ]\n  },\n  {\n    ...\n  }\n]\n```\n\n Information on the available roles can be found [here](https://docs.couchbase.com/server/current/learn/security/roles.html). If you want to limit the role to a specific bucket, place the bucket name in brackets at the end of the name, i.e. `bucket_full_access[sample]`.\n\n### Generating Data With FakeIt\n\nTo generate data with FakeIt, create a directory underneath `/startup` with the name of your bucket, and directory beneath that named `models`.  For example, `/startup/sample/models`.  Note that the names are case sensitive.  Add your FakeIt YAML models to the models directory.\n\nFakeIt will be run using these models automatically during startup.\nYou may also include inputs, such as CSV files, in the image to be referenced by the models.\n\nThis process will be run before indexes are created so that index updates don't degrade the performance of the data inserts.\n\n### Creating Views\n\nTo create views, add a directory underneath `/startup` with the name of your bucket and a text file named `views.json`.  This file should be a JSON object with one or more design document specifications.  The name of each attribute should be the name of the design document.\n\n```json\n{\n  \"customers\": {\n    \"views\": {\n        \"CustomersByFirstName\": {\n            \"map\": \"function (doc, meta) {\\n  if ((doc.type === \\\"customer\\\") \u0026\u0026 doc.firstName) {\\n    emit(doc.firstName, null);\\n  }\\n}\"\n        }\n    }\n  }\n}\n```\n\nExamples of the syntax for design documents can be found [in the Couchbase documentation](https://developer.couchbase.com/documentation/server/current/rest-api/rest-ddocs-create.html).  Note that `views.json` has an extra nesting level above the Couchbase examples, as it supports more than one design document in a single file.\n\n### Creating Indexes\n\nTo create indexes, add a directory underneath `/startup` with the name of your bucket and a text file named `indexes.n1ql`.  For example, `/startup/default/indexes.n1ql`.  Note that the names are case sensitive.\n\nWithin this file, you can define the `CREATE INDEX` statements for your bucket, separated by semicolons.  It is recommended for performance to use `WITH {\"defer_build\": true}` for all indexes, and use a `BUILD INDEX` statement at the end of the file.\n\n```sql\nCREATE PRIMARY INDEX `#primary` ON default WITH {\"defer_build\": true};\nCREATE INDEX `Types` ON default (`type`) WITH {\"defer_build\": true};\nBUILD INDEX ON default (`#primary`, `Types`);\n```\n\n### Creating Indexes with YAML\n\nAlternatively, you may add YAML files with index definitions under the `/startup/\u003cbucketname\u003e/indexes` folder.  This operation uses [couchbase-index-manager](https://www.npmjs.com/package/couchbase-index-manager-cli) to create the indexes.  [See here](https://github.com/brantburnett/couchbase-index-manager/tree/master/packages/couchbase-index-manager-cli#definition-files) for an explanation of the YAML file format.\n\n### Analytics Dataset Setup\n\nTo setup the analytics service datasets, add a directory under the `/startup/\u003cbucketname\u003e/analytics` folder. Within this folder create a text file named `dataset.json`. For example, `/startup/default/analytics/dataset.json`.  Note that the names are case sensitive.\n\nWithin this file, create a key called `statements` with an array as the value. Within the array you can define your `CREATE DATAVERSE` and `CREATE DATASET` statements for your bucket, separated by semicolons. Below is an example showing what the `dataset.json` structure should look like. **IMPORTANT** Make sure to append the proper `USE` statement to each `CREATE DATASET` statement so that it's placed in the proper DATAVERSE. Additionaly, always end your file with a `CONNECT LINK Local;` statement.\n\n```json\n{\n  \"statements\": [\n    \"CREATE DATAVERSE `sample` IF NOT EXISTS;\",\n    \"USE `sample`; CREATE DATASET IF NOT EXISTS users ON `sample` WHERE `type` = 'user';\",\n    \"USE `sample`; CONNECT LINK Local;\"\n  ]\n}\n```\n\n### Creating Analytics Indexes\n\nTo create analytics indexes, add a directory under the `/startup/\u003cbucketname\u003e/analytics` folder.  Within this folder create a text file named `indexes.json`. For example, `/startup/default/analytics/indexes.json`.  Note that the names are case sensitive.\n\nWithin this file, create a key called `statements` with an array as the value. Within the array you can define your `CREATE INDEX` statements for your DATASET, separated by semicolons. **IMPORTANT** Make sure your queries always start with a `USE` statment otherwise the query engine will have no idea which DATAVERSE to associate the index with.\n\n```json\n{\n  \"statements\": [\n    \"USE `sample`; CREATE INDEX `idx_users` IF NOT EXISTS ON `users` (id: string);\"\n  ]\n}\n```\n\n### Creating Full Text Search Indexes\n\nTo create FTS indexes, add a directory underneath `/startup` with the name of your bucket, and underneath that a `fts` directory.  Within that, add a json file for each index, with the file name being the index name.  For example, `/startup/default/fts/my_index.json`.  Note that names are case sensitive.\n\nWithin this file, place the JSON index definition.  This can be easily exported from the Couchbase Console.\n\nTo create FTS index aliases, add an additional file in the same folder named `aliases.json`.  This file should be an object with each attribute being an alias name, and the value being an array of index names.\n\n```json\n{\n    \"my_alias\": [\"my_index\"],\n    \"my_second_alias\": [\"my_index_2\", \"my_index_3\"]\n}\n```\n\n### Creating Events\n\n[Couchbase Eventing](https://docs.couchbase.com/server/current/eventing/eventing-overview.html) allows\ndocument mutations from a bucket to be streamed, processed using Javascript, and outputs performed such\nas storing new documents in another bucket. CouchbaseFakeIt can create and deploy these events\nautomatically on startup.\n\nFirst, add a directory within your startup folder named `events`. Within this directory, add two files for\neach event you'd like to deploy.\n\n`event-name.json` will have configuration, specifically the `depcfg` configuration for source buckets,\nmetadata buckets, and buckets which may be referenced by the event. The `settings` attribute can also be\nused to override any settings, defaults apply for any excluded settings. An easy way to get these\nsettings is to manually configure an event and then get the definition from `http://localhost:8096/api/v1/functions`\n(use HTTP Basic Authentication).\n\n```json\n{\n  \"depcfg\": {\n    \"buckets\": [\n      {\n        \"alias\": \"dst\",\n        \"bucket_name\": \"default\",\n        \"access\": \"rw\"\n      }\n    ],\n    \"curl\": [],\n    \"metadata_bucket\": \"default\",\n    \"source_bucket\": \"sample\"\n  },\n  \"settings\": {\n    \"worker_count\": 3\n  }\n}\n```\n\nThe second file should have the same name but a `.js` extension, `event-name.js`. This file\ncontains the Javascript for the event.\n\n```js\nfunction OnUpdate(doc, meta) {\n  // This example event copies all documents from the \"example\" bucket to the \"default\" bucket\n\n  dst[meta.id] = doc;\n}\n\nfunction OnDelete(meta) {\n}\n```\n\nThe event will be automatically deployed once it is created with the \"Everything\" feed boundary.\nThis means that all documents in the source bucket should be processed by the event at startup,\nincluding any documents created from models. However, the `/nodestatus/initialized` file will be\ncreated before all documents are processed, as events are asynchronous in nature.\n\nAlso, note that by default logging will be set to the DEBUG level and each event will use only 1\nworker. This is because CouchbaseFakeIt is intended for local machine development or CI testing.\nThese settings can be overridden in the JSON file in the `settings` attribute.\n\n### Example\n\nAn example image configuration can be found [here](example/).\n\nTo run the example locally:\n\n1. Ensure that Couchbase Server is not currently running on your machine to avoid port conflicts\n2. `git clone https://github.com/brantburnett/couchbasefakeit.git`\n3. `cd couchbasefakeit/example`\n4. `docker-compose up -d`\n5. The server will be accessible at http://localhost:8091 after 15-30 seconds. The username is \"Administrator\", password is \"password\".\n\nTo shut down and cleanup:\n\n1. `docker-compose down`\n\nFor more detailed examples of FakeIt models, see https://github.com/bentonam/fakeit/tree/dev/test/fixtures/models.\n\n### Note on Community Edition\n\nIf you are using the Couchbase Server Community images, then note that configuration of enterprise features may cause your settings/configuration to fail.\n\nFor example:\n\n* Couchbase Server Community does not have Eventing. Therefore any json configuration files in the `events` folder may be ignored or may cause your configuration to fail.\n* Couchbase Server Community does not support `memory_optimized` index storage. Setting CB_INDEXSTORAGE to `memory_optimized` may be ignored or may cause your configuration to fail.\n\nFor more information: read about the [differences between Community and Enterprise editions](https://www.couchbase.com/products/editions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrantburnett%2Fcouchbasefakeit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrantburnett%2Fcouchbasefakeit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrantburnett%2Fcouchbasefakeit/lists"}