Skip to content

Commit

Permalink
feat (docker) micro-services stack
Browse files Browse the repository at this point in the history
  • Loading branch information
pentateu committed Feb 18, 2019
1 parent cadba49 commit c1c4edf
Show file tree
Hide file tree
Showing 25 changed files with 557 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:10-alpine

ENV NODE_ENV=production

RUN mkdir /app
WORKDIR /app

COPY package.json .

RUN npm install --production

COPY . .

CMD ["npm", "start"]
29 changes: 29 additions & 0 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:

dev:
image: node:10-alpine
expose:
- "3000"
ports:
- "3000:3000"
env_file: env
environment:
PORT: 3000

working_dir: /src
volumes:
- ../..:/src

command: /bin/sh -c "npm install && npm run dev"

links:
- mongo
depends_on:
- mongo

mongo:
image: mongo
# volumes:
# - ../../db:/data/db
5 changes: 5 additions & 0 deletions docker/dev/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NODE_ENV=development
LOGLEVEL=debug
CACHER=false
MONGO_URI=mongodb://mongo/moleculer-blog
SERVICEDIR=services
7 changes: 7 additions & 0 deletions docker/elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG ELK_VERSION

# https://github.com/elastic/elasticsearch-docker
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:${ELK_VERSION}

# Add your elasticsearch plugins setup here
# Example: RUN elasticsearch-plugin install analysis-icu
16 changes: 16 additions & 0 deletions docker/elasticsearch/config/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
## Default Elasticsearch configuration from elasticsearch-docker.
## from https://github.com/elastic/elasticsearch-docker/blob/master/build/elasticsearch/elasticsearch.yml
#
cluster.name: "docker-cluster"
network.host: 0.0.0.0

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1

## Use single node discovery in order to disable production mode and avoid bootstrap checks
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
#
discovery.type: single-node
1 change: 1 addition & 0 deletions docker/extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Third-party extensions that enable extra integrations with the ELK stack.
13 changes: 13 additions & 0 deletions docker/extensions/curator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.8

ENV CURATOR_VERSION=5.5.4

RUN apk --update add --no-cache tini python py-pip \
&& pip install elasticsearch-curator==${CURATOR_VERSION}

COPY entrypoint.sh /

WORKDIR /usr/share/curator
COPY config ./config

ENTRYPOINT ["/entrypoint.sh"]
18 changes: 18 additions & 0 deletions docker/extensions/curator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Curator

Elasticsearch Curator helps you curate or manage your indices.

## Usage

If you want to include the Curator extension, run Docker Compose from the root of the repository with an additional
command line argument referencing the `curator-compose.yml` file:

```bash
$ docker-compose -f docker-compose.yml -f extensions/curator/curator-compose.yml up
```

All configuration files are available in the `config/` directory.

## Documentation

https://github.com/elastic/curator
24 changes: 24 additions & 0 deletions docker/extensions/curator/config/curator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# Remember, leave a key empty if there is no value. None will be a string,
# not a Python "NoneType"
client:
hosts:
- ${ELASTICSEARCH_HOST}
port: 9200
url_prefix:
use_ssl: False
certificate:
client_cert:
client_key:
aws_key:
aws_secret_key:
aws_region:
ssl_no_validate: False
http_auth:
timeout: 30
master_only: False

logging:
loglevel: DEBUG
logfile: /usr/share/curator/curator.log
logformat: default
20 changes: 20 additions & 0 deletions docker/extensions/curator/config/delete_log_files_curator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
actions:
1:
action: delete_indices
description: >-
Delete indices. Find which to delete by first limiting the list to logstash-
prefixed indices. Then further filter those to prevent deletion of anything
less than ${UNIT_COUNT} days old. Ignore the error if the filter does not result in an
actionable list of indices (ignore_empty_list) and exit cleanly.
options:
ignore_empty_list: True
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: logstash-
- filtertype: age
source: creation_date
direction: older
unit: days
unit_count: ${UNIT_COUNT}
18 changes: 18 additions & 0 deletions docker/extensions/curator/curator-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '2'

services:


curator:
build:
context: extensions/curator/
environment:
ELASTICSEARCH_HOST: elasticsearch
CRON: 0 0 * * *
CONFIG_FILE: /usr/share/curator/config/curator.yml
COMMAND: /usr/share/curator/config/delete_log_files_curator.yml
UNIT_COUNT: 2
networks:
- elk
depends_on:
- elasticsearch
6 changes: 6 additions & 0 deletions docker/extensions/curator/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

