From fcc0b4957674e246e7fd1737f90bbff873412ffa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 21 Nov 2021 20:51:56 +0600 Subject: [PATCH] add dockerfile environment --- Dockerfile | 9 +++++++++ Makefile | 19 +++++++++++++++++++ README.md | 7 +++++++ build.gradle | 5 +++++ docker-compose.yml | 6 ++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/kotlin/telegram_bot/App.kt | 4 ++++ 7 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f061516 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM adoptopenjdk/openjdk11 + +USER 1000 + +VOLUME /config.json + +ENTRYPOINT ["/telegram_bot/bin/telegram_bot", "TOKEN"] + +ADD ./build/distributions/telegram_bot.tar / diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..63b297c --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +#!make + +.ONESHELL: +.PHONY: + +clean: + ./gradlew clean + +build: + ./gradlew build + +start: + ./gradlew run + +startCompose: + docker-compose build && docker-compose up + +buildAndStartCompose: + make clean build startCompose diff --git a/README.md b/README.md index 5c95f86..74c9c8e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ output you will get your bot information like: ExtendedBot(id=ChatId(chatId=1234567890), username=Username(username=@username_of_your_bot), firstName=Name of bot, lastName=, canJoinGroups=(some boolean), canReadAllGroupMessages=(some boolean), supportsInlineQueries=(some boolean)) ``` +### Docker + +In this template there is template-like [docker-compose](docker-compose.yml) and [docker](Dockerfile) files. Besides, +there is [Makefile](Makefile) and you may use something like `make buildAndStartCompose` to start your bot. + +It is important to replace `"TOKEN"` in [Dockerfile](Dockerfile) or remove and add some config as a volume. + ## What next? There are several ways to continue: diff --git a/build.gradle b/build.gradle index ebd6fe3..3fe306d 100644 --- a/build.gradle +++ b/build.gradle @@ -28,3 +28,8 @@ dependencies { application { mainClassName = 'telegram_bot.AppKt' } + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5696bc0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3.4" + +services: + server: + build: . + restart: unless-stopped diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/telegram_bot/App.kt b/src/main/kotlin/telegram_bot/App.kt index d0ef8d7..0add9eb 100644 --- a/src/main/kotlin/telegram_bot/App.kt +++ b/src/main/kotlin/telegram_bot/App.kt @@ -27,5 +27,9 @@ suspend fun main(args: Array) { // simply reply :) reply(it, "Hello, I am ${me.firstName}") } + + // That will be called on the end of bot initiation. After that prinln will be started long polling and bot will + // react on your commands + println(me) }.join() }