Skip to content

Commit

Permalink
Merge pull request #13 from 'tanupoo-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mi2428 committed Jun 2, 2020
2 parents 57d126b + b77bbbd commit d5c905b
Show file tree
Hide file tree
Showing 15 changed files with 2,203 additions and 11 deletions.
1 change: 1 addition & 0 deletions .secrets/gf_password.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changeme
1 change: 1 addition & 0 deletions .secrets/gf_user.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sindan
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ jobs:
# env:
# - CACHE_NAME=visualization

- stage: "Test: building 1/2"
- stage: "Test: building 1/3"
name: "Building sindan-fluentd"
script: bash .travis/test_building_fluentd.sh

- stage: "Test: building 2/2"
- stage: "Test: building 2/3"
name: "Building sindan-visualization (with build-time secret option)"
script: bash .travis/test_building_visualization.sh

- stage: "Test: building 3/3"
name: "Building sindan-grafana"
script: bash .travis/test_building_grafana.sh

- stage: "Test: initializing and running"
name: "Initialize database and start rails app with fluentd"
script:
Expand All @@ -64,13 +68,15 @@ jobs:
- ls -al docker
- gzip -dc docker/fluentd.tar.gz | docker load
- gzip -dc docker/visualization.tar.gz | docker load
- gzip -dc docker/grafana.tar.gz | docker load
- bash .travis/deploy_dockerhub.sh
- name: "Deploy to GitHub Package Registry"
if: branch = master
script:
- ls -al docker
- gzip -dc docker/fluentd.tar.gz | docker load
- gzip -dc docker/visualization.tar.gz | docker load
- gzip -dc docker/grafana.tar.gz | docker load
- bash .travis/deploy_github.sh

env:
Expand Down
2 changes: 2 additions & 0 deletions .travis/deploy_dockerhub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ cd $(dirname $0)/..

IMAGE_TAG_FLUENTD="$(grep 'image: sindan/fluentd' docker-compose.yml | awk '{print $2}')"
IMAGE_TAG_VISUALIZATION="$(grep 'image: sindan/visualization' docker-compose.yml | awk '{print $2}')"
IMAGE_TAG_GRAFANA="$(grep 'image: sindan/grafana' docker-compose.yml | awk '{print $2}')"

docker login --username "$DOCKER_HUB_USERNAME" --password "$DOCKER_HUB_PASSWORD"

docker push "$IMAGE_TAG_FLUENTD"
docker push "$IMAGE_TAG_VISUALIZATION"
docker push "$IMAGE_TAG_GRAFANA"
4 changes: 4 additions & 0 deletions .travis/deploy_github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cd $(dirname $0)/..

IMAGE_TAG_FLUENTD="$(grep 'image: sindan/fluentd' docker-compose.yml | awk '{print $2}')"
IMAGE_TAG_VISUALIZATION="$(grep 'image: sindan/visualization' docker-compose.yml | awk '{print $2}')"
IMAGE_TAG_GRAFANA="$(grep 'image: sindan/grafana' docker-compose.yml | awk '{print $2}')"

docker login docker.pkg.github.com --username "$GITHUB_PKG_USERNAME" --password "$GITHUB_PKG_TOKEN"

Expand All @@ -10,10 +11,13 @@ docker login docker.pkg.github.com --username "$GITHUB_PKG_USERNAME" --password
PREFIX=docker.pkg.github.com/sindan/sindan-docker
IMAGE_FLUENTD=$(echo $IMAGE_TAG_FLUENTD | cut -d '/' -f 2)
IMAGE_VISUALIZATION=$(echo $IMAGE_TAG_VISUALIZATION | cut -d '/' -f 2)
IMAGE_GRAFANA=$(echo $IMAGE_TAG_GRAFANA | cut -d '/' -f 2)

docker tag $IMAGE_TAG_FLUENTD $PREFIX/$IMAGE_FLUENTD
docker tag $IMAGE_TAG_VISUALIZATION $PREFIX/$IMAGE_VISUALIZATION
docker tag $IMAGE_TAG_GRAFANA $PREFIX/$IMAGE_GRAFANA

docker push $PREFIX/$IMAGE_FLUENTD
docker push $PREFIX/$IMAGE_VISUALIZATION
docker push $PREFIX/$IMAGE_GRAFANA

18 changes: 18 additions & 0 deletions .travis/test_building_grafana.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cd $(dirname $0)/..

IMAGE_TAG="$(grep 'image: sindan/grafana' docker-compose.yml | awk '{print $2}')"
echo $IMAGE_TAG

pushd grafana

BUILDKIT_HOST=tcp://0.0.0.0:1234 \
buildctl build --no-cache --frontend dockerfile.v0 --local context=. --local dockerfile=. --progress plain \
--output type=docker,name=$IMAGE_TAG | docker load

st=$?
(( $st > 0 )) && exit $st

popd

