Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Meta: Add docker support #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ target/
out/
*.iml

# Docker files
.docker

# Created by https://www.gitignore.io/api/eclipse,visualstudiocode
# Edit at https://www.gitignore.io/?templates=eclipse,visualstudiocode

Expand Down
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM openjdk:11-slim
LABEL "tjbot"="true"

ARG USER_ID

# The user id is injected at build time
RUN useradd --uid $USER_ID tjbot

# Expose the config dir
VOLUME ["/home/tjbot/config"]

# We should be able to place temp data in there
# Not *strictly* needed though
RUN chown -R tjbot:tjbot /home/tjbot

USER tjbot

WORKDIR /home/tjbot

# Include backend files
COPY TjBot.jar /home/tjbot/TjBot.jar

# Execute the server, needs the path to the configuration file passed as an argument
ENTRYPOINT ["java", "-jar", "/home/tjbot/TjBot.jar"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
USER_ID ?= 1000

build: target/TjBot.jar
echo "Build done!"

target/TjBot.jar: $(shell find -type f -iname '*.java' -or -iname '*sql') pom.xml
mvn package

clean:
rm -rf .docker
mvn clean

.PHONY: clean

.docker:
mkdir .docker

build-docker: build .docker
cp target/TjBot.jar .docker
cp Dockerfile .docker
(cd .docker && sudo docker build -t tjbot --build-arg USER_ID=$(USER_ID) .)
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
## About
The intention of this bot is to make moderation easier and provide useful commands to manage the server.

## Contributing
Before you contribute to this Repository consider taking a look at the [CONTRIBUTING.md](https://github.com/Together-Java/TjBot/blob/master/CONTRIBUTING.md).

## Running the bot
1. Copy `src/main/resources/sample-config.yml` and use it to structure your bot config.
2. Start the bot with following arguments: `-c path/to/your/config`

## Contributing
Before you contribute to this Repository consider taking a look at the [CONTRIBUTING.md](https://github.com/Together-Java/TjBot/blob/master/CONTRIBUTING.md).
## Running the bot in docker
### On Linux
1. Run `make build-docker USER_ID=<your wanted user id>` to build the image.
The user id is needed, as the container does not run as root and needs to read the
config file you mount in.
2. Run the docker image. The `WORKDIR` of the image is `/home/tjbot/`.
```sh
sudo docker run \ # Run it
--rm \ # Delete it on exit
-it \ # Wire up std in and out (for testing)
-v "your config dir:/home/tjbot/config" \ # Mount in your config dir
tjbot \ # Name of the image
-c config/sample-config.yml \ # See 'Running the bot', Step 2.
```

## Notice
Please keep your private bot token secret. **Do not include your bot token in any committed or pushed file.**
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
</executions>
<configuration>
<finalName>${project.name}</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.togetherjava.discordbot.BotMain</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</plugin>
</plugins>
Expand Down