diff --git a/.gitignore b/.gitignore index d1544bf..925afc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.swp +*.aci +*.auth bin/ stage.tmp/ -.auth diff --git a/Makefile b/Makefile index 77c3668..0d4fc9c 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,32 @@ docker: stat sudo docker build -t $(IMAGE_NAME) . @echo "$(IMAGE_NAME) built" +aci: stat + mkdir -p stage.tmp/lorebot-layout/rootfs/ + tar -zxf deps/rootfs.tar.gz -C stage.tmp/lorebot-layout/rootfs/ + cp bin/lorebot stage.tmp/lorebot-layout/rootfs/lorebot + chmod +x deps/run.sh + cp deps/run.sh stage.tmp/lorebot-layout/rootfs/ + cp deps/redis.conf stage.tmp/lorebot-layout/rootfs/ + cp config.gcfg stage.tmp/lorebot-layout/rootfs/ + cp deps/manifest.json stage.tmp/lorebot-layout/manifest + cd stage.tmp/ && \ + actool build lorebot-layout lorebot.aci && \ + mv lorebot.aci ../ + @echo "lorebot.aci built" + +test_aci: + mkdir -p /tmp/lorebot/redis/ + touch /tmp/lorebot/dump.rdb + cp .auth /tmp/lorebot/ + sudo rkt run \ + --volume redis,kind=host,source=/tmp/lorebot/redis/ \ + --volume auth,kind=host,source=/tmp/lorebot/.auth \ + --net=host \ + --insecure-options=image \ + ./lorebot.aci + clean: rm -rf bin/ rm -rf stage.tmp/ + rm -rf lorebot.aci diff --git a/config.gcfg b/config.gcfg index ae6434d..10c728c 100644 --- a/config.gcfg +++ b/config.gcfg @@ -1,5 +1,6 @@ [lorebot] loglevel = "debug" + slackdebug = false bootstrapdelay = 1 AuthFile = ".auth" diff --git a/deps/lorebot.service b/deps/lorebot.service new file mode 100644 index 0000000..50667fa --- /dev/null +++ b/deps/lorebot.service @@ -0,0 +1,11 @@ +[Unit] +Description=automod of all lorez + +[Service] +ExecStart=/usr/bin/rkt run \ + --net=host \ + --volume redis,kind=host,source=/tmp/dump.rdb \ + unixvoid.com/smpldbot + +[Install] +WantedBy=multi-user.target diff --git a/deps/manifest.json b/deps/manifest.json new file mode 100644 index 0000000..1eab99c --- /dev/null +++ b/deps/manifest.json @@ -0,0 +1,44 @@ +{ + "acKind": "ImageManifest", + "acVersion": "0.7.1", + "name": "unixvoid.com/lorebot", + "labels": [ + { + "name": "version", + "value": "latest" + }, + { + "name": "arch", + "value": "amd64" + }, + { + "name": "os", + "value": "linux" + } + ], + "app": { + "user": "root", + "group": "root", + "exec": [ + "/run.sh" + ], + "mountPoints": [ + { + "name": "redis", + "path": "/redisbackup/", + "readOnly": false + }, + { + "name": "auth", + "path": "/.auth", + "readOnly": false + } + ] + }, + "annotations": [ + { + "name": "authors", + "value": "Matthew Faltys " + } + ] +} diff --git a/deps/redis.conf b/deps/redis.conf new file mode 100644 index 0000000..6554e91 --- /dev/null +++ b/deps/redis.conf @@ -0,0 +1,4 @@ +daemonize yes +dbfilename dump.rdb +dir /redisbackup/ +save 30 1 diff --git a/deps/rootfs.tar.gz b/deps/rootfs.tar.gz index dd37d4c..50a0a05 100644 Binary files a/deps/rootfs.tar.gz and b/deps/rootfs.tar.gz differ diff --git a/deps/run.sh b/deps/run.sh index b2cff43..9a61141 100755 --- a/deps/run.sh +++ b/deps/run.sh @@ -1,10 +1,5 @@ #!/bin/sh -echo "daemonize yes" > /redis.conf -echo "dbfilename dump.rdb" >> /redis.conf -echo "dir /redisbackup/" >> /redis.conf -echo "save 30 1" >> /redis.conf - redis-server /redis.conf /lorebot $@ diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 1c57eda..2ee93e8 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "log" "mime/multipart" "net/http" "net/textproto" @@ -21,6 +22,7 @@ import ( type Config struct { Lorebot struct { Loglevel string + SlackDebug bool BootstrapDelay time.Duration AuthFile string } @@ -61,7 +63,13 @@ func main() { auth := lines[0] api := slack.New(auth) - //api.SetDebug(true) + + // enable slack debug if set + if config.Lorebot.SlackDebug { + logger := log.New(os.Stdout, "slack-bot: ", log.Lshortfile|log.LstdFlags) + slack.SetLogger(logger) + api.SetDebug(true) + } rtm := api.NewRTM() go rtm.ManageConnection()