diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 742e1391..b96e1be6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,8 +12,8 @@ Bug fixes and optimisations are also greatly appreciated! # VCS 1) Create a new branch (and fork if applicable). Label it appropriately. -2) Make the changes on that branch. -3) Commit to and push the changes. +2) Make the changes on that branch. Make sure to test these changes thoroughly. +3) Commit to and push the changes, once you are sure the code is functional. 4) Create a PR from your branch to master. 5) A maintainer will then review your PR. @@ -26,7 +26,6 @@ If you have questions, please ask a maintainer. * Use Java-style braces (moustache-bois). This means that the opening brace is on the same line, but the closing brace is on a new line. There must be a space before an opening brace. -* Do not use a space between a keyword and the opening parentheses `if(that)` rather than `if (that)`. * For methods that return `this`, chain them on a new line, as shown below: ![Formatting](https://i.imgur.com/7kZPU4O.png) * For long methods, feel free to split the statement over multiple statements, with one parameter per line. diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 99718878..273ac4ed 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -2,29 +2,26 @@ This document describes steps towards releasing a new version of the bot. -## Testing and building +## Developing and testing -Building with `docker build .` will run all necessary build steps and tests. If the build fails, the code is not ready to deploy. +If you have write-access to this repository: make a new branch and write the code there. +If you do not have write-access: you can choose to use master or a different branch in your clone of this repository. -On `git push origin master`, Docker Hub will automatically run the build and report the logs to https://hub.docker.com/r/pants1/ib.ai. +Modify any source code files. -## Releasing +Test by running the source code in Docker directly using: +``` +$ docker-compose -f dev.docker-compose.yml up --build +``` -New features should be merged from their feature branch onto `master` and undergo testing. Once builds pass: +On `git push origin master`, Docker Hub will automatically run the build and report the logs to https://hub.docker.com/r/pants1/ib.ai. -1. Version updated in Java project's `pom.xml` -2. Docker build tagged with new version and pushed to Docker Hub [1] -3. Latest `master` commit tagged and pushed to GitHub [2] -4. Latest source code pulled to production server, built, and ran. +## Releasing -[1] -``` -$ docker build -t pants1/ib.ai:x.y.z . -$ docker push pants1/ib.ai:x.y.z -``` +Make sure the `pom.xml` has a new version. +Commit and push all changes. -[2] -``` -$ git tag -a x.y.z -m "Description" -$ git push origin x.y.z -``` \ No newline at end of file +Create a pull request from your repository/branch into `IB.ai:master`. +This pull request will be reviewed and approved/rejected respectively. +If the pull request is accepted, the CI will automatically build the repository, and the latest version will reflect your changes. +Additionally, the `pants1/ib.ai` Docker image will also be updated, though this is currently not in use. \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d3c4d8f5..a4d75153 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,18 @@ -# Using maven base image for building with maven. -FROM maven:latest AS builder +# Using Java JDK 10 base image +FROM openjdk:10 +# Metadata LABEL "repository"="https://github.com/ib-ai/IB.ai/" LABEL "homepage"="https://discord.gg/IBO/" -LABEL "maintainer"="Jarred Vardy " - -WORKDIR /IB.ai/ - -# Resolve maven dependencies -COPY pom.xml . -COPY checkstyle.xml . -RUN mvn dependency:go-offline - -# Build from source into ./target/*.jar -COPY src ./src -RUN mvn -e -B package - -# Using Java JDK 10 base image -FROM openjdk:10 WORKDIR /IB.ai/ -# Copying maven dependencies from builder image to prevent re-downloads -COPY --from=builder /root/.m2 /root/.m2 - # Add language files COPY lang ./lang -# Copying artifacts from maven (builder) build stage -COPY --from=builder /IB.ai/pom.xml . -COPY --from=builder /IB.ai/target/ ./target +# Download the latest binary from the CI +ADD https://ci.arraying.de/job/ib-ai/lastSuccessfulBuild/artifact/target/IB.ai.jar . -# Running bot. Uses version from pom.xml to call artifact file name. -CMD VERSION="$(grep -oP -m 1 '(?<=).*?(?=)' /IB.ai/pom.xml)" && \ - java -jar /IB.ai/target/IB.ai.jar \ No newline at end of file +# Run the jar as a CMD so it can be overwritten in the run +# Could be useful for overwriting start parameters to, for example, restrict memory usage +CMD ["java", "-jar", "IB.ai.jar"] \ No newline at end of file diff --git a/README.md b/README.md index ead53b0e..d8484e57 100644 --- a/README.md +++ b/README.md @@ -32,24 +32,29 @@ Please read the `CONTRIBUTING.md` file to find out more about contributing towar ## Installation and Compilation -### From source +Create and fill in the following configuration files (neither are Git tracked): + - bot.env (see bot.example.env) + - backup.env (see backup.example.env) -Configuration files: - - bot.env - - backup.env +### Running in production -Using `Docker` and `Docker-Compose` to build container images and run: +The production version will use IB.ai's CI server to automatically obtain the jar. +Therefore, it will always run the latest release. + +Using `Docker-Compose` to build container images and run: ``` -$ docker-compose build -$ docker-compose up +$ docker-compose up --build ``` -### From Docker Hub image +### Running during development -``` -$ docker run -d -v db-data:/data redis +If there are any changes to the source code that are not reflected on the CI server, use this. +The sources will be built and subsequently run. +This may take a few minutes, especially the first time. -$ docker run -d --env-file bot.env --link redis pants1/ib.ai +Using `Docker-Compose` to build container images and run: +``` +$ docker-compose -f dev.docker-compose.yml up --build ``` ## License diff --git a/backup-example.env b/backup.example.env similarity index 100% rename from backup-example.env rename to backup.example.env diff --git a/bot-example.env b/bot.example.env similarity index 100% rename from bot-example.env rename to bot.example.env diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 00000000..d3c4d8f5 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,36 @@ +# Using maven base image for building with maven. +FROM maven:latest AS builder + +LABEL "repository"="https://github.com/ib-ai/IB.ai/" +LABEL "homepage"="https://discord.gg/IBO/" +LABEL "maintainer"="Jarred Vardy " + +WORKDIR /IB.ai/ + +# Resolve maven dependencies +COPY pom.xml . +COPY checkstyle.xml . +RUN mvn dependency:go-offline + +# Build from source into ./target/*.jar +COPY src ./src +RUN mvn -e -B package + +# Using Java JDK 10 base image +FROM openjdk:10 + +WORKDIR /IB.ai/ + +# Copying maven dependencies from builder image to prevent re-downloads +COPY --from=builder /root/.m2 /root/.m2 + +# Add language files +COPY lang ./lang + +# Copying artifacts from maven (builder) build stage +COPY --from=builder /IB.ai/pom.xml . +COPY --from=builder /IB.ai/target/ ./target + +# Running bot. Uses version from pom.xml to call artifact file name. +CMD VERSION="$(grep -oP -m 1 '(?<=).*?(?=)' /IB.ai/pom.xml)" && \ + java -jar /IB.ai/target/IB.ai.jar \ No newline at end of file diff --git a/dev.docker-compose.yml b/dev.docker-compose.yml new file mode 100644 index 00000000..4129d547 --- /dev/null +++ b/dev.docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.4' + +services: + + # The Java bot process -- uses dev.Dockerfile in ./docker/ + # Will attempt to restart 3 times. + bot: + image: ib.ai + restart: on-failure:3 + build: + context: ./ + dockerfile: dev.Dockerfile + env_file: + - bot.env + depends_on: + - db + + # Redis database + # Running on port 6379, on a failure it will restart itself + # Connect via the URL 'redis://db:6379' + db: + restart: always + image: redis + volumes: + - db-data:/data + +volumes: + # Database persistence + db-data: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b863f9b9..f8d8df47 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,14 +2,14 @@ version: '3.4' services: - # The Java bot process -- uses Dockerfile in ./docker/ + # The Java bot process -- uses dev.Dockerfile in ./docker/ # Will attempt to restart 3 times. bot: image: ib.ai restart: on-failure:3 build: context: ./ - dockerfile: prod.Dockerfile + dockerfile: Dockerfile env_file: - bot.env depends_on: diff --git a/prod.Dockerfile b/prod.Dockerfile deleted file mode 100644 index a4d75153..00000000 --- a/prod.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# Using Java JDK 10 base image -FROM openjdk:10 - -# Metadata -LABEL "repository"="https://github.com/ib-ai/IB.ai/" -LABEL "homepage"="https://discord.gg/IBO/" - -WORKDIR /IB.ai/ - -# Add language files -COPY lang ./lang - -# Download the latest binary from the CI -ADD https://ci.arraying.de/job/ib-ai/lastSuccessfulBuild/artifact/target/IB.ai.jar . - -# Run the jar as a CMD so it can be overwritten in the run -# Could be useful for overwriting start parameters to, for example, restrict memory usage -CMD ["java", "-jar", "IB.ai.jar"] \ No newline at end of file diff --git a/v5.txt b/v5.txt new file mode 100644 index 00000000..4e52be29 --- /dev/null +++ b/v5.txt @@ -0,0 +1,6 @@ +V5: + - Postgres + - Punishment overhaul + - Strip out fluff + - Discuss any features that may be bloat, strip out + - Remove language files besides English from i18n