echo "$CRON /usr/bin/curator --config ${CONFIG_FILE} ${COMMAND}" >>/etc/crontabs/root

# https://github.com/krallin/tini/blob/master/README.md#subreaping
tini -s -- crond -f -d 8 -l 8
5 changes: 5 additions & 0 deletions docker/extensions/logspout/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# uses ONBUILD instructions described here:
# https://github.com/gliderlabs/logspout/tree/master/custom

FROM gliderlabs/logspout:master
ENV SYSLOG_FORMAT rfc3164
28 changes: 28 additions & 0 deletions docker/extensions/logspout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logspout extension

Logspout collects all Docker logs using the Docker logs API, and forwards them to Logstash without any additional
configuration.

## Usage

If you want to include the Logspout extension, run Docker Compose from the root of the repository with an additional
command line argument referencing the `logspout-compose.yml` file:

```bash
$ docker-compose -f docker-compose.yml -f extensions/logspout/logspout-compose.yml up
```

In your Logstash pipeline configuration, enable the `udp` input and set the input codec to `json`:

```
input {
udp {
port => 5000
codec => json
}
}
```

## Documentation

https://github.com/looplab/logspout-logstash
18 changes: 18 additions & 0 deletions docker/extensions/logspout/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# unmodified from:
# https://github.com/gliderlabs/logspout/blob/67ee3831cbd0594361bb3381380c65bdbeb3c20f/custom/build.sh

set -e
apk add --update go git mercurial build-base
mkdir -p /go/src/github.com/gliderlabs
cp -r /src /go/src/github.com/gliderlabs/logspout
cd /go/src/github.com/gliderlabs/logspout
export GOPATH=/go
go get
go build -ldflags "-X main.Version=$1" -o /bin/logspout
apk del go git mercurial build-base
rm -rf /go /var/cache/apk/* /root/.glide

# backwards compatibility
ln -fs /tmp/docker.sock /var/run/docker.sock
16 changes: 16 additions & 0 deletions docker/extensions/logspout/logspout-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '2'

services:
logspout:
build:
context: extensions/logspout
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
ROUTE_URIS: logstash://logstash:5000
LOGSTASH_TAGS: docker-elk
networks:
- elk
depends_on:
- logstash
restart: on-failure
9 changes: 9 additions & 0 deletions docker/extensions/logspout/modules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// installs the Logstash adapter for Logspout, and required dependencies
// https://github.com/looplab/logspout-logstash
import (
_ "github.com/looplab/logspout-logstash"
_ "github.com/gliderlabs/logspout/transports/udp"
_ "github.com/gliderlabs/logspout/transports/tcp"
)
7 changes: 7 additions & 0 deletions docker/kibana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG ELK_VERSION

# https://github.com/elastic/kibana-docker
FROM docker.elastic.co/kibana/kibana-oss:${ELK_VERSION}

# Add your kibana plugins setup here
# Example: RUN kibana-plugin install <name|url>
7 changes: 7 additions & 0 deletions docker/kibana/config/kibana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
## Default Kibana configuration from kibana-docker.
## from https://github.com/elastic/kibana-docker/blob/master/build/kibana/config/kibana.yml
#
server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
7 changes: 7 additions & 0 deletions docker/logstash/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG ELK_VERSION

# https://github.com/elastic/logstash-docker
FROM docker.elastic.co/logstash/logstash-oss:${ELK_VERSION}

# Add your logstash plugins setup here
# Example: RUN logstash-plugin install logstash-filter-json
6 changes: 6 additions & 0 deletions docker/logstash/config/logstash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
## Default Logstash configuration from logstash-docker.
## from https://github.com/elastic/logstash-docker/blob/master/build/logstash/config/logstash-oss.yml
#
http.host: "0.0.0.0"
path.config: /usr/share/logstash/pipeline
13 changes: 13 additions & 0 deletions docker/logstash/pipeline/logstash.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
input {
tcp {
port => 5000
}
}

## Add your filters / logstash plugins configuration here

output {
elasticsearch {
hosts => "elasticsearch:9200"
}
}
Loading

0 comments on commit c1c4edf

Please sign in to comment.