Skip to content

Commit

Permalink
The Assets update is now working properly on Linux
Browse files Browse the repository at this point in the history
Also added a new Workflow and disabled the Rust workflow.
Redesigned Dockerfile
  • Loading branch information
shiroyashik committed Sep 21, 2024
1 parent f0599ae commit 0103c31
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 81 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/dev-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Push Dev

on:
push:
branches: [ "dev" ]

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

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

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

- name: Get short SHA
id: short_sha
run: echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
# context: .
tags: ghcr.io/${{ github.repository_owner }}/sculptor:${{ steps.short_sha.outputs.sha }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sculptor:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sculptor:buildcache,mode=max
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ jobs:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Write release version to env
run: |
CURRENT_SEMVER=${GITHUB_REF_NAME}
echo "CURRENT_SEMVER=$CURRENT_SEMVER" >> $GITHUB_ENV
- uses: docker/setup-buildx-action@v3
id: buildx
with:
Expand All @@ -142,7 +138,7 @@ jobs:
run: |
docker build --platform linux/amd64 \
-t ghcr.io/${{ github.repository_owner }}/sculptor:latest \
-t ghcr.io/${{ github.repository_owner }}/sculptor:${{env.CURRENT_SEMVER}} \
-t ghcr.io/${{ github.repository_owner }}/sculptor:${{ github.ref_name }} \
--provenance=false --sbom=false \
--push \
-f Dockerfile .
12 changes: 7 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Rust

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
on: workflow_dispatch
# push:
# branches: [ "master" ]
# pull_request:
# branches: [ "master" ]

env:
CARGO_TERM_COLOR: always
Expand All @@ -16,7 +16,9 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
49 changes: 31 additions & 18 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ thiserror = "1.0.63"
chrono = { version = "0.4.38", features = ["now", "serde"] }
serde = { version = "1.0.201", features = ["derive"] }
serde_json = "1.0.117"
toml = "0.8.13"
toml = "0.8.19"

# Other
dashmap = { version = "6.0.1", features = ["serde"] }
Expand All @@ -35,11 +35,12 @@ ring = "0.17.8"
rand = "0.8.5"

# Web framework
axum = { version = "0.7.5", features = ["ws", "macros", "http2"] }
tower-http = { version = "0.5.2", features = ["trace"] }
axum = { version = "0.7.6", features = ["ws", "macros", "http2"] }
tower-http = { version = "0.6.0", features = ["trace"] }
tokio = { version = "1.37.0", features = ["full"] }
indexmap = { version = "2.5.0", features = ["serde"] }
zip = "2.2.0"
lazy_static = "1.5.0"

[dev-dependencies]
cross = "0.2.5"
Expand Down
37 changes: 26 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
FROM rust:1.80.1-alpine3.20 as builder

WORKDIR /build

## Chef
# FROM clux/muslrust:stable AS chef
FROM rust:1.81.0-alpine3.20 as chef

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
USER root
RUN apk add musl-dev libressl-dev
RUN cargo install cargo-chef
WORKDIR /build

## Planner
FROM chef AS planner
COPY Cargo.toml Cargo.lock ./
COPY src src
RUN cargo chef prepare --recipe-path recipe.json

## Builder
FROM chef AS builder
COPY --from=planner /build/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
# Build application
COPY Cargo.toml Cargo.lock ./
COPY src src
RUN cargo build --release --target x86_64-unknown-linux-musl --bin sculptor

RUN cargo build --release

FROM alpine:3.20.0

## Runtime
FROM alpine:3.20.0 AS runtime
WORKDIR /app
COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/sculptor /app/sculptor

COPY --from=builder /build/target/release/sculptor /app/sculptor
RUN apk add --no-cache tzdata
ENV TZ=Etc/UTC

VOLUME [ "/app/avatars" ]
VOLUME [ "/app/data" ]
VOLUME [ "/app/logs" ]
EXPOSE 6665/tcp

CMD ["./sculptor"]
CMD [ "./sculptor" ]
6 changes: 5 additions & 1 deletion docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ services:
restart: unless-stopped
volumes:
- ./Config.toml:/app/Config.toml:ro
- ./avatars:/app/avatars
- ./data:/app/data
- ./logs:/app/logs
# You can specify the path to the server folder
# for Sculptor to use the ban list from it
# - ./minecraft-server:/app/mc
environment:
- RUST_LOG=info
# Set your timezone. https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
- TZ=Europe/Moscow
# ports:
# - 6665
## Recommended for use with reverse proxy.
# networks:
# - traefik
Expand Down
8 changes: 4 additions & 4 deletions src/api/figura/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde_json::Value;
use tokio::{fs, io::AsyncReadExt as _};
use walkdir::WalkDir;

use crate::{api::errors::internal_and_log, ApiError, ApiResult, AppState, ASSETS_ENV};
use crate::{api::errors::internal_and_log, ApiError, ApiResult, AppState, ASSETS_VAR};

pub fn router() -> Router<AppState> {
Router::new()
Expand All @@ -17,7 +17,7 @@ pub fn router() -> Router<AppState> {
}

async fn versions() -> ApiResult<Json<Value>> {
let dir_path = PathBuf::from(&std::env::var(ASSETS_ENV).unwrap());
let dir_path = PathBuf::from(&*ASSETS_VAR);

let mut directories = Vec::new();

Expand All @@ -43,7 +43,7 @@ async fn hashes(Path(version): Path<String>) -> ApiResult<Json<IndexMap<String,
}

async fn download(Path((version, path)): Path<(String, String)>) -> ApiResult<Vec<u8>> {
let mut file = if let Ok(file) = fs::File::open(format!("{}/{version}/{path}", std::env::var(ASSETS_ENV).unwrap())).await {
let mut file = if let Ok(file) = fs::File::open(format!("{}/{version}/{path}", *ASSETS_VAR)).await {
file
} else {
return Err(ApiError::NotFound)
Expand All @@ -57,7 +57,7 @@ async fn download(Path((version, path)): Path<(String, String)>) -> ApiResult<Ve

async fn index_assets(version: &str) -> anyhow::Result<IndexMap<String, Value>> {
let mut map = IndexMap::new();
let version_path = PathBuf::from(std::env::var(ASSETS_ENV).unwrap()).join(version);
let version_path = PathBuf::from(&*ASSETS_VAR).join(version);

for entry in WalkDir::new(version_path.clone()).into_iter().filter_map(|e| e.ok()) {
let data = match fs::read(entry.path()).await {
Expand Down
Loading

0 comments on commit 0103c31

Please sign in to comment.