Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions .github/workflows/backend-compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# StorageHub: Backend Compatibility Image Workflow
#
# This workflow builds and publishes a backend Docker image with custom tagging
# for compatibility with older indexer DB schemas (e.g., stagenet deployment).
#
# Trigger options:
# 1. Manual workflow dispatch with custom tag input
# 2. Push a git tag matching pattern: backend-compat-*
#
# Usage examples:
# - Push tag: git tag backend-compat-stagenet-2025-10-28 && git push origin backend-compat-stagenet-2025-10-28
# - Manual: Use GitHub Actions UI to run with custom tag
#
# Note: This workflow does NOT push to 'latest' tag - only custom tags are used.

name: StorageHub Backend Compat

on:
workflow_dispatch:
inputs:
image_tag:
description: 'Docker image tag (e.g., stagenet-compat-2025-10-28)'
required: true
type: string
push:
branches:
- 'stagenet/backend-compat'
tags:
- 'backend-compat-*'

jobs:
build_backend:
name: 'Build backend binary'
runs-on: blacksmith-16vcpu-ubuntu-2404
env:
SCCACHE_GHA_ENABLED: 'true'
RUSTC_WRAPPER: 'sccache'
CARGO_INCREMENTAL: '0'
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- uses: actions-rust-lang/[email protected]
with:
cache: true
- name: Cache cargo registry and git index
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- uses: rui314/setup-mold@v1
- name: Set build flags (use mold linker)
run: echo "RUSTFLAGS=${{ env.RUSTFLAGS }} -C linker=clang -C link-arg=-fuse-ld=mold" >> $GITHUB_ENV
- uses: ./.github/workflow-templates/setup-pnpm
- name: Install libpq-dev
run: sudo apt-get update && sudo apt-get install -y libpq-dev libclang-dev
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build backend
run: cargo build -p sh-msp-backend --release --locked
- name: Build Stats
run: sccache --show-stats || true
- name: Check Backend Built By Mold
run: readelf -p .comment target/release/sh-msp-backend
- name: Prepare artefacts (backend)
run: |
mkdir -p build
cp target/release/sh-msp-backend build/
- uses: actions/upload-artifact@v4
with:
name: backend
path: build/sh-msp-backend
if-no-files-found: error

push_backend_image:
needs: [build_backend]
name: 'Push backend Docker image to Docker Hub'
runs-on: blacksmith-16vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- name: Download backend binary from artefacts
uses: actions/download-artifact@v4
with:
name: backend
path: build/
- name: Derive image tag
id: derive-tag
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
# Extract tag name from ref (e.g., refs/tags/backend-compat-stagenet-2025-10-28)
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "image_tag=${TAG_NAME}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "branch" ]]; then
# Push to branch: use branch name + short SHA
BRANCH_NAME=$(echo "${{ github.ref_name }}" | sed 's/\//-/g')
SHORT_SHA=$(git log -1 --format='%h')
echo "image_tag=${BRANCH_NAME}-${SHORT_SHA}" >> $GITHUB_OUTPUT
else
# Use manual input
echo "image_tag=${{ github.event.inputs.image_tag }}" >> $GITHUB_OUTPUT
fi
- name: Prepare Docker tags
id: prep
run: |
DOCKER_IMAGE=moonsonglabs/storage-hub-msp-backend
TAGS="${DOCKER_IMAGE}:${{ steps.derive-tag.outputs.image_tag }}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build Docker image and push it to Docker Hub
uses: useblacksmith/build-push-action@v2
with:
context: .
file: ./docker/storage-hub-msp-backend.Dockerfile
push: true
platforms: linux/amd64
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}-msp-backend
org.opencontainers.image.description=Storage Hub MSP Backend (Compatibility Build)
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
- name: Output image information
run: |
echo "✅ Backend image published successfully!"
echo "🐳 Image: ${{ steps.prep.outputs.tags }}"
echo "📦 Pull command: docker pull ${{ steps.prep.outputs.tags }}"