docker images
docker save $IMAGE_TAG | gzip > docker/grafana.tar.gz
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BUILDKIT_DOCKER_BUILD = DOCKER_BUILDKIT=1 docker build
SINDAN_FLUENTD_TAG = sindan/fluentd:v1.6-1-rev1
SINDAN_VISUALIZATION_TAG = sindan/visualization:2.6.3-alpine-rev1
SINDAN_GRAFANA_TAG = sindan/grafana:6.5.0-rev1

.PHONY: all
all: run
Expand All @@ -9,6 +10,7 @@ all: run
lint: fluentd/Dockerfile visualization/Dockerfile
docker run --rm -i hadolint/hadolint < fluentd/Dockerfile || true
docker run --rm -i hadolint/hadolint < visualization/Dockerfile || true
docker run --rm -i hadolint/hadolint < grafana/Dockerfile || true

.PHONY: build
build:
Expand All @@ -20,16 +22,19 @@ build:
--build-arg BUILDTIME_DB_PASSWORD_FILE=/run/secrets/db_password \
--secret id=rails_secret,src=.secrets/rails_secret_key_base.txt \
--secret id=db_pass,src=.secrets/db_password.txt
$(BUILDKIT_DOCKER_BUILD) grafana --no-cache -t $(SINDAN_GRAFANA_TAG)

.PHONY: push
push:
docker push $(SINDAN_FLUENTD_TAG)
docker push $(SINDAN_VISUALIZATION_TAG)
docker push $(SINDAN_GRAFANA_TAG)

.PHONY: pull
pull:
docker pull $(SINDAN_FLUENTD_TAG)
docker pull $(SINDAN_VISUALIZATION_TAG)
docker pull $(SINDAN_GRAFANA_TAG)

