Skip to content

Commit

Permalink
add docker build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Jan 7, 2022
1 parent 52f2695 commit fa9918b
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logs
ui/node_modules
bin
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ts linguist-detectable=false
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# UI build stage
FROM node:16-alpine3.14 as js-builder

ENV NODE_OPTIONS=--max_old_space_size=8000
WORKDIR /mogo
COPY ui/package.json ui/package-lock.json ui/yarn.lock .

RUN yarn install
ENV NODE_ENV production
COPY ui .
RUN yarn build


# # API build stage
FROM golang:1.17.3-alpine3.14 as go-builder

ENV GOPROXY=https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk add --no-cache make bash git
WORKDIR /mogo

COPY go.mod go.sum .
RUN go mod download -x
COPY scripts scripts
COPY api api
COPY Makefile Makefile
RUN ls -rlt && make build.api


# # Fianl running stage
FROM alpine:3.14.3
LABEL maintainer="[email protected]"

WORKDIR /mogo

COPY --from=go-builder /mogo/bin/mogo ./bin/
COPY --from=js-builder /mogo/dist ./public

EXPOSE 9001
EXPOSE 9003

CMD ["sh", "-c", "./bin/mogo"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ build.ui:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making $@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@cd $(APP_PATH)/ui && npm run build
@echo -e "\n"

docker.build:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making $@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@docker build -t mogo:latest .
@echo -e "\n"
5 changes: 5 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# mogo

[![Go Report Card](https://goreportcard.com/badge/github.com/shimohq/mogo)](https://goreportcard.com/report/github.com/shimohq/mogo)
[![Release](https://img.shields.io/github/v/release/shimohq/mogo.svg)](https://github.com/shimohq/mogo)
[![GitHub license](https://img.shields.io/github/license/shimohq/mogo)](https://github.com/shimohq/mogo/blob/master/LICENSE)
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,62 @@

[![Go Report Card](https://goreportcard.com/badge/github.com/shimohq/mogo)](https://goreportcard.com/report/github.com/shimohq/mogo)
[![Release](https://img.shields.io/github/v/release/shimohq/mogo.svg)](https://github.com/shimohq/mogo)
[![goproxy.cn](https://goproxy.cn/stats/github.com/shimohq/mogo/badges/download-count.svg)](https://goproxy.cn/stats/github.com/shimohq/mogo)
[![GitHub license](https://img.shields.io/github/license/shimohq/mogo)](https://github.com/shimohq/mogo/blob/master/LICENSE)

Mogo is a lightweight browser-based logs analytics and logs search platform for some datasource(ClickHouse, MySQL, etc.)

clickhouse,log,es,mysql
## Live demo
TODO.

## Features
- visual query dashboard, support query Histogram and raw logs for SQL.
- shows percentage for specified fields.
- vscode style configuration board, you can easily emit your fluent-bit configuration to Kubernetes ConfigMap.
- Out of the box, easily deployment with `kubectl`.
- Support for GitHub and GitLab Authentication.

## Architecture

## Installation
- For host
```bash
# download release
# go to https://github.com/shimohq/mogo/releases and choose specific release to download.
latest=$(curl -sL https://api.github.com/repos/shimohq/mogo/releases/latest | grep ".tag_name" | sed -E 's/.*"([^"]+)".*/\1/')
# for MacOS
wget https://github.com/shimohq/mogo/releases/download/${latest}/mogo_${latest}_darwin_x86_64.tar.gz -O mogo.tar.gz
# for Linux
wget https://github.com/shimohq/mogo/releases/download/${latest}/mogo_${latest}_linux_x86_64.tar.gz -O mogo.tar.gz

# extract zip file
tar xvf mogo.tar.gz -O

# start api server


# configure nginx config

```

- For Docker
```bash
git clone https://github.com/shimohq/mogo.git
docker-compose up

# then go to browser and visit http://localhost:9001
# username: admin
# password: admin
```

- For helm
```bash
```

## Main Tasks
-[x] task1
-[x] task2

## Bugs or features
If you want to report a bug or request for a feature, create a issue [here](https://github.com/shimohq/mogo/issues).

## Contributors
93 changes: 93 additions & 0 deletions api/config/default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[logger.default]
level = "debug"

[server.http]
host = "0.0.0.0"
port = 9001
public="./public"

[server.governor]
host = "0.0.0.0"
port = 9003

[permission]
resourceFile = './config/resource.yaml'

[mysql.default]
connMaxLifetime = "300s"
debug = true
dsn = "root:123456@tcp(mysql:3307)/mocro?charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&loc=Local&readTimeout=1s&timeout=1s&writeTimeout=3s"
level = "panic"
maxIdleConns = 50
maxOpenConns = 100

[redis.default]
addr = "redis:6380"
writeTimeout = "3s"
password = ""

[app]
secretKey = "ASDFASDFASDF" # hashStatecode
rootURL = "http://localhost:9001"
baseURL = "/api/admin/login/"

[auth]
# Login cookie name
loginCookieName = "mogo_session"
# The lifetime (days) an authenticated user can be inactive before being required to login at next visit. Default is 7 days.
loginMaximumInactiveLifetimeDays = 7
# The maximum lifetime (days) an authenticated user can be logged in since login time before being required to login. Default is 30 days.
loginMaximumLifetimeDays = 30
# How often should auth tokens be rotated for authenticated users when being active. The default is each 10 minutes.
tokenRotationIntervalMinutes = 10
# Set to true to disable (hide) the login form, useful if you use OAuth
disableLoginForm = false
# Set to true to disable the signout link in the side menu. useful if you use auth.proxy
disableSignoutMenu = false
# URL to redirect the user to after sign out
signoutRedirectUrl = ""
# Set to true to attempt login with OAuth automatically, skipping the login screen.
# This setting is ignored if multiple OAuth providers are configured.
oauthAutoLogin = false
# OAuth state max age cookie duration. Defaults to 60 seconds.
oauthStateCookieMaxAge = 60
# limit of api_key seconds to live before expiration
apiKeyMaxSecondsToLive = -1

[[auth.tps]]
typ = "github"
enable = true
allowSignUp = true
clientId = ""
clientSecret = ""
scopes = ["user:email", "read:org"]
authUrl = "https://github.com/login/oauth/authorize"
tokenUrl = "https://github.com/login/oauth/access_token"
apiUrl = "https://api.github.com/user"
allowedDomains = []
teamIds = []
allowedOrganizations = []

[[auth.tps]]
typ = "gitlab"
enable = true
allowSignUp = true
clientId = ""
clientSecret = ""
scopes = ["api"]
authUrl = "https://gitlab.com/oauth/authorize"
tokenUrl = "https://gitlab.com/oauth/token"
apiUrl = "https://gitlab.com/api/v4"
allowedDomains = []
teamIds = []
allowedOrganizations = []

[session]
mode = "redis"
name = "mysession"
size = 10
debug = true
network = "tcp"
addr = "redis:6380"
password = ""
keypairs = ""
5 changes: 3 additions & 2 deletions api/config/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ level = "debug"
[server.http]
host = "0.0.0.0"
port = 9001
public="./public"

[server.governor]
host = "0.0.0.0"
Expand All @@ -21,7 +22,7 @@ maxIdleConns = 50
maxOpenConns = 100

[redis.default]
addrs = "127.0.0.1:6379"
addrs= "127.0.0.1:6379"
writeTimeout = "3s"
password = ""

Expand All @@ -32,7 +33,7 @@ baseURL = "/api/admin/login/"

[auth]
# Login cookie name
loginCookieName = "juno_session"
loginCookieName = "mogo_session"
# The lifetime (days) an authenticated user can be inactive before being required to login at next visit. Default is 7 days.
loginMaximumInactiveLifetimeDays = 7
# The maximum lifetime (days) an authenticated user can be logged in since login time before being required to login. Default is 30 days.
Expand Down
22 changes: 18 additions & 4 deletions api/internal/router/router.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package router

import (
"github.com/gotomicro/ego/core/econf"
"github.com/gotomicro/ego/core/elog"
"github.com/kl7sn/toolkit/kfile"
"net/http"
"strings"

"github.com/shimohq/mogo/api/internal/apiv1/configure"
"github.com/shimohq/mogo/api/internal/apiv1/inquiry"
"github.com/shimohq/mogo/api/internal/apiv1/kube"
"github.com/shimohq/mogo/api/internal/apiv1/permission"
"github.com/shimohq/mogo/api/internal/apiv1/setting"
"github.com/shimohq/mogo/api/internal/apiv1/static"
"github.com/shimohq/mogo/api/internal/apiv1/sys"
"github.com/shimohq/mogo/api/internal/apiv1/user"
"github.com/shimohq/mogo/api/internal/invoker"
Expand All @@ -23,13 +26,24 @@ func GetRouter() *egin.Component {
r := invoker.Gin
r.Use(invoker.Session)

public := econf.GetString("server.http.public")
// static file
flag, err := kfile.IsFileExists("./ui/dist")
flag, err := kfile.IsFileExists(public)
if err != nil || !flag {
panic("Execute yarn install & & yarn build in the ./ui directory to compile the front-end static files before starting the back-end service.")
}
r.GET("/", core.Handle(static.File))
r.NoRoute(core.Handle(static.Filter))
r.GET("/", core.Handle(func(c *core.Context) {
c.File(public + "/index.html")
}))
r.NoRoute(core.Handle(func(c *core.Context) {
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
c.JSONE(http.StatusNotFound, "", nil)
return
}
elog.Debug("static", elog.String("path", c.Request.URL.Path))
c.File(public + c.Request.URL.Path)
return
}))

// non-authentication api
r.POST("/api/admin/users/login", core.Handle(user.Login))
Expand Down
75 changes: 75 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: '3'

networks:
mogo-net:
driver: bridge

services:
mysql:
image: mysql:5.7.24
expose:
- "3307"
ports:
- "3307:3307"
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--port=3307',
'--init-file=/data/migration/latest.sql',
]
volumes:
- ./scripts/migration:/data/migration
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_ROOT_HOST: '%'
restart: always
networks:
- mogo-net
redis:
image: redis:5.0.14-alpine
expose:
- "6380"
ports:
- "6380:6380"
restart: always
networks:
- mogo-net
command: [ '--port 6380' ]
clickhouse:
image: clickhouse/clickhouse-server:latest
expose:
- "8123"
ports:
- "8123:8123"
# volumes:
# - ./scripts/migration/latest.sql:/data/init.sql
# environment:
restart: always
networks:
- mogo-net
api:
image: mogo:latest
build:
context: .
dockerfile: Dockerfile
expose:
- "9001"
ports:
- "9001:9001"
depends_on:
- mysql
- redis
- clickhouse
networks:
- mogo-net
links:
- mysql
- redis
- clickhouse
restart: always
environment:
EGO_CONFIG_PATH: /mogo/config/default.toml
EGO_LOG_WRITER: stderr
volumes:
- ./api/config:/mogo/config
command: ['/bin/sh', '-c', './bin/mogo']
Loading

0 comments on commit fa9918b

Please sign in to comment.