Skip to content

Version 5 #66

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

Open
wants to merge 6 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
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down
35 changes: 16 additions & 19 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
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.
34 changes: 8 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <vardy@riseup.net>"

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 '(?<=<version>).*?(?=</version>)' /IB.ai/pom.xml)" && \
java -jar /IB.ai/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"]
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <vardy@riseup.net>"

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 '(?<=<version>).*?(?=</version>)' /IB.ai/pom.xml)" && \
java -jar /IB.ai/target/IB.ai.jar
29 changes: 29 additions & 0 deletions dev.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 0 additions & 18 deletions prod.Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions v5.txt
Original file line number Diff line number Diff line change
@@ -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