Skip to content

Commit

Permalink
Release v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyashik committed Jun 12, 2024
1 parent 5eedf26 commit 082b90d
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 99 deletions.
1 change: 1 addition & 0 deletions .github/release-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Full Changelog**: https://github.com/shiroyashik/sculptor/compare/v0.2.0...v0.2.1
63 changes: 0 additions & 63 deletions .github/workflows/docker.yml

This file was deleted.

148 changes: 148 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Stolen from https://github.com/mrjackwills/oxker :D
name: Release CI
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
#################################################
## Cross platform binary build for release page #
#################################################

cross_platform_build:
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
output_name: linux_x86_64.tar.gz

- target: x86_64-pc-windows-gnu
output_name: windows_x86_64.zip

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

# Install stable rust, and associated tools
- name: Install rust
uses: dtolnay/rust-toolchain@stable

# Install cross-rs
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

# Build binary
- name: Build
run: CROSS_NO_WARNINGS=0 cross build --target ${{ matrix.target }} --release

# Create necessary files and directories
- name: Create necessary files and directories
run: |
mkdir -p target/output/avatars
cp Config.example.toml target/output/Config.toml
# Compress the output
- name: Compress | windows
if: matrix.target == 'x86_64-pc-windows-gnu'
run: |
cp target/${{ matrix.target }}/release/sculptor.exe target/output
zip -jv "./sculptor_${{ matrix.output_name }}" target/output/*
# Compress the output
- name: Compress | linux
if: matrix.target != 'x86_64-pc-windows-gnu'
run: |
cp target/${{ matrix.target }}/release/sculptor target/output
tar -czvf "./sculptor_${{ matrix.output_name }}" -C "target/output" .
# Upload output for release page
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{ matrix.target }}
path: sculptor_${{ matrix.output_name }}
retention-days: 1

###################
## Create release #
###################

create_release:
needs: [cross_platform_build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup | Artifacts
uses: actions/download-artifact@v4

- name: Update Release
uses: ncipollo/release-action@v1
with:
makeLatest: true
name: ${{ github.ref_name }}
tag: ${{ github.ref }}
bodyFile: ".github/release-body.md"
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: |
**/sculptor_*.zip
**/sculptor_*.tar.gz
##################
## Cargo publish #
##################

# cargo_publish:
# needs: [create_release]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - name: publish to crates.io
# uses: katyo/publish-crates@v2
# with:
# registry-token: ${{ secrets.CRATES_IO_TOKEN }}

#########################################
## Build images for Dockerhub & ghcr.io #
#########################################

image_build:
needs: [create_release]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Write release version to env
run: |
CURRENT_SEMVER=${GITHUB_REF_NAME#v}
echo "CURRENT_SEMVER=$CURRENT_SEMVER" >> $GITHUB_ENV
- uses: docker/setup-buildx-action@v3
id: buildx
with:
install: true
- name: Build for Dockerhub & ghcr.io
run: |
docker build --platform linux/amd64 \
-t ghcr.io/${{ github.repository_owner }}/sculptor:latest \
-t ghcr.io/${{ github.repository_owner }}/sculptor:${{env.CURRENT_SEMVER}} \
--provenance=false --sbom=false \
--push \
-f Dockerfile .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
output.log
docker-compose.yml
Config.toml
.env
9 changes: 8 additions & 1 deletion Cargo.lock

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

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sculptor"
authors = ["Shiroyashik <shiroyashik@shsr.ru>"]
version = "0.2.0"
version = "0.2.1"
edition = "2021"
publish = false

Expand All @@ -26,6 +26,7 @@ hex = "0.4.3"
uuid = { version = "1.8.0", features = ["serde"] }
base64 = "0.22.1"
reqwest = { version = "0.12.4" }
dotenvy = "0.15.7"

# Crypto
ring = "0.17.8"
Expand All @@ -36,7 +37,11 @@ axum = { version = "0.7.5", features = ["ws", "macros", "http2"] }
tower-http = { version = "0.5.2", features = ["trace"] }
tokio = { version = "1.37.0", features = ["full"] }

[dev-dependencies]
cross = "0.2.5"

# TODO: Sort it!
# TODO: Replace Vec<u8> and &[u8] by Bytes
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace.metadata.cross.target.x86_64-unknown-linux-gnu]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH"
]
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn id(
State(state): State<AppState>,
) -> String {
let server_id =
bytes_into_string(&digest(&digest::SHA1_FOR_LEGACY_USE_ONLY, &rand()).as_ref()[0..20]);
hex::encode(&digest(&digest::SHA1_FOR_LEGACY_USE_ONLY, &rand()).as_ref()[0..20]);
let state = state.pending;
state.insert(server_id.clone(), query.username);
server_id
Expand Down
17 changes: 5 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use anyhow::{anyhow, Result};
use anyhow::Result;
use axum::{
extract::DefaultBodyLimit, middleware::from_extractor, routing::{delete, get, post, put}, Router
};
use dashmap::DashMap;
use std::sync::Arc;
use tokio::sync::{broadcast, Mutex};
use tower_http::trace::TraceLayer;
use tracing::{error, info};
use tracing::info;
use uuid::Uuid;

// WebSocket worker
Expand Down Expand Up @@ -97,6 +97,7 @@ const SCULPTOR_VERSION: &'static str = env!("CARGO_PKG_VERSION");

#[tokio::main]
async fn main() -> Result<()> {
dotenvy::dotenv()?;
// "trace,axum=info,tower_http=info,tokio=info,tungstenite=info,tokio_tungstenite=info",
let logger_env = std::env::var(LOGGER_ENV).unwrap_or_else(|_| "info".into());

Expand Down Expand Up @@ -138,23 +139,15 @@ async fn main() -> Result<()> {
}
});

let max_body_size = {
let mbs = state.config.clone().lock().await.limitations.max_avatar_size as usize;
if mbs >= 1024 {
mbs
} else {
return Err(anyhow!("maxAvatarSize {mbs} smaller than 1024!"));
}
};
let api = Router::new()
.nest("//auth", api_auth::router())
.route("/limits", get(api_info::limits))
.route("/version", get(api_info::version))
.route("/motd", get(api_info::motd))
.route("/equip", post(api_profile::equip_avatar))
.route("/:uuid", get(api_profile::user_info))
.route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::max(max_body_size)))
.route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::max(max_body_size)))
.route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::disable()))
.route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::disable()))
.route("/avatar", delete(api_profile::delete_avatar));

let app = Router::new()
Expand Down
4 changes: 0 additions & 4 deletions src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow_http::{http_error_ret, response::Result};
use axum::{
body::Bytes,
debug_handler,
extract::{Path, State},
Json,
};
Expand All @@ -20,7 +19,6 @@ use crate::{
AppState,
};

#[debug_handler]
pub async fn user_info(
Path(uuid): Path<Uuid>,
State(state): State<AppState>,
Expand Down Expand Up @@ -85,7 +83,6 @@ pub async fn user_info(
Json(user_info_response)
}

#[debug_handler]
pub async fn download_avatar(Path(uuid): Path<Uuid>) -> Result<Vec<u8>> {
let uuid = format_uuid(&uuid);
tracing::info!("Requesting an avatar: {}", uuid);
Expand All @@ -104,7 +101,6 @@ pub async fn download_avatar(Path(uuid): Path<Uuid>) -> Result<Vec<u8>> {
Ok(buffer)
}

#[debug_handler]
pub async fn upload_avatar(
Token(token): Token,
State(state): State<AppState>,
Expand Down
Loading

0 comments on commit 082b90d

Please sign in to comment.