Skip to content

Docker integration #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM adoptopenjdk/openjdk11:latest
ARG token
ARG config_file=bot.properties.standard
ENV JSHELL_TOKEN=$token
# ENV JSHELL_BOT_CONFIG=/opt/app/$config_file
RUN mkdir /opt/app
WORKDIR /opt/app
COPY ./target/JShellBot.jar ./app.jar
COPY ./$config_file ./bot.properties

CMD ["java", "-jar", "app.jar"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The prefix for commands
prefix=!jshell
# Th bot token
# The bot token
token=yourtokengoeshere
# How long a JShell session is kept around. Short means the history will be lost earlier,
# but it will need less server resources, if many people use it.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/togetherjava/discord/server/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public String getString(String key) {
return properties.getProperty(key);
}

/**
* Sets a property with a string
*
* @param key the key
* @param value the value of the property
*/
public void setString(String key, String value) {
properties.setProperty(key, value);
}

/**
* Tries to parse an entry in ISO-8601 duration format.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/togetherjava/discord/server/JShellBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ private Config getConfig() throws IOException {
+ " or provide a 'bot.properties' file in the same directory as this jar file"
);
System.exit(1);
} else {
Config config = new Config(path);
String token = System.getenv("JSHELL_TOKEN");
if(token != null){
//environment variable override for token i.e. building from container
config.setString("token", token);
}
return config;
}

return new Config(path);
Expand Down
29 changes: 29 additions & 0 deletions src/main/resources/bot.properties.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The prefix for commands
prefix=!jshell
# The bot token
token=yourtokengoeshere
# How long a JShell session is kept around. Short means the history will be lost earlier,
# but it will need less server resources, if many people use it.
session.ttl=PT15M
# The maximum time a single command can take before it is killed
computation.allotted_time=PT15S
# Whether to auto delete the bot's messages
messages.auto_delete=false
# Defines after what timeout the bot messages should be deleted
messages.auto_delete.duration=PT15M
# Packages listed here will not be able to be used in JShell commands
blocked.packages=sun,\
jdk,\
java.lang.reflect,\
java.lang.invoke,\
org.togetherjava
# Classes listed here will not be able to be used in JShell commands
blocked.classes=java.lang.ProcessBuilder,\
java.lang.ProcessHandle,\
java.lang.Runtime
# Methods listed here will not be able to be used in JShell commands
blocked.methods=java.lang.System#exit,\
java.lang.Thread#sleep,\
java.lang.Thread#wait,\
java.lang.Thread#notify,\
java.lang.Thread#currentThread