Browse Source

Add Docker deployment instructions

CapacitorSet 4 years ago
parent
commit
6ca6b798d2

+ 7 - 0
README.md

@@ -1,2 +1,9 @@
 # karl-marx
 
+## Deploying
+
+ * Create a fat jar with `sbt assembly` and call it `Bot.jar`
+ * On the server, create a directory for your bot. Copy `docker-compose.yml` into it, create `data/bot/`, and copy `Bot.jar` into `data/bot/`
+ * Run `docker-compose up -d`
+
+You can view logs with `docker-compose logs`, take down the server with `docker-compose down`, and restart it with `docker-compose restart`.

+ 3 - 1
build.sbt

@@ -3,4 +3,6 @@ name := "karl-marx"
 version := "0.1"
 
 scalaVersion := "2.12.8"
-libraryDependencies += "com.bot4s" %% "telegram-core" % "4.2.0-RC1"
+libraryDependencies += "com.bot4s" %% "telegram-core" % "4.2.0-RC1"
+
+mainClass := Some("Runner")

+ 19 - 0
docker-compose.yml

@@ -0,0 +1,19 @@
+version: "2"
+services:
+  bot:
+    restart: always
+    image: openjdk:8-jre-stretch
+    volumes:
+      - ./data/bot:/bot
+    working_dir: /bot
+    entrypoint: java -jar Bot.jar
+    environment:
+      - BOT_TOKEN=soandso
+    depends_on:
+      - redis
+  redis:
+    restart: always
+    image: redis
+    entrypoint: redis-server --appendonly yes
+    volumes:
+      - ./data/redis:/data

+ 1 - 0
project/assembly.sbt

@@ -0,0 +1 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")

+ 2 - 1
src/main/scala/org/congressodeiradicali/karlmarx/Runner.scala

@@ -7,10 +7,11 @@ object Runner {
   def main(args: Array[String]): Unit = {
     val bot = new Bot("657892534:AAEeSKtA9rbo9WCYDenFXygwtNg-YV_EDs4")
     val eol = bot.run()
+    /*
     println("Press [ENTER] to shutdown the bot, it may take a few seconds...")
     scala.io.StdIn.readLine()
-    bot.shutdown() // initiate shutdown
     // Wait for the bot end-of-life
+    */
     Await.result(eol, Duration.Inf)
   }
 }