Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yangm97 committed Sep 28, 2018
2 parents d021586 + 658135a commit ae1557b
Show file tree
Hide file tree
Showing 129 changed files with 42,162 additions and 33,779 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 2
indent_size = 3
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ docker-compose.*.yml
*.sh
*.json
*.tar
luacov.*

!docker-compose.override.yml
!install.sh
!launch.sh
42 changes: 0 additions & 42 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
std = 'ngx_lua+busted'
globals = {'bot', 'string'}
globals = {'string'}
max_string_line_length = false
max_comment_line_length = false
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
sudo: false

env:
- LUA="lua=5.1" # Recommended version for polling mode
# - LUA="lua=5.1" # Recommended version for polling mode
- LUA="luajit=2.1" # Recommended version for webhooks mode
# - LUA="lua=5.2"
# - LUA="lua=5.3"
Expand All @@ -15,16 +15,18 @@ before_install:

install:
- luarocks install luacheck
# - luarocks install busted
# - luarocks install luacov
# - luarocks install luacov-coveralls
- luarocks install busted
- luarocks install luacov
- luarocks install luacov-coveralls
- luarocks install telegram-bot-api
- luarocks install lua-resty-socket

script:
- luacheck . --exclude-files lua/vendor lua_install
# - busted --verbose --coverage
- busted --coverage --lpath "./lua/?.lua;./lua/?/?.lua;./lua/?/init.lua"

# after_success:
# - luacov-coveralls --exclude $TRAVIS_BUILD_DIR/lua_install
after_success:
- luacov-coveralls --exclude lua/vendor --exclude lua_install

# matrix:
# allow_failures:
Expand Down
19 changes: 0 additions & 19 deletions Dockerfile

This file was deleted.

37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
all: dev_polling logs

clean: kill down
# docker system prune -fa

pot:
find . -name "*.lua" | sort | xgettext --from-code=utf-8 \
--add-comments=TRANSLATORS \
--force-po \
--keyword=i18n \
--files-from=/dev/stdin \
--output=/dev/stdout | msgmerge --backup=off --update locales/en.po /dev/stdin
--output=/dev/stdout | msgmerge --backup=off --update locales/en_GB.po /dev/stdin

luacheck:
luacheck . --exclude-files lua/vendor src

logs:
docker-compose logs -f --tail 20

kill:
docker-compose kill groupbutler

down:
docker-compose -f docker-compose.yml -f docker/docker-compose.polling.yml down

pull:
docker-compose pull

easy_deploy: pull
docker-compose -f docker-compose.yml -f docker/docker-compose.polling.deploy.yml up -d

build_polling:
docker-compose -f docker-compose.yml -f docker/docker-compose.polling.yml build

build_webhooks:
docker-compose -f docker-compose.yml -f docker/docker-compose.webhooks.yml build

dev_polling: kill build_polling
docker-compose -f docker-compose.yml -f docker/docker-compose.polling.yml up

dev_webhooks: kill build_webhooks
docker-compose -f docker-compose.yml -f docker/docker-compose.webhooks.yml up
30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Group Butler

