Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker-compose to run Khan locally #61

Closed
Closed
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Dockerfile
docker-compose.yml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.11
- 1.12

sudo: false

Expand Down
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
FROM golang:1.11-alpine

MAINTAINER TFG Co <backend@tfgco.com>
WORKDIR /go/src/github.com/topfreegames/khan

EXPOSE 80

RUN apk update
RUN apk add git make g++ apache2-utils
RUN apk add git make g++ apache2-utils curl
RUN apk add --update bash

RUN go get -u github.com/golang/dep/...
RUN go get -u github.com/topfreegames/goose/cmd/goose

ADD loadtest/words /usr/share/dict/words
ADD . /go/src/github.com/topfreegames/khan
ADD Gopkg.* ./
RUN dep ensure --vendor-only

WORKDIR /go/src/github.com/topfreegames/khan
ADD . .
RUN dep ensure
RUN go install github.com/topfreegames/khan

Expand Down Expand Up @@ -44,4 +46,6 @@ ENV KHAN_BASICAUTH_PASSWORD ""

ENV KHAN_RUN_WORKER ""

CMD /bin/bash -c 'if [ "$KHAN_RUN_WORKER" != "true" ]; then /go/bin/khan start --bind 0.0.0.0 --port 80 --fast --config /go/src/github.com/topfreegames/khan/config/default.yaml; else /go/bin/khan worker --config /go/src/github.com/topfreegames/khan/config/default.yaml; fi'
RUN chmod +x ./docker/start-khan.sh

CMD [ "./docker/start-khan.sh" ]
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ setup-ci:
@go get github.com/topfreegames/goose/cmd/goose
@go get github.com/mattn/goveralls
@go get github.com/onsi/ginkgo/ginkgo
@dep ensure

build:
@go build -o ./bin/khan main.go
Expand Down Expand Up @@ -88,6 +87,9 @@ run-fast:
build-docker:
@docker build -t khan .

start-on-docker: migrate
@bash ./docker/start-khan.sh

build-dev-docker:
@cp ./config/default.yaml ./dev
@cp ./bin/khan-linux-x86_64 ./dev
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ To run a new khan instance, run:

$ make run-docker

### Running with docker-compose

We already provide a docker-compose.yml as well with all dependencies configured for you to run. To run Khan and all its dependencies, run:

```sh
$ docker-compose up
```

**Note** If you are running it on MacOS, you will need to update the amount of RAM docker has access to. Docker, by default, can use 2GB of RAM, however, Khan uses an instance of ElasticSearch and it needs at least 2GB of RAM to work properly. So, if you are experiencing problems while connecting to the elastic search, this might be the root cause of the problem.

### Tests

Running tests can be done with `make test`, while creating the test database can be accomplished with `make drop-test` and `make db-test`.
Expand Down
108 changes: 108 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
version: "3.8"

services:
khan:
build:
context: .
dockerfile: Dockerfile
command: "make start-on-docker"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
links:
- postgres
- redis
- elasticsearch
ports:
- "80:80"
networks:
- wildlife-services
environment:
- KHAN_POSTGRES_HOST=postgres
- KHAN_POSTGRES_USER=postgres
- KHAN_POSTGRES_PASSWORD=123456
- KHAN_REDIS_HOST=redis
- KHAN_ELASTICSEARCH_HOST=elasticsearch
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail http://localhost/healthcheck || exit 1"]
interval: 30s
timeout: 30s
retries: 3

khan-worker:
build:
context: .
dockerfile: Dockerfile
depends_on:
khan:
condition: service_healthy
links:
- khan
ports:
- "8080:8080"
networks:
- wildlife-services
environment:
- KHAN_RUN_WORKER=true
- KHAN_POSTGRES_HOST=postgres
- KHAN_POSTGRES_USER=postgres
- KHAN_POSTGRES_PASSWORD=123456
- KHAN_REDIS_HOST=redis
- KHAN_ELASTICSEARCH_HOST=elasticsearch

postgres:
image: postgres:9.6
restart: always
environment:
- POSTGRES_PASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_DB=khan
ports:
- "5432:5432"
volumes:
- ./docker-data/postgres:/var/lib/postgresql/data
networks:
- wildlife-services
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

redis:
image: redis
restart: always
ports:
- "6379:6379"
networks:
- wildlife-services
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 3s
retries: 30

elasticsearch:
image: elasticsearch:5.6.12
ports:
- '9200:9200'
- '9300:9300'
networks:
- wildlife-services
volumes:
- ./docker-data/elasticsearch:/usr/share/elasticsearch/data
environment:
- xpack.security.enabled=false
- discovery.type=single-node
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 30s
retries: 3

networks:
wildlife-services:
6 changes: 6 additions & 0 deletions docker/start-khan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
if [ "$KHAN_RUN_WORKER" != "true" ]; then
/go/bin/khan start --bind 0.0.0.0 --port 80 --fast --config /go/src/github.com/topfreegames/khan/config/default.yaml
else
/go/bin/khan worker --config /go/src/github.com/topfreegames/khan/config/default.yaml
fi
2 changes: 1 addition & 1 deletion util/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
package util

// VERSION identifies Khan's current version
var VERSION = "4.3.12"
var VERSION = "4.3.13"