6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ tokio-postgres = "0.7"
tokio-postgres-rustls = "0.13"
tokio-util = { version = "0.7", features = ["io"] }
toml = "0.8.19"
tower-http = { version = "0.5", features = ["cors"] }
tower-http = { version = "0.5", features = ["cors", "trace"] }
tracing = "0.1"
tracing-bunyan-formatter = "0.3"
tracing-subscriber = { version = "=0.3.19", features = [
Expand Down
2 changes: 0 additions & 2 deletions backend/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["full"] }
toml = { workspace = true }
tracing = { workspace = true }
tracing-bunyan-formatter = { workspace = true }
tracing-subscriber = { workspace = true }

# Local dependencies
sh-msp-backend-lib = { path = "../lib" }
Expand Down
35 changes: 1 addition & 34 deletions backend/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ use sh_msp_backend_lib::{
rpc::{AnyRpcConnection, RpcConfig, StorageHubRpcClient, WsConnection},
storage::{BoxedStorageWrapper, InMemoryStorage},
},
log::initialize_logging,
services::Services,
};
use tracing::{debug, info, warn};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

#[derive(Parser, Debug)]
#[command(name = "sh-msp-backend")]
Expand Down Expand Up @@ -142,38 +141,6 @@ fn load_config() -> Result<Config> {
Ok(config)
}

/// Initialize logging with the specified format
fn initialize_logging(log_format: LogFormat) {
let env_filter = EnvFilter::from_default_env();
let format = log_format.resolve();

match format {
LogFormat::Json => {
// JSON logging using Bunyan format
tracing_subscriber::registry()
.with(env_filter)
.with(JsonStorageLayer)
.with(BunyanFormattingLayer::new(
"storage-hub-backend".to_string(),
std::io::stdout,
))
.init();
}
LogFormat::Text => {
// Human-readable text logging
tracing_subscriber::registry()
.with(env_filter)
.with(tracing_subscriber::fmt::layer())
.init();
}
LogFormat::Auto => {
// This should have been resolved, but handle it just in case
let resolved = log_format.resolve();
initialize_logging(resolved);
}
}
}

async fn create_postgres_client(config: &Config) -> Result<Arc<DBClient>> {
debug!(target: "main::create_postgres_client", "Creating PostgreSQL client");

Expand Down
3 changes: 3 additions & 0 deletions backend/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ tokio-util = { workspace = true }
toml = { workspace = true }
tower-http = { workspace = true }
tracing = { workspace = true }
tracing-bunyan-formatter = { workspace = true }
tracing-subscriber = { workspace = true }
rustls = { workspace = true }
rustls-platform-verifier = { workspace = true }
tokio-postgres = { workspace = true }
Expand All @@ -47,6 +49,7 @@ shc-file-manager = { workspace = true }
shc-indexer-db = { workspace = true, default-features = true }
shp-file-metadata = { workspace = true }
shc-rpc = { workspace = true, features = ["std"] }
shp-constants = { workspace = true }
shp-types = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions backend/lib/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod validation;
use axum::Router;
use tower_http::cors::CorsLayer;

use crate::services::Services;
use crate::{log, services::Services};

/// Creates the axum application with all routes and middleware
pub fn create_app(services: Services) -> Router {
Expand All @@ -16,7 +16,10 @@ pub fn create_app(services: Services) -> Router {
// Add CORS layer for permissive access
let cors = CorsLayer::permissive();

router.layer(cors)
// Add tracing layer to attach endpoint information to all logs within a request
let trace_layer = log::create_http_trace_layer();

router.layer(cors).layer(trace_layer)
}

#[cfg(all(test, feature = "mocks"))]
Expand Down
6 changes: 4 additions & 2 deletions backend/lib/src/constants/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub mod bucket {

/// Test file data
pub mod file {
use shc_indexer_db::models::FileStorageRequestStep;

/// Default file key
pub const DEFAULT_FILE_KEY: &str = "test_file.txt";

Expand All @@ -90,8 +92,8 @@ pub mod file {
/// Default file size
pub const DEFAULT_SIZE: i64 = 1024;

/// Default file step (0 = requested, 1 = fulfilled)
pub const DEFAULT_STEP: i32 = 1;
/// By default, all files are fulfilled
pub const DEFAULT_STEP: i32 = FileStorageRequestStep::Stored as i32;
}

/// Mock connection test data
Expand Down
1 change: 1 addition & 0 deletions backend/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod config;
pub mod constants;
pub mod data;
pub mod error;
pub mod log;
pub mod models;
pub mod services;

Expand Down
Loading
Loading