[![Build Status](https://travis-ci.com/group-butler/GroupButler.svg?branch=master)](https://travis-ci.com/group-butler/GroupButler)
[![Crowdin](https://d322cqt584bo4o.cloudfront.net/group-butler/localized.svg)](https://crowdin.com/project/group-butler)
[![Coverage Status](https://coveralls.io/repos/github/group-butler/GroupButler/badge.svg?branch=master)](https://coveralls.io/github/group-butler/GroupButler?branch=master)
[![Localization Status](https://d322cqt584bo4o.cloudfront.net/group-butler/localized.svg)](https://crowdin.com/project/group-butler)

## Short introduction

Expand All @@ -12,11 +13,11 @@ Group Butler was born as an [otouto](https://otou.to) [v3.1](https://github.com/
#### Group Butler on Telegram:

- [`@GroupButler_bot`](https://telegram.me/GroupButler_Bot)
- **_branch_**: `production`
- **_branch_**: `master`
- **_channel_**: [`@GroupButler_ch`](https://telegram.me/groupbutler_ch).

- [`@GBReborn_bot`](https://telegram.me/GBReborn_bot)
- **_branch_**: `staging`
- **_branch_**: `develop`
- **_channel_**: [`@GroupButler_beta`](https://telegram.me/GroupButler_beta).

* * *
Expand Down Expand Up @@ -51,12 +52,11 @@ Requirements:
- docker 17.06.0-ce
- docker-compose 1.14.0
- Optional: Docker Swarm cluster for deployment
- Optional: GitLab repository for CI/CD

### Running (dev mode)
Run `docker-compose up`. Docker will pull and build the required images, so the first time you run this command should take a little while. After that, the bot should be up and running.
Run `make dev_polling`. Docker will pull and build the required images, so the first time you run this command should take a little while. After that, the bot should be up and running.

Code is mounted on the bot container, so you can make changes and restart the bot as you normally would. There’s no need to use `docker-compose up --build` or `docker-compose build` unless you changed something on `Dockerfile`.
Code is mounted on the bot container, so you can make changes and restart the bot as you normally would.

Redis default port is mounted to host, just in case you want to debug something using tools available at the host.

Expand All @@ -65,30 +65,22 @@ Redis default port is mounted to host, just in case you want to debug something
### Running (production mode)
There’s a number of ways you can use docker for deploying into production.

Files named `docker-compose.*.yml` are gitignored, just in case you feel the need to override `docker-compose.yml` or write something else entirely. `docker-compose.override.yml` is used to store dev mode overrides since it’s read by default by docker-compose.
Files named `docker-compose.*.yml` are gitignored, just in case you feel the need to override `docker-compose.yml` or write something else entirely.

The bot also supports reading Docker Secrets (may work with other vaults too). Check `lua/config.lua` to see which variables can be read from secrets.

#### Compose Example
You would need to write another override file (i.e. `docker-compose.deploy.yml`) matching your needs (change restart policy to always, either add groupbutler to an external network or create a redis service with persistency, etc.).

You could deploy Group Butler by running something like this:
You can deploy Group Butler by running:

`make easy_deploy`

`docker-compose -f docker-compose.yml -f docker-compose.deploy.yml up`

#### Swarm Example
Assuming you have deployed redis into `staging` (`docker stack deploy …` or `docker service create …`) and exported the required environment variables (like `$TG_TOKEN`…), you could deploy Group Butler by running:
Assuming you have deployed redis into, for instance `staging` (`docker stack deploy …` or `docker service create …`) and exported the required environment variables (like `$TG_TOKEN`…), you could deploy Group Butler by running:

`docker stack deploy staging -c docker-compose.yml`

#### GitLab CI Example (uses swarm)
- Clone this repo to a GitLab server (could be gitlab.com or self hosted)
- Set Project Variables, paying attention to variable scope: the `.gitlab-ci.yml` bundled with this repo supports two environments: `staging` and `production`
- Disable shared runners and install GitLab CI runner on at least one of the manager nodes. Make sure to tag them as `manager` too
- Deploy (manually or using another repository) redis to `staging` and/or `production`
- Push to `staging` and/or `production` branches
- If everything went well, your very own Group Butler should be up and running

## Setup (without using Docker)
List of required packages:
- `libreadline-dev`
Expand Down
85 changes: 85 additions & 0 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
env GB_OLD_UPDATE;
env CHANNEL;
env DEFAULT_LANG;
env HELP_GROUP;
env LOG_CHAT;
env LOG_ADMIN;
env LOG_STATS;
env MULTIPURPOSE_PLUGINS;
env POSTGRES_HOST;
env POSTGRES_PORT;
env POSTGRES_USER;
env POSTGRES_PASSWORD;
env POSTGRES_DB;
env REDIS_HOST;
env REDIS_PORT;
env REDIS_DB;
env SOURCE;
env SUPERADMINS;
env TG_TOKEN;
env TG_UPDATES;
env TG_POLLING_LIMIT;
env TG_POLLING_TIMEOUT;
env TG_WEBHOOK_URL;
env TG_WEBHOOK_DOMAIN;
env TG_WEBHOOK_CERT;
env TG_WEBHOOK_MAX_CON;

error_log /dev/stderr notice;

master_process on;
worker_processes auto;
worker_cpu_affinity auto;

events {
worker_connections 10240;
}

http {
client_body_buffer_size 1M;
client_max_body_size 1M;
log_format combined_no_query '$remote_addr ' '"$request_method $uri" $status $body_bytes_sent ';
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
lua_ssl_verify_depth 2;
lua_package_path "$prefix/lua/?.lua;$prefix/lua/vendor/?.lua;;";
lua_max_running_timers 10240;
# lua_socket_log_errors off;
# lua_code_cache off; # only during development
resolver 127.0.0.11 ipv6=off; # use docker local resolver and disable IPv6
server {
access_log /dev/stdout combined_no_query;
listen 80;
charset utf-8;
charset_types application/json;
default_type application/json;
access_by_lua_block {
local config = require "groupbutler.config"
if not config.telegram.webhook.domain then -- Using custom URL. Don't check for the token
return
end
if not ngx.var.arg_token or (ngx.var.arg_token ~= config.telegram.token) then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
return
}
location / {
content_by_lua_block {
require "groupbutler".go()
}
}
location /set_webhook {
content_by_lua_block {
require "init_nginx".set_webhook()
}
}
}
server {
listen 8000;
access_log /dev/null;
location /health {
content_by_lua_block {
require "groupbutler".health()
}
}
}
}
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.3'
version: '3.6'

services:
groupbutler:
Expand Down Expand Up @@ -28,6 +28,7 @@ services:
- TG_POLLING_LIMIT
- TG_POLLING_TIMEOUT
- TG_WEBHOOK_URL
- TG_WEBHOOK_DOMAIN
- TG_WEBHOOK_CERT
- TG_WEBHOOK_MAX_CON
image: ${IMAGE:-groupbutler/groupbutler}:${TAG:-latest}
19 changes: 19 additions & 0 deletions docker/docker-compose.polling.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.6'

services:
groupbutler:
environment:
REDIS_HOST: redis
restart: always

redis:
image: redis:alpine
restart: always
# Optional. Map redis port to the host if you want to explore the db
# ports:
# - "127.0.0.1:6379:6379"
volumes:
- redis:/data

volumes:
redis:
17 changes: 10 additions & 7 deletions docker-compose.override.yml → docker/docker-compose.polling.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
version: '3.3'
version: '3.6'

services:
groupbutler:
build: .
depends_on:
- redis
build:
context: .
dockerfile: docker/polling.Dockerfile
args:
# DEPS_NATIVE: $DEPS_NATIVE
# DEPS_ROCKS: $DEPS_ROCKS
GB_COMMIT: $GB_COMMIT
environment:
- REDIS_HOST=redis
restart: on-failure
REDIS_HOST: redis
volumes:
- ./conf:/srv/app/conf
- ./locales:/srv/app/locales
- ./lua:/srv/app/lua
- ./polling.lua:/srv/app/polling.lua

redis:
command: --save "" --appendonly no
image: redis:alpine
restart: on-failure
ports:
- "6379:6379"

0 comments on commit ae1557b

Please sign in to comment.