Skip to content

Commit

Permalink
Separate packages for core lib and server
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed Dec 8, 2024
1 parent af3c4c9 commit 64e3e11
Show file tree
Hide file tree
Showing 88 changed files with 6,082 additions and 104 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target/
/.env
/node_modules/
rust-toolchain.toml
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
27 changes: 26 additions & 1 deletion Cargo.lock

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

58 changes: 8 additions & 50 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
[package]
name = "citadels"
edition = "2021"
default-run = "citadels"
version = "0.7.1"

[[bin]]
name = "citadels"
path = "src/main.rs"

[dependencies]
askama = { version = "0.12.1", default-features = false }
axum = { version = "0.7.2", features = ["ws","macros"], default-features = true }
axum-extra = { version = "0.9.0", features = ["cookie-private"], default-features = false }
futures = { version = "0.3.30", default-features = false }
http = { version = "1.0.0", default-features = false }
rand = { version = "0.8.5", default-features = false }
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.14", default-features = false }
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
log = "0.4.20"
env_logger = { version = "0.10.1", features = ["color"] }
rand_xoshiro = "0.6.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
serde = { version = "1.0.195", features = ["derive", "rc"] }
serde_json = "1.0.111"
time = "0.3.31"
dotenv = { version = "0.15.0", optional = true }
axum-core = "0.4.3"
serde_with = "3.5.0"
tracing = { version = "0.1.40", default-features = false }
macros = { path = "./macros"}
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
anyhow = { version = "1.0.83", default-features = true }
maud = { version = "0.26.0", features = ["axum"], default-features = false}
arcstr = { version = "1.2.0", features = ["serde"], default-features = false }
uuid = { version = "1.8.0", features = ["v4"] }
thiserror = "1.0.61"

[features]
dev = []
dotenv = ["dep:dotenv"]

# https://old.reddit.com/r/rust/comments/gvrgca/this_is_a_neat_trick_for_getting_good_runtime/
[profile.dev.package."*"]
opt-level = 3

[profile.dev]
opt-level = 0
[workspace]
resolver = "2"
members = [
"citadels_server",
"citadels",
"macros",
"macros-impl"
]
21 changes: 8 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# syntax=docker/dockerfile:1.3.1
# https://github.com/LukeMathWalker/cargo-chef?tab=readme-ov-file#without-the-pre-built-image
FROM rust:alpine AS chef
RUN apk add --no-cache musl-dev
RUN cargo --version
RUN cargo install cargo-chef

FROM lukemathwalker/cargo-chef:latest-rust-1.80.1 AS chef
WORKDIR /app

FROM chef AS planner
Expand All @@ -14,16 +10,15 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

COPY macros/ macros/
COPY macros-impl/ macros-impl/

# build dependencies
RUN cargo chef cook --release --recipe-path recipe.json
# Build application

# build application
COPY . .
RUN cargo build --release --bin citadels
RUN cargo build --release --bin citadels_server

FROM alpine AS runtime
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/citadels /usr/local/bin
COPY --from=builder /app/target/release/citadels_server /usr/local/bin
COPY public/ public/
ENTRYPOINT ["/usr/local/bin/citadels"]
ENTRYPOINT ["/usr/local/bin/citadels_server"]
29 changes: 29 additions & 0 deletions citadels/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "citadels"
edition = "2021"


[dependencies]
rand = { version = "0.8.5" }
log = "0.4.20"
env_logger = { version = "0.10.1", features = ["color"] }
rand_xoshiro = "0.6.0"

rand_core = { version = "0.6.4", features = ["getrandom"] }
serde = { version = "1.0.195", features = ["derive", "rc"] }
serde_json = "1.0.111"
time = "0.3.31"
dotenv = { version = "0.15.0", optional = true }
serde_with = "3.5.0"
tracing = { version = "0.1.40", default-features = false }
macros = { path = "../macros"}
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
anyhow = { version = "1.0.83", default-features = true }
maud = { version = "0.26.0", features = ["axum"], default-features = false}
arcstr = { version = "1.2.0", features = ["serde"], default-features = false }
uuid = { version = "1.8.0", features = ["v4"] }
thiserror = "1.0.61"

