diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..4f442e0 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,33 @@ +name: Backend + +on: + workflow_dispatch: {} + push: + branches: + - "main" + paths: + - ".github/workflows/backend.yml" + - "backend/*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: docker/Dockerfile.backend + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/txpipe/asteria-backend:${{ github.sha }} diff --git a/.gitignore b/.gitignore index 397a47c..65b4e38 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,3 @@ target # .env files **/.env - -# sqlx -**/.sqlx \ No newline at end of file diff --git a/backend/.sqlx/query-d234cba02f8f6fa0620368c1a6c164859c6a6efaade36ffa824a1bcbda537664.json b/backend/.sqlx/query-d234cba02f8f6fa0620368c1a6c164859c6a6efaade36ffa824a1bcbda537664.json new file mode 100644 index 0000000..7fb9857 --- /dev/null +++ b/backend/.sqlx/query-d234cba02f8f6fa0620368c1a6c164859c6a6efaade36ffa824a1bcbda537664.json @@ -0,0 +1,72 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, fuel, positionX as position_x, positionY as position_y, shipyardPolicy as policy_id, shipTokenName as token_name, pilotTokenName as pilot_name, class, totalRewards as total_rewards\n FROM MapObjects\n WHERE positionX BETWEEN ($1::int - $3::int) AND ($1::int + $3::int)\n AND positionY BETWEEN ($2::int - $3::int) AND ($2::int + $3::int)\n AND ABS(positionX - $1::int) + ABS(positionY - $2::int) <= $3::int", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "fuel", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "position_x", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "position_y", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "policy_id", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "token_name", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "pilot_name", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "class", + "type_info": "Varchar" + }, + { + "ordinal": 8, + "name": "total_rewards", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Int4" + ] + }, + "nullable": [ + false, + true, + false, + false, + true, + true, + true, + false, + true + ] + }, + "hash": "d234cba02f8f6fa0620368c1a6c164859c6a6efaade36ffa824a1bcbda537664" +} diff --git a/backend/docs/example.sql b/backend/docs/example.sql index f1ca1f9..bd76ef0 100644 --- a/backend/docs/example.sql +++ b/backend/docs/example.sql @@ -1,9 +1,9 @@ -- Insert the central RewardPot -INSERT INTO MapObjects (id, type, positionX, positionY, totalRewards) +INSERT INTO MapObjects (id, class, positionX, positionY, totalRewards) VALUES ('rewardpot01', 'RewardPot', 0, 0, 1000.0); -- Ships -INSERT INTO MapObjects (id, type, positionX, positionY, fuel, shipyardPolicy, shipTokenName, pilotTokenName) +INSERT INTO MapObjects (id, class, positionX, positionY, fuel, shipyardPolicy, shipTokenName, pilotTokenName) VALUES ('ship01', 'Ship', 1, 0, 100, 'policy01', 'tokenName01', 'pilotName01'), ('ship02', 'Ship', -1, 0, 120, 'policy02', 'tokenName02', 'pilotName02'), ('ship03', 'Ship', 0, 1, 110, 'policy03', 'tokenName03', 'pilotName03'), @@ -12,7 +12,7 @@ VALUES ('ship01', 'Ship', 1, 0, 100, 'policy01', 'tokenName01', 'pilotName01'), ('ship06', 'Ship', -2, -1, 150, 'policy06', 'tokenName06', 'pilotName06'); -- FuelPellets -INSERT INTO MapObjects (id, type, positionX, positionY, fuel) +INSERT INTO MapObjects (id, class, positionX, positionY, fuel) VALUES ('fuel01', 'FuelPellet', 1, 1, 50), ('fuel02', 'FuelPellet', 2, 0, 60), ('fuel03', 'FuelPellet', -1, 2, 70), diff --git a/backend/docs/table.sql b/backend/docs/table.sql index daf285c..cb2b387 100644 --- a/backend/docs/table.sql +++ b/backend/docs/table.sql @@ -11,5 +11,5 @@ CREATE TABLE MapObjects ( ); -- Indexes for performance optimization -CREATE INDEX idx_mapobjects_type ON MapObjects(type); -CREATE INDEX idx_mapobjects_position ON MapObjects(positionX, positionY); \ No newline at end of file +CREATE INDEX idx_mapobjects_class ON MapObjects(class); +CREATE INDEX idx_mapobjects_position ON MapObjects(positionX, positionY); diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend new file mode 100644 index 0000000..d995e1f --- /dev/null +++ b/docker/Dockerfile.backend @@ -0,0 +1,16 @@ +FROM rust:1.77-slim-buster as build + +WORKDIR /app + +RUN apt update +RUN apt install -y build-essential pkg-config libssl-dev cmake libasound2-dev libudev-dev + +COPY ./Cargo.toml ./Cargo.toml +COPY ./backend ./backend +COPY ./visualizer ./visualizer + +RUN cargo build --release + +FROM rust:1.77-slim-buster +COPY --from=build /app/target/release/asteria-backend . +CMD ["./asteria-backend"]