{"id":10275,"date":"2023-08-28T06:56:25","date_gmt":"2023-08-28T13:56:25","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/sync-gateway-setup\/"},"modified":"2023-08-28T06:56:25","modified_gmt":"2023-08-28T13:56:25","slug":"sync-gateway-setup","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/","title":{"rendered":"Set up Sync Gateway for use with Inventory Demo App"},"content":{"rendered":"\n<h3 id=\"h-introduction\" class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Couchbase Sync Gateway is a key component of the Couchbase Mobile stack. It is an Internet-facing synchronization mechanism that securely syncs data across devices as well as between devices and the cloud. Couchbase Mobile uses a websocket based <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/replication.html#replication-protocol%20\">replication protocol<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The core functions of the Sync Gateway include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data Synchronization across devices and the cloud<\/li>\n\n\n<li>Authorization &amp; Access Control<\/li>\n\n\n<li>Data Validation<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this part of our learning path, you will walk you through setting up Couchbase Server and Sync Gateway so that in future steps we can replicate documents from the mobile app to Couchbase Server and vice versa.  You will learn the fundamentals of:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installing Couchbase Server using Docker and Docker Compose<\/li>\n\n\n<li>Automation of Couchbase Server cluster setup and importing of data<\/li>\n\n\n<li>Installing Sync Gateway using Docker and Docker Compose<\/li>\n\n\n<li>Setup of a Sync Gateway configuration file<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this step of the learning path, we will be using docker and docker compose and should have both of these installed  before continuing.  <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/www.docker.com\/products\/docker-desktop\/\">Docker Desktop<\/a> provides these tools and UI for Mac, Windows, and Linux.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You might also want a text editor outside of Android Studio to review the docker and docker compose config files.  Any text editor will work including Android Studio, but for many developers Visual Studio Code is a good solution as it provides extensions for Docker config file formatting and YAML support, which is a file format Docker Compose uses.  You can download Visual Studio code <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/code.visualstudio.com\/download\">here<\/a>.  If you are using Visual Studio code make sure you install the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/code.visualstudio.com\/docs\/containers\/overview\">Docker extension<\/a>.  The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/redhat-developer\/vscode-yaml\">YAML Language Support<\/a> is another great extension that can be a major quality of life improvement if you use YAML files a lot.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>NOTE<\/strong>: This part of the learning path is longer than normal as there are several configuration files to review.  For developers looking to try out the containers without reviewing the configuration files, you can skip to the <a href=\"#try-it-out\">Try It Out<\/a> section.<\/p>\n<\/blockquote>\n\n\n\n<h3 id=\"h-review-setup-of-docker-containers\" class=\"wp-block-heading\">Review Setup of Docker Containers<\/h3>\n\n\n\n<h4 id=\"h-fetching-app-source-code\" class=\"wp-block-heading\">Fetching App Source Code<\/h4>\n\n\n\n<h5 id=\"h-clone-source-code\" class=\"wp-block-heading\">Clone Source Code<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you haven&#8217;t already cloned the repo from the previous steps, clone the <code>Learn Couchbase Lite with Kotlin and Jetpack Compose<\/code> repository from GitHub.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git clone https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path.git\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-couchbase-server-dockerfile\" class=\"wp-block-heading\">Couchbase Server &#8211; Dockerfile<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Docker and Docker Compose will be used to create a Couchbase Server container that has a one node cluster setup with a bucket, a user for sync gateway to perform replication between the sync gateway server and server, and indexes for the bucket.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is accomplished by creating a custom Dockerfile that defines the Couchbase Server base image along with a shell scripts to perform the automation of the Couchbase Server cluster setup and importing of sample data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/couchbase-server\/Dockerfile\">Dockerfile<\/a> found in the couchbase-server folder in the root of the repo in a text editor of your choice.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-docker\"><code>FROM couchbase:latest AS stage_base \nCOPY init-cbserver.sh \/opt\/couchbase\/init\/\nCOPY sample-data.json \/opt\/couchbase\/init\/\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The first line tells docker which docker container should be used as the <code>base<\/code> image for this container.  We are using the <code>couchbase:latest<\/code> image.  As of Couchbase Server 7.1 &#8211; ARM64 and X86 images are provided.<\/li>\n\n\n<li>Next it copies the init-cbserver.sh shell script into the containers \/opt\/couchbase\/init folder<\/li>\n\n\n<li>Finally it copies the sample-data.json file into the containers \/opt\/couchbase\/init folder<\/li>\n\n<\/ol>\n\n\n\n<h5 id=\"h-automation-using-shell-script\" class=\"wp-block-heading\">Automation using Shell Script<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Next open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/couchbase-server\/init-cbserver.sh\">init-cbserver.sh<\/a> file found in the same folder as the Dockerfile.  This shell script is well documented with comments before each line, however we will still go through the script from a high level.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>#!\/bin\/bash\n# used to start couchbase server - can&#039;t get around this as docker compose\n# only allows you to start one command - so we have to start couchbase like the Dockerfile would \n# https:\/\/github.com\/couchbase\/docker\/blob\/master\/enterprise\/couchbase-server\/7.1.1\/Dockerfile#L88\n\n\/entrypoint.sh couchbase-server &amp; \n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first line starts couchbase server just like the standard docker file would.  We need to do this because docker compose has a limit of only allowing one command\/entrypoint to run per container.  We need couchbase server to start before we can do our automated setup steps.<\/li>\n\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>NOTE<\/strong> Sleep statements make sure that things complete before moving on to the next step.  The 10-second delay is set after Couchbase Server is started to make sure the cluster is completely running before moving on to the next command.  The delay is conservative and could be shortened based on the speed of your computer.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>sleep 10s  \n\/opt\/couchbase\/bin\/couchbase-cli cluster-init -c 127.0.0.1 \n--cluster-username $COUCHBASE_ADMINISTRATOR_USERNAME \n--cluster-password $COUCHBASE_ADMINISTRATOR_PASSWORD \n--services data,index,query \n--cluster-ramsize $COUCHBASE_RAM_SIZE \n--cluster-index-ramsize $COUCHBASE_INDEX_RAM_SIZE \n--index-storage-setting default\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The couchbase-cli tool is used to initialize the cluster and will set the administration username, password, and services along with the index configuration based on environment variables that are set in the docker compose file we will look at in a bit.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/opt\/couchbase\/bin\/couchbase-cli bucket-create -c localhost:8091 \n--username $COUCHBASE_ADMINISTRATOR_USERNAME \n--password $COUCHBASE_ADMINISTRATOR_PASSWORD \n--bucket $COUCHBASE_BUCKET \n--bucket-ramsize $COUCHBASE_BUCKET_RAMSIZE \n--bucket-type couchbase \n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The couchbase-cli tool is used again, but this time to create a bucket bsaed on the environment variables that are set in the docker compose file<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/opt\/couchbase\/bin\/couchbase-cli user-manage \n--cluster http:\/\/127.0.0.1 \n--username $COUCHBASE_ADMINISTRATOR_USERNAME \n--password $COUCHBASE_ADMINISTRATOR_PASSWORD \n--set \n--rbac-username $COUCHBASE_RBAC_USERNAME \n--rbac-password $COUCHBASE_RBAC_PASSWORD \n--roles mobile_sync_gateway[*] \n--auth-domain local\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The couchbase-cli tool is used to create a new user that can be used for sync gateway to connect to the server and replicate documents.   The roles switch sets the role for sync gateway and the [*] defines that this user has access to all buckets for sync gateway.  Note this could be a security risk in non-development environments and is set like this for sake of simplicity.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/opt\/couchbase\/bin\/curl -v http:\/\/localhost:8093\/query\/service \n  -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD \n  -d &#039;statement=CREATE INDEX idx_projects_team on projects(team)&#039;\n      \nsleep 2s\n\n\/opt\/couchbase\/bin\/curl -v http:\/\/localhost:8093\/query\/service \n  -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD \n  -d &#039;statement=CREATE INDEX idx_projects_type on projects(type)&#039;\n      \nsleep 2s\n\n\/opt\/couchbase\/bin\/curl -v http:\/\/localhost:8093\/query\/service \n  -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD \n  -d &#039;statement=CREATE INDEX idx_projects_projectId on projects(projectId)&#039;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The next three commands use the REST API to add indexes in for queries that you could use in the web console Query.  These aren&#8217;t required for the mobile app or sync, but are nice to have when validating data.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/opt\/couchbase\/bin\/cbimport json --format list \n  -c http:\/\/localhost:8091 \n  -u $COUCHBASE_ADMINISTRATOR_USERNAME \n  -p $COUCHBASE_ADMINISTRATOR_PASSWORD \n  -d &quot;file:\/\/\/opt\/couchbase\/init\/sample-data.json&quot; -b &#039;projects&#039; -g %projectId%\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>cbimport is used to import data from a file into a bucket.  In this command we are telling it that we are going to use the file we copied into the the container and that the documentId should be set from the projectId property inside the document.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-sync-gateway-dockerfile\" class=\"wp-block-heading\">Sync Gateway &#8211;  Dockerfile<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have reviewed how the Couchbase Server will be created, let&#8217;s review how the Sync Gateway server will be created.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/sync-gateway\/Dockerfile\">Dockerfile<\/a> found in the sync-gateway folder in the root of the repo in a text editor of your choice.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>FROM couchbase\/sync-gateway:latest AS stage_base\nCOPY sync-gateway.json \/etc\/sync_gateway\/config.json\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The first line tells docker which docker container should be used as the <code>base<\/code> image for this container.  We are using the <code>sync-gateway:latest<\/code> image.<\/li>\n\n\n<li>Next it copies the sync-gateway.json config file into the containers \/etc\/sync_gateway folder and renames it to config.json which Sync Gateway reads in by default when starting.<\/li>\n\n<\/ol>\n\n\n\n<h5 id=\"h-sync-gateway-config-file-overview\" class=\"wp-block-heading\">Sync Gateway Config File Overview<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The Sync Gateway server uses a configuration file when it starts to load in all important settings.  In the demo app, this file is setup in <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html\">Legacy Pre-3.0 Configuration<\/a> for sake of simplicity.  Let&#8217;s review the configuration file by sections.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/sync-gateway\/sync-gateway.json\">sync-gateway.json<\/a> config file found in the same folder as the Dockerfile.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>\t&quot;interface&quot;:&quot;:4984&quot;,\n\t&quot;adminInterface&quot;:&quot;:4985&quot;,\n\t&quot;log&quot;: [&quot;*&quot;],\n\t&quot;logging&quot;: {\n\t  &quot;log_file_path&quot;: &quot;\/var\/tmp\/sglogs&quot;,\n\t  &quot;console&quot;: {\n\t\t&quot;log_level&quot;: &quot;debug&quot;,\n\t\t&quot;log_keys&quot;: [&quot;*&quot;]\n\t  },\n\t  &quot;error&quot;: {\n\t\t&quot;enabled&quot;: true,\n\t\t&quot;rotation&quot;: {\n\t\t  &quot;max_size&quot;: 20,\n\t\t  &quot;max_age&quot;: 180\n\t\t}\n\t  },\n\t  &quot;warn&quot;: {\n\t\t&quot;enabled&quot;: true,\n\t\t&quot;rotation&quot;: {\n\t\t  &quot;max_size&quot;: 20,\n\t\t  &quot;max_age&quot;: 90\n\t\t}\n\t  },\n\t  &quot;info&quot;: {\n\t\t&quot;enabled&quot;: false\n\t  },\n\t  &quot;debug&quot;: {\n\t\t&quot;enabled&quot;: false\n\t  }\n\t},\n\t&quot;disable_persistent_config&quot;:true,\n\t&quot;server_tls_skip_verify&quot;: true,\n\t&quot;use_tls_server&quot;: false,\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#Interface%20\">interface<\/a> and <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#adminInterface%20\">adminInterface<\/a> are used to define which ports that Sync Gateway will run on.  Note if you change the default values, you will also need to update your mobile app&#8217;s replication configuration.<\/li>\n\n\n<li>log and <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#logging\">logging<\/a> set up the logging configuration.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#disable_persistent_config\">disable_persistent_config<\/a> is required to run in <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html\">Legacy Pre-3.0 Configuration<\/a> mode<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#server_tls_skip_verify\">server_tls_skip_verify<\/a> is set to true because the Couchbase Server container is not using TLS in it&#8217;s configuration.  <strong>NOTE<\/strong>:  DO NOT run with TLS disabled in production!<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#use_tls_server\">use_tls_server<\/a> is set to false so that the mobile app can communicate with the Sync Gateway server over HTTP instead of HTTPS.  This is for the sake of simpliciy.  <strong>NOTE<\/strong>:  DO NOT run with TLS disabled in production!<\/li>\n\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>:  To use TLS with something like self-signed certificates would greatly increase the complexity and length of this tutorial.  For this reason the tutorial shows the configuration without certificates.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>&quot;databases&quot;: {\n &quot;projects&quot;: {\n  &quot;import_docs&quot;: true,\n  &quot;bucket&quot;:&quot;projects&quot;,\n  &quot;server&quot;: &quot;couchbase:\/\/couchbase-server&quot;,\n  &quot;enable_shared_bucket_access&quot;:true,\n  &quot;delta_sync&quot;: {\n    &quot;enabled&quot;:false\n  },\n  &quot;num_index_replicas&quot;:0,\n  &quot;username&quot;: &quot;admin&quot;,\n  &quot;password&quot;: &quot;P@$$w0rd&quot;,\n &quot;users&quot;: { \n\t\t &quot;demo@example.com&quot;:  { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team1&quot;] },\n\t\t &quot;demo1@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team1&quot;] },\n\t\t &quot;demo2@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team2&quot;] },\n\t\t &quot;demo3@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team2&quot;] },\n\t\t &quot;demo4@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team3&quot;] },\n\t\t &quot;demo5@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team3&quot;] },\n\t\t &quot;demo6@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team4&quot;] },\n\t\t &quot;demo7@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team4&quot;] },\n\t\t &quot;demo8@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team5&quot;] },\n\t\t &quot;demo9@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team5&quot;] },\n\t\t &quot;demo10@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team6&quot;] },\n\t\t &quot;demo11@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team6&quot;] },\n\t\t &quot;demo12@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team7&quot;] },\n\t\t &quot;demo13@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team8&quot;] },\n\t\t &quot;demo14@example.com&quot;: { &quot;password&quot;: &quot;P@ssword12&quot;, &quot;admin_roles&quot;: [&quot;team9&quot;] },\n\t\t &quot;demo15@example.com&quot;: { &quot;password&quot;: &quot;P@ssw0rd12&quot;, &quot;admin_roles&quot;: [&quot;team10&quot;] }\n\t\t},\n\t\t&quot;roles&quot;: {\n\t\t  &quot;team1&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team1&quot; ] },\n\t\t  &quot;team2&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team2&quot; ] },\n\t\t  &quot;team3&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team3&quot; ] },\n\t\t  &quot;team4&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team4&quot; ] },\n\t\t  &quot;team5&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team5&quot; ] },\n\t\t  &quot;team6&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team6&quot; ] },\n\t\t  &quot;team7&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team7&quot; ] },\n\t\t  &quot;team8&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team8&quot; ] },\n\t\t  &quot;team9&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team9&quot; ] },\n\t\t  &quot;team10&quot;: { &quot;admin_channels&quot;: [ &quot;channel.team10&quot; ] }\n\t\t},\n\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases\">databases<\/a>  sets up the configuration for communication between Sync Gateway and Couchbase Server.<\/li>\n\n\n<li>projects is the configuration section for the projects bucket that Sync Gateway will be replicating.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases\">import_docs<\/a> set to true allows Sync Gateway to import documents that exists on Couchbase Server.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-bucket\">bucket<\/a> is the name of the bucket that Sync Gateway will replicate with on Couchbase Server.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-server\">server<\/a> is the connection string to connect to the Couchbase Server.  The name of the server is defined in the Docker Compose file and dockers internal DNS will handle name resolution to this hostname.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-enable_shared_bucket_access\">enable_shared_bucket_access<\/a> enables Mobile-Server Data Sync (a.ka. mobile convergence), which will generate the mobile-specific metadata for all the preexisting documents in the Couchbase Server bucket.  You can learn more about this functionality in <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-with-couchbase-server.html\">Syncing Mobile and Server<\/a> documentation.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-delta_sync\">delta_sync<\/a> is an Enterprise Edition feature which requires a license.  Delta Sync allows Sync Gateway to replicate only the parts of the Couchbase Mobile document that have changed.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-num_index_replicas\">num_index_replicas<\/a> determines the number of index replicas used when creating the core Sync Gateway indexes.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-replications-this_rep-username\">username<\/a> Sync Gateway uses to connect to the Couchbase Server.  This username was created in the automation shell script step.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-password\">password<\/a> is the password that Sync Gateway will use to communicate with Couchbase Server.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-users\">users<\/a> is a hard coded collection of username, passwords and the role that the user is assigned to.  Roles can be assigned to channels to which documents are assigned to in the sync process, restricting the documents that are replicated.  Note that these username and passwords are the same username and passwords that are hard coded into the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/src\/app\/src\/main\/java\/com\/couchbase\/learningpath\/services\/MockAuthenticationService.kt#L36\">MockAuthenticationService<\/a> in the mobile app.<\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html#databases-this_db-roles\">roles<\/a> a collection of roles used to map the roles to the channels they have access to.  This is used in the sync function to map roles to channels.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The next part of the configuration is the import_filter.  The import_filter is a string value of Javascript code that controls whether a document written to the Couchbase Server bucket should be made available to Couchbase Mobile clients.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code> function(doc){\n  console.log(&quot;********Processing import filter - documents from couchbase server&quot;);\n  if (doc.type == &#039;project&#039; \n    || doc.type == &#039;location&#039; \n    || doc.type == &#039;user&#039; \n    || . doc.type == &#039;audit&#039;){\n\t return true;\n  }\n  return false;\n }\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The function takes the document body as parameter and is expected to return a boolean to indicate whether the document should be imported.<\/li>\n\n\n<li>The type attribute is used to only import documents of type: project, location, user, and audit.<\/li>\n\n\n<li>Any document without one of these four types set will not be imported from Couchbase Server to Sync Gateway for replication to mobile clients.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The sync section of the configuration is used to define custom business logic.  The sync is a string value of Javascript code that will run every time a new document, revision, or deletion is added to a database.  The sync function will examine the document and custom business logic can then calculate things like access control to limit which users can see which documents.  The demo app is a simple example of custom business logic.  See the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-function-api.html\">Sync Function API<\/a> and <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/access-control-how.html\">Access Control How-To<\/a> guides for more detailed information and a listing of other API functions available.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>function sync(doc, oldDoc) {  \/\/ &lt;1&gt;\n \/* Data Validation *\/\n validateNotEmpty(&quot;type&quot;, doc.type);  \/\/ &lt;2&gt;\n\n if (doc.type == &#039;location&#039;){  \/\/ &lt;3&gt;\n  console.log(&quot;********Processing Location Docs - setting it to global\/public&quot;);\n  channel(&#039;!&#039;);  \/\/ &lt;3&gt;\n } else { \/\/ &lt;4&gt;\n  console.log(&quot;********Processing Team Docs&quot;);\n  validateNotEmpty(&quot;team&quot;, doc.team); \/\/ &lt;5&gt;\n  if (!isDelete()) {  \/\/ &lt;6&gt;\n   \/* Routing  -- add channel routing rules here for document *\/\n   var team = getTeam(); \/\/ &lt;7&gt;\n   var channelId = &quot;channel.&quot; + team; \/\/ &lt;8&gt;\n   console.log(&quot;********Setting Channel to &quot; + channelId);\n   channel(channelId);  \/\/ &lt;9&gt;\n\n   \/* Authorization  - Access Control *\/\n   requireRole(team); \/\/ &lt;10&gt;\n   access(&quot;role:team1&quot;, &quot;channel.team1&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team2&quot;, &quot;channel.team2&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team3&quot;, &quot;channel.team3&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team4&quot;, &quot;channel.team4&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team5&quot;, &quot;channel.team5&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team6&quot;, &quot;channel.team6&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team7&quot;, &quot;channel.team7&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team8&quot;, &quot;channel.team8&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team9&quot;, &quot;channel.team9&quot;); \/\/ &lt;11&gt;\n   access(&quot;role:team10&quot;, &quot;channel.team10&quot;); \/\/ &lt;11&gt;\n  }\n }\n \/\/ get type property\n function getType() {\n  return (isDelete() ? oldDoc.type : doc.type);\n }\n \/\/ get email Id property\n function getTeam() {\n  return (isDelete() ? oldDoc.team : doc.team);\n }\n \/\/ Check if document is being created\/added for first time\n function isCreate() {\n  \/\/ Checking false for the Admin UI to work\n  return ((oldDoc == false) || (oldDoc == null || oldDoc._deleted) &amp;&amp; !isDelete());\n }\n \/\/ Check if this is a document delete\n function isDelete() {\n  return (doc._deleted == true);\n }\n \/\/ Verify that specified property exists\n function validateNotEmpty(key, value) {\n if (!value) {\n  throw({forbidden: key + &quot; is not provided.&quot;});\n  }\n }\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The sync function parameters allow acces to the current document and previous document (if it&#8217;s a revision) and all it&#8217;s properties.<\/li>\n\n\n<li>validateNotEmpty is a custom function that is called to inspect the doc and validate a property exists and a value is set in it.  This is used to make sure we always have the &#8220;type&#8221; attribute that we can run business logic against.<\/li>\n\n\n<li>The doc.type attribute is checked to filter out documents of type location.  In previous parts of the learning path we used a pre-built database to start the database with location documents.  This allows for new locations to be added from Couchbase Server without having to update the pre-built database.  If the document type is location, passing in a <code>!<\/code> to the channel function will make the document global and giving all users access to the document.<\/li>\n\n\n<li>The else statement is used to catch all other document types.<\/li>\n\n\n<li>The validateNotEmpty function is used again, this time to make sure the document has an assigned team to it.  This attribute will be used to control access to the document.<\/li>\n\n\n<li>The isDelete function call checks the document to see if it&#8217;s mark for deletion and is used to skip those documents.<\/li>\n\n\n<li>The getTeam function will get the current team assigned to the document.<\/li>\n\n\n<li>The channelId varible is set to a string value of channel plus the current team assigned to the document.<\/li>\n\n\n<li>The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-function-api.html#lbl-channel\">channel<\/a> function is called to route the document to the named channel.<\/li>\n\n\n<li>The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-function-api.html#lbl-require-role\">requireRole<\/a> function is used to reject updates that are not made by user with the specified role or roles.<\/li>\n\n\n<li>The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-function-api.html#lbl-access\">access<\/a> function grants a user access to a given channel.<\/li>\n\n<\/ol>\n\n\n\n<h4 id=\"h-docker-compose-yaml-file\" class=\"wp-block-heading\">Docker Compose YAML file<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/docker-compose.yml\">docker-compose.yml<\/a> file is provide to configure and build the Couchbase Server and Sync Gateway containers that we have reviewed.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/couchbase-examples\/android-kotlin-cbl-learning-path\/blob\/main\/docker-compose.yml\">docker-compose.yml<\/a> found in the root of the repo in a text editor of your choice.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-yaml\"><code>  couchbase-server:\n    build: .\/couchbase-server\n    ports:\n     - 8091-8096:8091-8096\n     - 11210:11210\n    environment:  \n      - CLUSTER_NAME=couchbase-demo\n      - COUCHBASE_ADMINISTRATOR_USERNAME=Administrator\n      - COUCHBASE_ADMINISTRATOR_PASSWORD=P@$$w0rd12\n      - COUCHBASE_BUCKET=projects\n      - COUCHBASE_BUCKET_RAMSIZE=512\n      - COUCHBASE_RBAC_USERNAME=admin\n      - COUCHBASE_RBAC_PASSWORD=P@$$w0rd\n      - COUCHBASE_RBAC_NAME=admin\n      - COUCHBASE_RAM_SIZE=2048\n      - COUCHBASE_INDEX_RAM_SIZE=512\n    hostname: couchbase-server\n    container_name: couchbase-server\n    working_dir: \/opt\/couchbase\n    stdin_open: true\n    tty: true      \n    networks:\n      - workshop\n    entrypoint: [&quot;&quot;]\n    command: sh -c &quot;\/opt\/couchbase\/init\/init-cbserver.sh&quot;\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The couchbase-server section is used to define the couchbase server container.<\/li>\n\n\n<li>The build property defines what directory to look for the Dockerfile in<\/li>\n\n\n<li>The ports collection defines the ports that Couchbase Server requires to run<\/li>\n\n\n<li>The environment collection defines a set of environment variables that we use in our automation shell script to setup Couchbase Server<\/li>\n\n\n<li>The hostname defines what name should be used for DNS resolution<\/li>\n\n\n<li>The working directory will be used for all commands ran.  We default this to \/opt\/couchbase since our automation script and data import file are located in this directory<\/li>\n\n\n<li>The network is set to workshop which will define a bridge or shared network that can be used to allow the Couchbase Server to communicate with the Sync Gateway server<\/li>\n\n\n<li>The entrypoint property is set to blank and overridden with a command since we want to run our custom automation script when the container is built.<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-yaml\"><code>  sync-gateway:\n    build: .\/sync-gateway\n    ports:\n      - 4984-4986:4984-4986\n    hostname: sync-gateway\n    container_name: sync-gateway\n    depends_on:\n      - couchbase\n    working_dir: \/docker-syncgateway\n    stdin_open: true\n    tty: true      \n    networks:\n      - workshop\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The sync-gateway section is used to define the sync gateway server container.<\/li>\n\n\n<li>The build property defines what directory to look for the Dockerfile in<\/li>\n\n\n<li>The ports collection defines the ports that Sync Gateway requires to run<\/li>\n\n\n<li>The hostname defines what name should be used for DNS resolution<\/li>\n\n\n<li>The network is set to workshop which will define a bridge or shared network that can be used to allow the Couchbase Server to communicate with the Sync Gateway server<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we define the network configuration and driver to use.<\/p>\n\n\n\n<pre class=\"wp-block-code language-yaml\"><code>networks:\n  workshop:\n    driver: bridge\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-try-it-out\" class=\"wp-block-heading\">Try it out<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have reviewed all the files that are used to create the containers, open a terminal window or command prompt depending on your platform of choice.<\/p>\n\n\n\n<h5 id=\"h-windows-mac-and-linux-users\" class=\"wp-block-heading\">Windows, Mac, and Linux users<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">If you are running in Mac or standard PC laptop with Windows or Linux on it you can follow the directions below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make sure you are in the root directory of the repo<\/li>\n\n\n<li>Run the docker-compose command<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker-compose up -d\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>The docker containers should start downloading, then build, and finally start up<\/p>\n<\/li>\n\n\n<li>\n<p>You can check the status of docker using either Docker Desktop or the terminal commands.<\/p>\n<\/li>\n\n\n<li>\n<p>Docker Desktop Users should see a container listing after launching the app.  The group name of the containers is the name of the directory of the code repo on your computer where you ran docker compose. In the example it&#8217;s named <code>android-kotlin-cbl-learning-path<\/code>.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"docker-desktop.png\" alt=\"Docker Desktop\" title=\"#width=600px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terminal users can use the docker-compose command to see the containers status<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker-compose ls\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"docker-compose-ls.png\" alt=\"Docker Compose Terminal \" title=\"#width=800px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To see individual containers you can use the docker command<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker container ls\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"docker-ls.png\" alt=\"Docker Terminal \" title=\"#width=800px\"><\/p>\n\n\n\n<h5 id=\"h-validation-of-containers\" class=\"wp-block-heading\">Validation of Containers<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Docker Desktop Users can select each container in Docker Desktop to get detained information and logs about the container running to validate the containers were built properly or use the terminal to gather information.<\/p>\n<\/li>\n\n\n<li>\n<p>Docker Desktop Users &#8211; select the couchbase-server container.  You should see logging information.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"docker-couchbase-server-logs.png\" alt=\"Docker Desktop\" title=\"#width=800px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terminal users can enter the following command<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker container logs couchbase-server\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The logs should show the status of cluster initialization, bucket creation, and User admin.  This will be followed by the resutls of the curl commands that create the indexes, and finally a message on the status of importing data.  When the setup is complete, you should see output similar to that shown below:<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-logs\"><code>Administrator : P@$w0rd12\nStarting Couchbase Server -- Web UI available at http:\/\/&lt;ip&gt;:8091\nand logs available in \/opt\/couchbase\/var\/lib\/couchbase\/logs\n\nSUCCESS: Cluster initialized\nSUCCESS: Bucket created\nSUCCESS: User admin set\n\n*   Trying 127.0.0.1:8093...\n* Connected to localhost (127.0.0.1) port 8093 (#0)\n* Server auth using Basic with user &#039;Administrator&#039;\n&gt; POST \/query\/service HTTP\/1.1\n&gt; Host: localhost:8093\n&gt; Authorization: Basic QWRtaW5pc3RyYXRvcjpQQCR3MHJkMTI=\n&gt; User-Agent: curl\/7.78.0-DEV\n&gt; Accept: *\/*\n&gt; Content-Length: 58\n&gt; Content-Type: application\/x-www-form-urlencoded\n&gt; \n* Mark bundle as not supporting multiuse\n&lt; HTTP\/1.1 200 OK\n&lt; Content-Length: 238\n&lt; Content-Type: application\/json; version=7.1.0-N1QL\n&lt; Date: Thu, 05 May 2022 16:29:41 GMT\n&lt; \n{\n&quot;requestID&quot;: &quot;fd7ead5a-15bb-449b-ae64-c5f416186267&quot;,\n&quot;signature&quot;: null,\n&quot;results&quot;: [\n],\n&quot;status&quot;: &quot;success&quot;,\n&quot;metrics&quot;: {&quot;elapsedTime&quot;: &quot;1.682457959s&quot;,&quot;executionTime&quot;: &quot;1.682413042s&quot;,&quot;resultCount&quot;: 0,&quot;resultSize&quot;: 0,&quot;serviceLoad&quot;: 5}\n}\n\n* Connection #0 to host localhost left intact\n*   Trying 127.0.0.1:8093...\n* Connected to localhost (127.0.0.1) port 8093 (#0)\n* Server auth using Basic with user &#039;Administrator&#039;\n&gt; POST \/query\/service HTTP\/1.1\n&gt; Host: localhost:8093\n&gt; Authorization: Basic QWRtaW5pc3RyYXRvcjpQQCR3MHJkMTI=\n&gt; User-Agent: curl\/7.78.0-DEV\n&gt; Accept: *\/*\n&gt; Content-Length: 58\n&gt; Content-Type: application\/x-www-form-urlencoded\n&gt; \n* Mark bundle as not supporting multiuse\n&lt; HTTP\/1.1 200 OK\n&lt; Content-Length: 236\n&lt; Content-Type: application\/json; version=7.1.0-N1QL\n&lt; Date: Thu, 05 May 2022 16:29:46 GMT\n&lt; \n{\n&quot;requestID&quot;: &quot;80880668-04f1-4970-815c-88e533399855&quot;,\n&quot;signature&quot;: null,\n&quot;results&quot;: [\n],\n&quot;status&quot;: &quot;success&quot;,\n&quot;metrics&quot;: {&quot;elapsedTime&quot;: &quot;2.67268896s&quot;,&quot;executionTime&quot;: &quot;2.67262546s&quot;,&quot;resultCount&quot;: 0,&quot;resultSize&quot;: 0,&quot;serviceLoad&quot;: 5}\n}\n\n* Connection #0 to host localhost left intact\n*   Trying 127.0.0.1:8093...\n* Connected to localhost (127.0.0.1) port 8093 (#0)\n* Server auth using Basic with user &#039;Administrator&#039;\n&gt; POST \/query\/service HTTP\/1.1\n&gt; Host: localhost:8093\n&gt; Authorization: Basic QWRtaW5pc3RyYXRvcjpQQCR3MHJkMTI=\n&gt; User-Agent: curl\/7.78.0-DEV\n&gt; Accept: *\/*\n&gt; Content-Length: 68\n&gt; Content-Type: application\/x-www-form-urlencoded\n&gt; \n* Mark bundle as not supporting multiuse\n&lt; HTTP\/1.1 200 OK\n&lt; Content-Length: 238\n&lt; Content-Type: application\/json; version=7.1.0-N1QL\n&lt; Date: Thu, 05 May 2022 16:29:50 GMT\n&lt; \n{\n&quot;requestID&quot;: &quot;ad9a5337-53ac-4f02-bfda-6c1d0bda1c5a&quot;,\n&quot;signature&quot;: null,\n&quot;results&quot;: [\n],\n&quot;status&quot;: &quot;success&quot;,\n&quot;metrics&quot;: {&quot;elapsedTime&quot;: &quot;2.566747917s&quot;,&quot;executionTime&quot;: &quot;2.566666001s&quot;,&quot;resultCount&quot;: 0,&quot;resultSize&quot;: 0,&quot;serviceLoad&quot;: 5}\n}\n\n* Connection #0 to host localhost left intact\nJSON `file:\/\/\/opt\/couchbase\/init\/sample-data.json` imported to `http:\/\/localhost:8091` successfully\n\nDocuments imported: 9 Documents failed: 0\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker Desktop Users &#8211; click the back button and now select the sync-gateway container.  You should see logging information.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"docker-sync-gateway-logs.png\" alt=\"Docker Desktop\" title=\"#width=800px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terminal users can enter the following command<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker container logs sync-gateway \n<\/code><\/pre>\n\n\n\n<h5 id=\"h-validate-couchbase-server-with-administration-console\" class=\"wp-block-heading\">Validate Couchbase Server with Administration Console<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Open your web browser of choice and navigate to the following URL:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/localhost:8091\/\">http:\/\/localhost:8091\/<\/a><\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Log into the portal using the same username and password that was displayed in the top of the Couchbase Server docker logs:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Username:  <strong>Administrator<\/strong><\/p>\n<\/li>\n\n\n<li>\n<p>Password:  <strong>P@$w0rd12<\/strong><\/p>\n<\/li>\n\n\n<li>\n<p>From the Cluster &gt; Dashboard page click on Buckets link on the navigation menu on the left side of the screen.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"cbserver-buckets-details.png\" alt=\"Docker Desktop\" title=\"#width=800px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click on the Documents link to open the Document browser<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"cbserver-document-browser.png\" alt=\"Docker Desktop\" title=\"#width=800px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click on the edit documents button on one of the listed documents, which is the first button in the list and is highlighted in the screen shot above<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"document-sync-metadata.png\" alt=\"Docker Desktop\" title=\"#width=400px\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click the Metadata button.  You should now see the metadata associated with the document.<\/li>\n\n\n<li>Sync Gateway will modify this metadata with revision and channel access information<\/li>\n\n\n<li>This metadata is <strong>READ-ONLY<\/strong> and can NOT be modified from this interface<\/li>\n\n<\/ul>\n\n\n\n<h5 id=\"h-validate-sync-gateway-server\" class=\"wp-block-heading\">Validate Sync Gateway Server<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">To validate the Sync Gateway server we will use the REST API interface.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open up <a href=\"http:\/\/localhost:4984\">http:\/\/localhost:4984<\/a> in your web browser.  You should see equivalent of the following message:<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>{&quot;couchdb&quot;:&quot;Welcome&quot;,&quot;vendor&quot;:{&quot;name&quot;:&quot;Couchbase Sync Gateway&quot;,&quot;version&quot;:&quot;3.0&quot;},&quot;version&quot;:&quot;Couchbase Sync Gateway\/3.0.0(541;46803d1) EE&quot;}\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-learn-more\" class=\"wp-block-heading\">Learn More<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations on completing this step of the learning path!  In this section, we walked through how to use Docker Compose and Docker Desktop to build and start a container running Couchbase Server and a container runnnig Sync Gateway.   Continue on to the next step to learn how to setup replication to sync information between the mobile demo app and Sync Gateway to Couchbase Server.<\/p>\n\n\n\n<h4 id=\"h-references\" class=\"wp-block-heading\">References<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/android\/replication.html\">Documentation: Data Sync using Sync Gateway<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-overview.html\">Documentation: Sync Gateway Configuration Overview<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-properties-legacy.html\">Documentation:  Legacy Pre-3.0 Configuration<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-schema-import-filter.html\">Documentation:  Import Filter Configuration<\/a><\/li>\n\n\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/configuration-javascript-functions.html\">Documentation:  Using External Javascript Functions<\/a><\/li>\n\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Couchbase Sync Gateway is a key component of the Couchbase Mobile stack. It is an Internet-facing synchronization mechanism that securely syncs data across devices as well as between devices and the cloud. Couchbase Mobile uses a websocket based replication protocol. The core functions of the Sync Gateway include: In this part of our learning [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[595,586,593],"tutorial-tags":[556],"tutorial-technologies":[585],"tutorial-types":[555],"class_list":["post-10275","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-android-java","tutorial-languages-kotlin","tutorial-languages-objective-c","tutorial-tags-docker","tutorial-technologies-mobile","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Set up Sync Gateway for use with Inventory Demo App - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set up Sync Gateway for use with Inventory Demo App\" \/>\n<meta property=\"og:description\" content=\"Introduction Couchbase Sync Gateway is a key component of the Couchbase Mobile stack. It is an Internet-facing synchronization mechanism that securely syncs data across devices as well as between devices and the cloud. Couchbase Mobile uses a websocket based replication protocol. The core functions of the Sync Gateway include: In this part of our learning [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"23 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/developers\\\/tutorials\\\/sync-gateway-setup\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/developers\\\/tutorials\\\/sync-gateway-setup\\\/\",\"name\":\"Set up Sync Gateway for use with Inventory Demo App - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#website\"},\"datePublished\":\"2023-08-28T13:56:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/developers\\\/tutorials\\\/sync-gateway-setup\\\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/developers\\\/tutorials\\\/sync-gateway-setup\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/developers\\\/tutorials\\\/sync-gateway-setup\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Set up Sync Gateway for use with Inventory Demo App\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/pt\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Set up Sync Gateway for use with Inventory Demo App - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/","og_locale":"pt_BR","og_type":"article","og_title":"Set up Sync Gateway for use with Inventory Demo App","og_description":"Introduction Couchbase Sync Gateway is a key component of the Couchbase Mobile stack. It is an Internet-facing synchronization mechanism that securely syncs data across devices as well as between devices and the cloud. Couchbase Mobile uses a websocket based replication protocol. The core functions of the Sync Gateway include: In this part of our learning [&hellip;]","og_url":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"23 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/","url":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/","name":"Set up Sync Gateway for use with Inventory Demo App - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/pt\/#website"},"datePublished":"2023-08-28T13:56:25+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/pt\/developers\/tutorials\/sync-gateway-setup\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Set up Sync Gateway for use with Inventory Demo App"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/pt\/#website","url":"https:\/\/www.couchbase.com\/pt\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/pt\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/pt\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/pt\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/pt\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/pt\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/pt\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"A Couchbase \u00e9 uma empresa de software de banco de dados com sede em San Jose, Calif\u00f3rnia, que fornece uma plataforma de dados operacional para a intelig\u00eancia artificial utilizada por centenas de empresas globais.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorials\/10275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorials\/10275\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/media?parent=10275"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorial-languages?post=10275"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorial-tags?post=10275"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorial-technologies?post=10275"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/pt\/wp-json\/wp\/v2\/tutorial-types?post=10275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}