diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0792132 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM openjdk:8-alpine + +RUN apk add --no-cache maven + +COPY . /usr/src/unobot +WORKDIR /usr/src/unobot +RUN mvn package +CMD java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar diff --git a/README.md b/README.md index 34c93bd..70119ca 100755 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ and allows members of the channel to play a game of uno. It also has an AI so it 1. You must have Java 1.7 JDK or higher installed. 2. The Java bin folder must be in your classpath if you are running windows. 3. Maven +4. Alternatively: The bot can be run with only having docker installed. ## Installation @@ -17,6 +18,13 @@ and allows members of the channel to play a game of uno. It also has an AI so it 3. run `mvn package` (you will have to cd to UnoBot's directory) 4. run `UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` using the `java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` command +## Running with Docker + +1. `docker build . -t unobot` +2. `docker-compose up` +3. Set the CONFIG_PATH to provide a location to store the scoreboard file and the config.ini (if using the config.ini file). +4. All of the key:value pairs from the config file can be used when starting the docker container and have the same effect. If there is no config file found in the CONIFG_PATH, the environment variables will be used + ### values in the config file Server - if no value given it will default to localhost diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..62c429b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +--- +version: "3.2" + +services: + unobot: + image: 127.0.0.1:5000/unobot + environment: + CONFIG_PATH: /config/ # Primarily storing the scoreboard file + Server: irc.freenode.net + Port: 6697 + Nick: unoBot + Channel: #spdcx + BotOps: roofis0 + UpdateScript: ./runUnoBot.sh + Verbose: "true" + SSL: "true" + + volumes: + - /mnt/data/unobot:/config + diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index 8113a0d..7d57709 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -28,16 +28,38 @@ * @author roofis0 */ public class UnoBotMain { - - public static void main(String[] args) throws Exception { Properties p = new Properties(); - try (FileInputStream in = new FileInputStream(new File("./config.ini"))) { - p.load(in); + + String path = getVarOrDefault("CONFIG_PATH","./"); + String filename = path + "/config.ini"; + File configFile = new File(filename); + if (configFile.exists()) { + try (FileInputStream in = new FileInputStream(configFile)) { + p.load(in); + } + } else { // Allows loading of the config values from either java properties or environment variables + putToProperties(p, "Server", getVarOrDefault("Server", "localhost")); + putToProperties(p, "Port", getVarOrDefault("Port", "6667")); + putToProperties(p, "Channel", getVarOrDefault("Channel", "#uno")); + putToProperties(p, "Nick", getVarOrDefault("Nick", "unoBot")); + + putToProperties(p, "BotOps", getVarOrDefault("BotOps", "")); + putToProperties(p, "ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat")); + putToProperties(p, "UpdateScript", getVarOrDefault("UpdateScript", null)); + putToProperties(p, "SSL", getVarOrDefault("SSL", "false")); + putToProperties(p, "Token", getVarOrDefault("Token", "!")); + putToProperties(p, "nickSrvPasswd", getVarOrDefault("nickSrvPasswd", null)); + putToProperties(p, "serverPasswd", getVarOrDefault("serverPasswd", null)); + putToProperties(p, "webIRCPasswd", getVarOrDefault("webIRCPasswd", null)); + + putToProperties(p, "aiWebIRCPasswd", getVarOrDefault("aiWebIRCPasswd", null)); + putToProperties(p, "aiServerPasswd", getVarOrDefault("aiServerPasswd", null)); + putToProperties(p, "aiNickSrvPasswd", getVarOrDefault("aiNickSrvPasswd", null)); + putToProperties(p, "AINick", getVarOrDefault("AINick", "unoAI")); } - // System.setProperty("socksProxyHost", "localhost"); // System.setProperty("socksProxyPort", "9999"); @@ -116,6 +138,18 @@ public static void main(String[] args) throws Exception { System.exit(0); } } + + public static String getVarOrDefault(String key, String def) { + String javaProp = System.getProperty(key, def); + return System.getenv().getOrDefault(key, javaProp); + } + + public static void putToProperties(Properties p, String key, String value) { + if (value == null) { + return; + } + p.setProperty(key, value); + } static class ExceptionListener extends ListenerAdapter { @Override