Skip to content
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

feat: revamp build system #79

Merged
merged 3 commits into from
Nov 11, 2024
Merged
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
23 changes: 10 additions & 13 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ permissions:
contents: read

jobs:
clippy_check:
format_and_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Clippy
run: cargo clippy --all-targets --all-features
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: mbrobbel/rustfmt-check@master
- uses: actions-rs/toolchain@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
toolchain: stable
override: true
- uses: davidB/rust-cargo-make@v1
- uses: actions/checkout@v1
- name: Run rustfmt and clippy executing setup if needed
run: cargo make format-and-lint
env:
DATABASE_URL: "sqlite://database.db"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ anyhow = "1.0.93"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
strum = {version="0.26.3", features = ["derive"]}
fastrand = "2.1.1"
fastrand = "2.2.0"
counter = "0.6.0"
ordered-float = { version = "4", features = ["serde"]}
num-traits = "0.2.19"
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ RUN apk add build-base

RUN apk add musl-dev

RUN apk add python3

# Build the project with optimizations
RUN cargo build --target x86_64-unknown-linux-musl --release
RUN cargo install --no-default-features --force cargo-make
RUN cargo make bybe-docker-release

# Stage 2: Create a minimal runtime image
FROM alpine:latest
Expand Down
62 changes: 62 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[tasks.clean]
command = "cargo"
args = ["clean"]

[tasks.prebuild]
command = "python3"
args = ["setup.py", "--db_version", "2.3.0"]

[tasks.format]
install_crate = "rustfmt"
command = "cargo"
args = ["fmt"]

[tasks.lint]
command = "cargo"
args = ["clippy", "--all-targets", "--all-features"]
dependencies = ["clean", "prebuild"]

[tasks.build]
command = "cargo"
args = ["build"]
dependencies = ["clean", "prebuild"]

[tasks.build-release]
command = "cargo"
args = ["build", "--release"]
dependencies = ["clean", "prebuild"]

[tasks.build-docker-release]
command = "cargo"
args = ["build", "--target", "x86_64-unknown-linux-musl", "--release"]
dependencies = ["clean", "prebuild"]

[tasks.test]
command = "cargo"
args = ["test"]
dependencies = ["clean", "prebuild"]

[tasks.bybe-build]
dependencies = [
"format",
"build",
"clippy",
"test"
]

[tasks.bybe-release]
dependencies = [
"test",
"build-release"
]

[tasks.bybe-docker-release]
dependencies = [
"build-docker-release"
]

[tasks.format-and-lint]
dependencies = [
"format",
"lint"
]
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
)
![SQLite](https://img.shields.io/badge/sqlite-%2307405e.svg?style=for-the-badge&logo=sqlite&logoColor=white)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)


[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/new_code?id=RakuJa_BYBE)
[![Built with cargo-make](https://sagiegurari.github.io/cargo-make/assets/badges/cargo-make.svg)](https://sagiegurari.github.io/cargo-make)

# BYBE - Backend

Expand Down Expand Up @@ -34,48 +32,52 @@ Built using:
2. Populate the SQLite database (public release date TBA).
3. Clone this repository:

```
```bash
git clone https://github.com/RakuJa/BYBE
```

4. Navigate to the project's main directory.
5. Build the project:

5. Build the project running all the tests and downloading the db (required only once):
```bash
cargo make bybe-build
```
6. Build the project

```bash
cargo build
```
6. Set DATABASE_URL variable to SQLite db path
7. Run the backend in development mode:

```
```bash
cargo run
```

8. To instead deploy the production build, run:

```
```bash
cargo build --release
```

```
```bash
cargo run
```

## Installation guide using Docker

1. Install Docker on your local machine
2. Clone the repository or download the ZIP
```
```bash
git clone https://github.com/RakuJa/BYBE
```
3. Go to the local BYBE project folder

4. Build docker image of bybe using
```
```bash
docker build -t bybe .
```
5. Run the image
```
```bash
docker run -p 25566:25566 --name bybe-container bybe
```

Expand All @@ -87,5 +89,5 @@ If you like this tool, consider supporting me:

Also consider supporting [TheAsel](https://github.com/TheAsel), the frontend developer. Thank you!

## BYBE - Client
## BYBE-Portable
If you were looking for the BYBE Local Application, it can be found [Here](https://github.com/rakuJa/BYBE-desktop)
2 changes: 1 addition & 1 deletion build/creature_core_db_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn create_creature_core_table(conn: &Pool<Sqlite>) -> Result<()> {
source TEXT NOT NULL DEFAULT '',
remaster BOOL NOT NULL DEFAULT 0,
alignment TEXT NOT NULL DEFAULT NO
)"
)",
)
.execute(conn)
.await?;
Expand Down
47 changes: 47 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# setup.py
import os
import urllib.request
import getopt, sys
from typing import Optional

# Remove 1st argument from the
# list of command line arguments
argumentList = sys.argv[1:]

# Options
options = "hd:"

# Long options
long_options = ["help", "db_version="]

def handle_command_line_arguments() -> Optional[str]:
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, long_options)

# checking each argument
for currentArgument, currentValue in arguments:

if currentArgument in ("-h", "--help"):
print("This script downloads or creates necessary file to build BYBE. \n"
"Should be executed the first time the project is built in the machine or when resetting the database \n"
"Pass the --db_version or -v argument to input a specific BYBE-DB version to download (>= 2.3.0)")
elif currentArgument in ("-d", "--db_version"):
return currentValue
except getopt.error:
pass

def main():
# Check if the file already exists or needs downloading
db_version: str = handle_command_line_arguments() or "2.3.0"
print(db_version)
remote_url: str = f"https://github.com/RakuJa/BYBE-DB/releases/download/v{db_version}/database.db"
destination_file: str = "database.db"
if not os.path.exists(destination_file):
print("Downloading the database file...")
urllib.request.urlretrieve(remote_url, destination_file)
else:
print("Database file already exists, skipping download.")

if __name__ == '__main__':
main()
8 changes: 4 additions & 4 deletions src/services/shop_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ mod tests {
#[case] expected: (i64, i64, i64, i64),
) {
let result = calculate_n_of_equippable_values(input_n_of_equippables, input_percentages);
assert_eq!(true, result.is_ok());
assert!(result.is_ok());
assert_eq!(expected, result.unwrap());
}

Expand All @@ -233,7 +233,7 @@ mod tests {
#[case] expected: (i64, i64, i64, i64),
) {
let result = calculate_n_of_equippable_values(input_n_of_equippables, input_percentages);
assert_eq!(true, result.is_ok());
assert!(result.is_ok());
assert_eq!(expected, result.unwrap());
}

Expand All @@ -246,7 +246,7 @@ mod tests {
#[case] expected: (i64, i64, i64, i64),
) {
let result = calculate_n_of_equippable_values(input_n_of_equippables, input_percentages);
assert_eq!(true, result.is_ok());
assert!(result.is_ok());
assert_eq!(expected, result.unwrap());
}

Expand All @@ -260,7 +260,7 @@ mod tests {
#[case] expected: (i64, i64, i64, i64),
) {
let result = calculate_n_of_equippable_values(input_n_of_equippables, input_percentages);
assert_eq!(true, result.is_ok());
assert!(result.is_ok());
assert_eq!(expected, result.unwrap());
}
}
Loading