Commit f3ea246d authored by Mo Firouz's avatar Mo Firouz Committed by Chris Molozian
Browse files

Run Nakama (and cockroachdb) in Docker. (#23)

parent 10df93b1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).

## [Unreleased]
### Added
- Include Dockerfile and Docker instructions.

## [0.11.1] - 2017-02-12
### Changed
+12 −0
Original line number Diff line number Diff line
@@ -22,6 +22,18 @@ $> nakama
[I] Startup done
```

### Run Nakama with Docker

Follow the [guide](https://heroiclabs.com/docs/setup/docker) to run Nakama (and CockroachDB) in Docker.

<a href="https://heroiclabs.com/docs/setup/docker"><img src="https://upload.wikimedia.org/wikipedia/commons/7/79/Docker_%28container_engine%29_logo.png" width="170"></a>

Nakama Docker images are available on [Docker Hub](http://hub.docker.com/r/heroiclabs/nakama/). If you'd like to publish your own Docker image have a look at our [Docker README](https://github.com/heroiclabs/nakama/blob/mhf-docker/install/docker/README.md).

#### Deploy Nakama with Docker Cloud

Nakama can be deployed to any cloud with Docker Cloud such as AWS, Google Cloud, Azure, Digital Ocean or your own private cloud. You'll need to setup Docker Cloud and provision separate nodes for Nakama and CockroachDB.

### Contribute

To build the codebase you will need to install these dependencies:
+78 −0
Original line number Diff line number Diff line
## Run Nakama with Docker

You'll need to setup `docker-compose` as [described by Docker](https://docs.docker.com/engine/installation/) for this guide.

It's recommended to run Nakama and the database (cockroachdb) as separate containers and connect them together via Docker's virtual network on the host machine. This guide will show you how to install and configure all resources together so it can be run in a single step.

1. Save the [`docker-compose.yml`](https://raw.githubusercontent.com/heroiclabs/nakama/master/install/docker/docker-compose.yml) file onto your computer.

   ```
   wget https://raw.githubusercontent.com/heroiclabs/nakama/master/install/docker/docker-compose.yml
   ```

   This will download `docker-compose.yml` to your current working directory.

2. Navigate to the folder where `docker-compose.yml` is located in a command line console.
3. Run the following command:

    ```
    docker-compose up
    ```

    This will download the latest cockroachdb and Nakama images published on Docker Hub.

4. You have both CockroachDB and Nakama running on your machine.
5. Navigate to [http://localhost:7351](http://localhost:7351) to check that you can view Nakama's embedded dashboard.

All server logs are printed to the console as part of the `docker-compose` output.

## Setup a client

By default the server is started on `127.0.0.1:7350` and dashboard is reachable at [http://127.0.0.1:7351](http://127.0.0.1:7351).

CockroachDB is started on `127.0.0.1:26257` and it's dashboard is available at [http://127.0.0.1:8080](http://127.0.0.1:8080).

Follow one of the client guides to connect to the server:

- [Unity](https://heroiclabs.com/docs/clients/unity/)

## Stop the containers

You can stop `docker-compose` while it is running with `ctrl-c`. You can also run `docker-compose stop` in the same directory as `docker-compose.yml` and all containers will be shutdown gracefully. Your data within these containers is still safe. You can re-run the containers by running `docker-compose up`.

To stop and purge all stored data, containers, and images from your machine. Run `docker-compose down`.

## Build and deploy the Docker image

1. To build the image locally. Setup a local copy of the codebase. Run the following command (in the same directory as this README):

   If you have updated the version number in the `Dockerfile` also update it in the command below:

   ```
   docker build -t heroiclabs:nakama-<VERSION> nakama
   ```

   This creates a new image for each version of Nakama.

2. Follow [these instructions](https://docs.docker.com/engine/getstarted/step_six/) to push the image to Docker Hub.

   Ensure that you tag the relevant image ID twice so that the `latest` always refers to the most up to date version tag.

   ```
   docker images
   docker tag <IMAGE_ID> heroiclabs/nakama:<VERSION>
   docker tag <IMAGE_ID> heroiclabs/nakama:latest
   ```

   ```
   docker login
   ```

   ```
   docker push heroiclabs/nakama:<VERSION>
   docker push heroiclabs/nakama:latest
   ```

   **Note:** You can (optionally) skip step 2 as the image you create has a different ID (because of the way we create the above).

3. Navigate to [Docker Hub](https://hub.docker.com/r/heroiclabs/nakama/tags/) and view the latest pushed image.
+43 −0
Original line number Diff line number Diff line
version: '3'
services:
  cockroachdb:
    image: cockroachdb/cockroach:latest
    command: start --insecure --store=attrs=ssd,path=/var/lib/cockroach/
    restart: always
    volumes:
      - data:/var/lib/cockroach
    expose:
      - "8080"
      - "26257"
    ports:
      - "26257:26257"
      - "8080:8080"
  nakama-migration:
    image: heroiclabs/nakama:latest
    command: migrate up --db "root@cockroachdb:26257"
    links:
      - "cockroachdb:db"
    depends_on:
      - cockroachdb
    volumes:
      - data:/var/lib/nakama
  nakama:
    image: heroiclabs/nakama:latest
    command: --name nakama --db "root@cockroachdb:26257"
    restart: always
    depends_on:
      - nakama-migration
    links:
      - "cockroachdb:db"
    volumes:
      - data:/var/lib/nakama
    ports:
      - "7350:7350"
      - "7351:7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7351/v0/health"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  data:
+25 −0
Original line number Diff line number Diff line
FROM ubuntu:xenial

MAINTAINER Heroic Labs <support@heroiclabs.com>

RUN mkdir -p /nakama
RUN mkdir -p /nakama/data/log/
RUN touch /nakama/data/log/nakama.log
WORKDIR /nakama/

# forward logs to docker log collector
# docker logs are JSON by default
RUN ln -sf /dev/stdout data/log/nakama.log

RUN apt-get update; apt-get install -y curl

RUN curl -sL https://github.com/heroiclabs/nakama/releases/download/v0.11.1/nakama-0.11.1-linux-amd64.tar.gz | tar xz

EXPOSE 7350 7351

# set entry point to nakama so that it can be invoked from the `docker run nakama`
ENTRYPOINT ["/nakama/nakama"]

# curl fails on non-200 HTTP status code
HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost:7351/v0/health/ || exit 1