From 79dc56d1799c39df37f81136528e9dfd7f75f0b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:21:42 +0000 Subject: [PATCH] Add emotes HTML page at /, health endpoint, Dockerfile, and Docker workflow Agent-Logs-Url: https://github.com/Open3DLab/mikebase/sessions/349bd27e-61d5-40d4-b4d1-0c552a78a9e2 Co-authored-by: Ganonmaster <168445+Ganonmaster@users.noreply.github.com> --- .github/workflows/docker.yml | 47 +++++++++++++++++++ Dockerfile | 33 +++++++++++++ src/main.rs | 1 + src/routes/emotes.rs | 6 +-- src/routes/health.rs | 8 ++++ src/routes/mod.rs | 1 + src/templates/index.html | 90 ++++++++++++++++++++++++++++++++++++ 7 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 src/routes/health.rs create mode 100644 src/templates/index.html diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..40a90e9 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,47 @@ +name: Docker + +on: + push: + tags: + - "v*" + +jobs: + docker: + name: Build and push Docker image + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker registry + uses: docker/login-action@v3 + with: + registry: ${{ vars.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a0309d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM rust:1.85-bookworm AS builder + +WORKDIR /app + +# Copy manifests first for better layer caching +COPY Cargo.toml Cargo.lock ./ + +# Create a dummy main to cache dependency compilation +RUN mkdir src && echo "fn main() {}" > src/main.rs && \ + mkdir migrations && touch migrations/.keep && \ + echo "fn main() {}" > build.rs && \ + cargo build --release && \ + rm -rf src build.rs migrations + +# Copy real source code +COPY . . + +# Touch main.rs so cargo knows it changed +RUN touch src/main.rs && cargo build --release + +# Runtime stage +FROM debian:bookworm-slim + +RUN apt-get update && \ + apt-get install -y --no-install-recommends ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=builder /app/target/release/mikebase /usr/local/bin/mikebase +COPY --from=builder /app/config.example.toml /etc/mikebase/config.example.toml + +EXPOSE 3000 + +CMD ["mikebase"] diff --git a/src/main.rs b/src/main.rs index c895e51..0677932 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ async fn main() { let app = Router::new() .route("/", get(routes::emotes::root)) + .route("/health", get(routes::health::health)) .route("/version", get(routes::version::version)) .route("/json", get(routes::emotes::list_emotes)) .route("/emotes", post(routes::emotes::create_emote)) diff --git a/src/routes/emotes.rs b/src/routes/emotes.rs index 736e233..2e87e30 100644 --- a/src/routes/emotes.rs +++ b/src/routes/emotes.rs @@ -1,7 +1,7 @@ use axum::{ extract::{Multipart, Path, State}, http::StatusCode, - response::{IntoResponse, Json}, + response::{Html, IntoResponse, Json}, }; use serde_json::json; @@ -11,9 +11,9 @@ use crate::{ }; /// GET / -/// Returns a simple health-check message. +/// Serves an HTML page that dynamically loads and displays emotes from /json. pub async fn root() -> impl IntoResponse { - Json(json!({"status": "ok", "message": "mikebase server is running"})) + Html(include_str!("../templates/index.html")) } /// GET /json diff --git a/src/routes/health.rs b/src/routes/health.rs new file mode 100644 index 0000000..9aa9aa9 --- /dev/null +++ b/src/routes/health.rs @@ -0,0 +1,8 @@ +use axum::response::{IntoResponse, Json}; +use serde_json::json; + +/// GET /health +/// Returns a simple health-check response. +pub async fn health() -> impl IntoResponse { + Json(json!({"status": "ok"})) +} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 39bf7e9..4cb0bc3 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,2 +1,3 @@ pub mod emotes; +pub mod health; pub mod version; diff --git a/src/templates/index.html b/src/templates/index.html new file mode 100644 index 0000000..6b8a818 --- /dev/null +++ b/src/templates/index.html @@ -0,0 +1,90 @@ + + +
+ + +