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 4 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
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ 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.
Before you can run the project, you need to execute the migrations in the database. You can achieve that executing:

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

After executing the migration, you can execute the project by running:

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

### 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
97 changes: 97 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
version: "3.8"

services:
khan:
build:
context: .
dockerfile: Dockerfile
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
links:
- postgres
- redis
- elasticsearch
ports:
- "80:80"
networks:
- khan
environment:
- KHAN_POSTGRES_HOST=postgres
- KHAN_POSTGRES_USER=postgres
- KHAN_POSTGRES_PASSWORD=123456
- KHAN_ELASTICSEARCH_HOST=elasticsearch

migrate:
build:
context: .
dockerfile: Dockerfile
command: "make migrate"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this configuration with a docker-compose up without reading README, migrate and khan will be running concurrently. Could we have problems with the khan container due to this?
Which is the advantage of running migrate outside the khan container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I can override the command to execute both make commands instead of using two separated services.

depends_on:
postgres:
condition: service_healthy
links:
- postgres
networks:
- khan
environment:
- KHAN_POSTGRES_HOST=postgres
- KHAN_POSTGRES_USER=postgres
- KHAN_POSTGRES_PASSWORD=123456

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:
- khan
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

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

elasticsearch:
image: elasticsearch:5.6.12
ports:
- '9200:9200'
- '9300:9300'
networks:
- khan
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:
khan:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion: we could use the same network name for all services, to help us to integrate with other services (this is why I named the network as wildlife-services in other services).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.

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"