[features]
dev = []
dotenv = ["dep:dotenv"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions src/lib.rs → citadels/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ pub mod game;
pub mod game_actions;
pub mod lobby;
pub mod logger;
pub mod markup;
pub mod museum;
pub mod random;
pub mod roles;
pub mod server;
pub mod templates;
pub mod types;
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions src/museum.rs → citadels/src/museum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ impl Museum {
if self.cards.len() > self.artifacts.len() {
let mut artifacts = Museum::ARTIFACTS;
artifacts.shuffle(&mut rand::thread_rng());
for artifact in artifacts {
self.artifacts.push(artifact);
}
self.artifacts.extend(artifacts);
}
}

const ARTIFACTS: [&'static str; 19] = [
"⚱️", "🏺", "🖼️", "🗿", "🏛️", "⛲", "🕰️", "🦴", "🦾", "⚰️", "🚀", "🦖", "🦣", "🦤", "🦕", "💎",
"🪩", "🔱", "🧋",
"⚱️", "🏺", "🖼️", "🗿", "🏛️", "⛲", "🕰️", "🦴", "🦾", "⚰️", "🚀", "🦖", "🦣", "🦤", "🦕",
"💎", "🪩", "🔱", "🧋",
];
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions citadels_server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "citadels_server"
edition = "2021"


[dependencies]
citadels = { path = "../citadels/" }
askama = { version = "0.12.1", default-features = false }
axum = { version = "0.7.2", features = ["ws","macros"], default-features = true }
axum-extra = { version = "0.9.0", features = ["cookie-private"], default-features = false }
futures = { version = "0.3.30", default-features = false }
http = { version = "1.0.0", default-features = false }
rand = { version = "0.8.5", default-features = false }
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.14", default-features = false }
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
log = "0.4.20"
env_logger = { version = "0.10.1", features = ["color"] }
rand_xoshiro = "0.6.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
serde = { version = "1.0.195", features = ["derive", "rc"] }
serde_json = "1.0.111"
time = "0.3.31"
dotenv = { version = "0.15.0", optional = true }
axum-core = "0.4.3"
serde_with = "3.5.0"
tracing = { version = "0.1.40", default-features = false }
macros = { path = "../macros"}
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
anyhow = { version = "1.0.83", default-features = true }
maud = { version = "0.26.0", features = ["axum"], default-features = false}
arcstr = { version = "1.2.0", features = ["serde"], default-features = false }
uuid = { version = "1.8.0", features = ["v4"] }
thiserror = "1.0.61"

[features]
dev = []
dotenv = ["dep:dotenv"]
3 changes: 3 additions & 0 deletions citadels_server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod markup;
pub mod server;
pub mod templates;
2 changes: 1 addition & 1 deletion src/main.rs → citadels_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use citadels::server::routes::get_router;
use citadels_server::server::routes::get_router;

#[tokio::main]
async fn main() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/server/routes.rs → citadels_server/src/server/routes.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use crate::actions::{ActionSubmission, ActionTag};
use crate::districts::DistrictName;
use crate::game::Game;
use crate::lobby::{ConfigOption, Lobby};
use crate::roles::{Rank, RoleName};
use crate::server::state::AppState;
use crate::templates::game::menu::*;
use crate::templates::game::menus::*;
use crate::templates::game::*;
use crate::templates::lobby::*;
use crate::templates::*;
use crate::types::{Marker, PlayerName};
use askama::Template;
use axum::extract::{Json, Path, State};
use axum::response::{ErrorResponse, Html, Redirect, Response, Result};
use axum::routing::{get, post};
use axum::Router;
use axum::{extract::ws::WebSocketUpgrade, response::IntoResponse};
use axum_extra::extract::{cookie::Cookie, PrivateCookieJar};
use citadels::actions::{ActionSubmission, ActionTag};
use citadels::districts::DistrictName;
use citadels::game::Game;
use citadels::lobby::{ConfigOption, Lobby};
use citadels::roles::{Rank, RoleName};
use citadels::types::{Marker, PlayerName};
use http::StatusCode;
use rand_core::SeedableRng;
use serde::Deserialize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::server::ws;
use crate::{game::Game, lobby::Lobby};
use axum::extract::FromRef;
use axum_extra::extract::cookie;
use citadels::{game::Game, lobby::Lobby};
use std::sync::{Arc, Mutex};

#[derive(Clone)]
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/templates.rs → citadels_server/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pub mod lobby;

use std::borrow::Cow;

use crate::districts::DistrictName;
use crate::game::{CityDistrict, Game};
use crate::roles::{Rank, RoleName};
use crate::types::CardSuit;
use askama::Template;
use axum::response::Html;
use citadels::districts::DistrictName;
use citadels::game::{CityDistrict, Game};
use citadels::roles::{Rank, RoleName};
use citadels::types::CardSuit;

#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum GamePhase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::actions::ActionTag;
use crate::types::CardSuit;
use citadels::actions::ActionTag;
use citadels::types::CardSuit;
use std::borrow::Cow;
use std::fmt::Debug;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub mod menu;
pub mod menus;

use crate::actions::ActionTag;
use crate::game::{Game, GameRole, Player, PlayerIndex, Turn};
use crate::roles::RoleName;
use crate::templates::game::menu::{MenuTemplate, MenuView};
use crate::templates::MyTemplate;
use crate::templates::{filters, DAISY_THEMES};
use crate::templates::{DistrictTemplate, RoleTemplate};
use crate::types::Marker;
use askama::Template;
use axum::response::Html;
use citadels::actions::ActionTag;
use citadels::game::{Game, GameRole, Player, PlayerIndex, Turn};
use citadels::roles::RoleName;
use citadels::types::Marker;
use std::borrow::{Borrow, Cow};

#[derive(Template)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{get_myself, GameContext};
use crate::actions::ActionTag;
use crate::game::{Call, Draft, Followup, ForcedToGatherReason, Game, Player, Turn};
use crate::roles::{Rank, RoleName};
use crate::templates::filters;
use crate::templates::game::menus::{BuildMenu, EmperorMenu};
use crate::templates::{DistrictTemplate, RoleTemplate};
use askama::Template;
use citadels::actions::ActionTag;
use citadels::game::{Call, Draft, Followup, ForcedToGatherReason, Game, Player, Turn};
use citadels::roles::{Rank, RoleName};
use std::borrow::{Borrow, Cow};

#[derive(Template)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::actions::ActionTag;
use crate::districts::DistrictName;
use crate::game::{self, Followup, Game, Player};
use crate::roles::RoleName;
use crate::templates::{filters, DistrictTemplate, RoleTemplate};
use crate::types::CardSuit;
use crate::types::Marker;
use askama::Template;
use citadels::actions::ActionTag;
use citadels::districts::DistrictName;
use citadels::game::{self, Followup, Game, Player};
use citadels::roles::RoleName;
use citadels::types::CardSuit;
use citadels::types::Marker;

use std::borrow::{Borrow, Cow};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::templates::filters;
use crate::templates::{DistrictTemplate, RoleTemplate};
use crate::{
use askama::Template;
use citadels::{
data::characters::ROLES,
districts::{DistrictName, UNIQUE},
lobby::{ConfigOption, Player},
roles::{Rank, RoleName},
};
use askama::Template;
use std::collections::{HashMap, HashSet};

#[derive(Template)]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5,937 changes: 5,936 additions & 1 deletion public/styles/index.css

Large diffs are not rendered by default.

0 comments on commit 64e3e11

Please sign in to comment.