.PHONY: init
init:
Expand Down Expand Up @@ -67,5 +72,7 @@ destroy:
docker volume rm -f $(shell basename $(CURDIR))_fluentd-data
docker volume rm -f $(shell basename $(CURDIR))_mysql-data
docker volume rm -f $(shell basename $(CURDIR))_visualization-data
docker volume rm -f $(shell basename $(CURDIR))_grafana-data
docker rmi -f $(SINDAN_FLUENTD_TAG)
docker rmi -f $(SINDAN_VISUALIZATION_TAG)
docker rmi -f $(SINDAN_GRAFANA_TAG)
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,63 @@
[![](https://travis-ci.org/SINDAN/sindan-docker.svg?branch=master)](https://travis-ci.org/SINDAN/sindan-docker) [![](http://img.shields.io/github/license/SINDAN/sindan-docker)](LICENSE) [![](https://img.shields.io/github/issues/SINDAN/sindan-docker)](https://github.com/SINDAN/sindan-docker/issues) [![](https://img.shields.io/github/issues-pr/SINDAN/sindan-docker)](https://github.com/SINDAN/sindan-docker/pull) [![](https://img.shields.io/github/last-commit/SINDAN/sindan-docker)](https://github.com/SINDAN/sindan-docker/commits) [![](https://img.shields.io/github/release/SINDAN/sindan-docker)](https://github.com/SINDAN/sindan-docker/releases) [![](https://img.shields.io/github/release-date/SINDAN/sindan-docker)](https://github.com/SINDAN/sindan-docker/releases)

Dockerization of server-side [@SINDAN](https://github.com/SINDAN) suite
- **[Branch: shored-master](https://github.com/SINDAN/sindan-docker/tree/shored-master)** Previous generation maintained by [@shored](https://github.com/shored) (soon to be deprecated and removed)
- **[Branch: shored-master](https://github.com/SINDAN/sindan-docker/tree/shored-master)** is the previous generation maintained by [@shored](https://github.com/shored) (soon to be deprecated and removed)

## About SINDAN Project

Please visit website [sindan-net.com](https://www.sindan-net.com) for more details. (Japanese edition only)

> In order to detect network failure, SINDAN project evaluates the network status based on user-side observations, and aims to establish a method that enables network operators to troubleshoot quickly.
## Getting Started

These instructions will get you a copy of this project up and running on your environment for production purpose.
If you want to use this for development or testing purposes, it is necessary to edit some configurations appropriately.
If you want to use this for development or testing purposes, some configurations need to be fixed appropriately.

### Prerequisites
To build images, **Docker with BuildKit support is needed.**

To build images on your local environment, **Docker with BuildKit support is needed.**
GNU/Make is not necessary, but it can reduce the number of commands you type.

- docker-engine: 18.06.0 and higher
- docker-compose: 1.22.0 and higher

### Clone repository

First of all, you have to shallow clone this repository recursively with:

```bash
$ git clone --recursive --depth 1 https://github.com/SINDAN/sindan-docker
```

If you ran simple cloning command without recursive option or downloaded as a zip archive via browser,
make sure that all submodules are fully updated.

```bash
$ git submodule update --init --recursive
```

### Setup secrets
All of password files in this directory are not tracked by Git.

Git will ignore all of password files in `.secrets` directory, so that the updates are local-only.
Set the password of MySQL database.
For mac users, use `shasum -a 256` instead of `sha256sum` below.

```bash
$ echo PASSWORD_OF_YOUR_ENV | sha256sum | cut -d ' ' -f 1 > .secrets/db_password.txt
```
Register user account of SINDAN Web.

Register user accounts of SINDAN Web.
User's password must be **8-72 characters long**.
Sample `accounts.yml` registers an account whose name is `sindan` and password is `changeme`.

```bash
$ cp .secrets/accounts.yml.example .secrets/accounts.yml
$ vim .secrets/accounts.yml
```

You can register multiple accounts in bulk.

```yml
accounts:
- username: hoge
Expand All @@ -58,45 +72,65 @@ accounts:
password: changeme
```
### Build/Get docker image and initialize DB
Finally, set the Grafana's username and password to `gf_user.txt` and `gf_password.txt` respectively.

### Build/Get docker imagesand initialize DB

Build dockerfile and initialize database. This might take a while.

```bash
$ cp .secrets/rails_secret_key_base.txt.example .secrets/rails_secret_key_base.txt
$ make build init
```
Instead of building locally, you can download built container images from [DockerHub](https://hub.docker.com/u/sindan).

Instead of building locally, you can download pre-built images from [DockerHub](https://hub.docker.com/u/sindan).
Note that in this case, you must not edit `.secrets/rails_secret_key_base.txt` as you like.
Just follow the next:

```bash
$ cp .secrets/rails_secret_key_base.txt.example .secrets/rails_secret_key_base.txt
$ make pull init
```

### Deploy
Deploy containers built previous steps.

Deploy containers built/pulled previous steps.

```
$ make run log
```
Open your favorite browser and go [http://localhost:3000](http://localhost:3000) to see SINDAN Web.
![Safari screenshot](https://raw.githubusercontent.com/SINDAN/sindan-docker/screenshot/safari.png)
You can also access [Grafana](https://grafana.com/) with [http://localhost:3001](http://localhost:3001).
<!-- ![screenshot of SINDAN Grafana](https://raw.githubusercontent.com/SINDAN/sindan-docker/screenshot/grafana.png) -->
### Stop and remove
```
$ make stop # stop all containers
$ make clean # remove all containers (data will not be lost)
$ make destroy # remove all containers, volumes, images
```
## Contributing
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/SINDAN/sindan-docker/tags).
We use [CalVer](https://calver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/SINDAN/sindan-docker/tags).
## Authors
- **Tomohiro ISHIHARA** - *Initial work & Patch contribution* - [@shored](https://github.com/shored)
- **Taichi MIYA** - *Overhaul & Refactoring* - [@mi2428](https://github.com/mi2428)
See also the list of [contributors](https://github.com/SINDAN/sindan-docker/graphs/contributors) who participated in this project.
## License
This project is licensed under the BSD 3-Clause "New" or "Revised" License - see the [LICENSE](LICENSE) file for details.
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,49 @@ services:
labels:
com.sindan-net.description: "Web frontend to manage diagnosis logs"

grafana:
image: sindan/grafana:6.5.0-rev1
build:
context: ./grafana
hostname: sindan-grafana
restart: always
depends_on:
- mysql
ports:
- "3001:3000"
secrets:
- db_password
- gf_user
- gf_password
logging: *default-logging
environment:
GF_PATHS_CONFIG: "/etc/grafana/config.ini"
GF_INSTALL_PLUGINS: "grafana-clock-panel"
GF_SECURITY_ADMIN_USER__FILE: "/run/secrets/gf_user"
GF_SECURITY_ADMIN_PASSWORD__FILE: "/run/secrets/gf_password"
healthcheck:
<<: *default-healthcheck
test: wget --spider http://127.0.0.1:3000/api/health || exit 1
timeout: "2s"
volumes:
- grafana-data:/var/lib/grafana
labels:
com.sindan-net.description: "Grafana dashboard"

secrets:
db_password:
file: .secrets/db_password.txt
rails_secret_key_base:
file: .secrets/rails_secret_key_base.txt
accounts:
file: .secrets/accounts.yml
gf_user:
file: .secrets/gf_user.txt
gf_password:
file: .secrets/gf_password.txt

volumes:
fluentd-data:
mysql-data:
visualization-data:
grafana-data:
15 changes: 15 additions & 0 deletions grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM grafana/grafana:6.5.0

USER root

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

USER grafana

COPY ./provisioning /etc/grafana/provisioning
COPY ./config.ini /etc/grafana/config.ini
COPY ./dashboards /var/lib/grafana/dashboards

ENTRYPOINT /entrypoint.sh

8 changes: 8 additions & 0 deletions grafana/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[paths]
provisioning = /etc/grafana/provisioning

[server]
enable_gzip = true

[log]
#level = debug
Loading

0 comments on commit d5c905b

Please sign in to comment.