diff --git a/.gitignore b/.gitignore index 4f63f428..eb66c3ae 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,9 @@ server/algorithms/src/routing/tsp # misc .idea/* .DS_Store + +# or-tools +or-tools/**/* +!or-tools/tsp +!or-tools/install.sh +or-tools.tar.gz diff --git a/README.md b/README.md index 72cd8e37..81a8b16d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,22 @@ ## Installation +### Docker (Recommended) + +### Temp Authenticate + +1. `docker login ghcr.io/turtiesocks/koji` +2. Enter your GitHub username +3. Enter your GitHub authentication token + +4. If you don't already have a `docker-compose.yml` file, `touch docker-compose.yml` +5. Copy the contents of the example [docker-compose.yml](./docker-compose.example.yml) file +6. `nano docker-compose.yml` +7. Paste the copied contents +8. Set the env variables as above +9. `docker-compose pull` +10. `docker-compose up -d` + ### Standard 1. Clone this repo: @@ -29,53 +45,53 @@ git clone https://github.com/TurtIeSocks/Koji.git 2. [Install NodeJS](https://nodejs.dev/en/learn/how-to-install-nodejs/) 3. [Install Rust](https://www.rust-lang.org/tools/install) -4. Copy the env file: +4. Install OR-Tools +5. [Check PreReqs](https://developers.google.com/optimization/install/cpp/binary_linux#prerequisites) + +For example, on Ubuntu 20.04: + +```bash +sudo apt update +sudo apt install -y build-essential cmake lsb-release +``` + +6. Run the install script: + +```bash +sudo chmod +x or-tools/install.sh && ./or-tools/install.sh +``` + +7. Copy the env file: ```bash cd server && cp .env.example .env ``` -5. Edit the env file: `nano .env` +8. Edit the env file: `nano .env` - Set the `SCANNER_DB_URL` to your RDM database url - Set the `KOJI_DB_URL` to the database you want Kōji to write migrations to - Set `KOJI_SECRET` to your preferred secret, this will be used for the bearer token when calling the API and logging into the client - Set `START_LAT` and `START_LON` to wherever you want the map to start -6. Compile the client: +9. Compile the client: ```bash cd ../client && yarn install && yarn build ``` -7. Compile the server: +10. Compile the server: ```bash cd ../server && cargo run -r # you might have to also install pkg-config (`apt install pkg-config`) ``` -8. Optionally install [pm2](https://pm2.keymetrics.io/) to run the server in the background: +11. Optionally install [pm2](https://pm2.keymetrics.io/) to run the server in the background: ```bash npm install pm2 -g pm2 start "cargo run -r" --name koji # from the /server folder ``` -### Docker (Recommended) - -### Temp Authenticate - -1. `docker login ghcr.io/turtiesocks/koji` -2. Enter your GitHub username -3. Enter your GitHub authentication token - -4. If you don't already have a `docker-compose.yml` file, `touch docker-compose.yml` -5. Copy the contents of the example [docker-compose.yml](./docker-compose.example.yml) file -6. `nano docker-compose.yml` -7. Paste the copied contents -8. Set the env variables as above -9. `docker-compose pull` -10. `docker-compose up -d` - ### Using the Client 1. Open a browser with whatever port you specified in the `.env` or `docker-compose.yml` file. (default is 8080) @@ -84,12 +100,14 @@ cd ../server && cargo run -r ### Updating Local Repo: + 1. `git pull` 2. `cd client && yarn install && yarn build` 3. `cd ../server && cargo run -r` 4. If using pm2, `pm2 restart koji` Docker: + 1. `docker-compose pull` 2. `docker-compose down && docker-compose up -d` diff --git a/or-tools/install.sh b/or-tools/install.sh new file mode 100755 index 00000000..911a7f90 --- /dev/null +++ b/or-tools/install.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +os=$OSTYPE +cpu=$(uname -p) + +if [[ $PWD != *"or-tools"* ]]; then + cd ./or-tools +fi + +echo Found $os $cpu + +if [ ! -d "source" ]; then + url="" + if [[ "$os" == "linux-gnu"* ]]; then + distro=$(cat /etc/os-release | grep "^ID=" | cut -d '=' -f 2) + version=$(cat /etc/os-release | grep "^VERSION_ID=" | cut -d '=' -f 2) + distro=${distro//\"/} + version=${version//\"/} + echo Found distro $distro $version + url="https://github.com/google/or-tools/releases/download/v9.5/or-tools_amd64_${distro}-${version}_cpp_v9.5.2237.tar.gz" + elif [[ "$os" == "darwin"* ]]; then + if [[ "$cpu" == "arm" ]]; then + cpu="arm64" + fi + url="https://github.com/google/or-tools/releases/download/v9.5/or-tools_${cpu}_macOS-13.0.1_cpp_v9.5.2237.tar.gz" + else + echo "Unsupported OS, contact the developer" + exit 1 + fi + curl -L $url -o ortools.tar.gz + tar -xzf ortools.tar.gz + mv ./or-tools_* ./source + rm ortools.tar.gz +fi +cd source +mkdir examples/koji +cp ../tsp/tsp.cc ./examples/koji/koji.cc +cp ../tsp/CMakeLists.txt ./examples/koji/CMakeLists.txt +make build SOURCE=examples/koji/koji.cc +mv ./examples/koji/build/bin/koji ../../server/algorithms/src/routing/tsp