Skip to content

Commit

Permalink
chore: Dockerize backend (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Apr 18, 2024
1 parent 4874b16 commit 27bb433
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 8 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ target

# .env files
**/.env

# sqlx
**/.sqlx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions backend/docs/example.sql
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions backend/docs/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
CREATE INDEX idx_mapobjects_class ON MapObjects(class);
CREATE INDEX idx_mapobjects_position ON MapObjects(positionX, positionY);
16 changes: 16 additions & 0 deletions docker/Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 27bb433

Please sign in to comment.