Compare commits

..

No commits in common. "adcbada69928052a6e9902179b8710a3bfc0bda4" and "e614b64bbab14a2638de020fb0ad113c1f33bcca" have entirely different histories.

12 changed files with 112 additions and 359 deletions

View File

@ -1,21 +1,25 @@
name: Build release binaries
name: Build release binaries (and publish them if this is a tag)
on:
push:
tags:
- "*"
# pull_request:
workflow_dispatch:
workflow_call:
env:
CARGO_TERM_COLOR: always
jobs:
build-binaries:
binaries:
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- i686-unknown-linux-musl
- armv7-unknown-linux-musleabihf
- aarch64-unknown-linux-musl
- x86_64-pc-windows-msvc
@ -25,23 +29,15 @@ jobs:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_path: target/x86_64-unknown-linux-musl/release/homedisk
artifact_name: target/x86_64-unknown-linux-musl/release/homedisk
release_name: x86_64-unknown-linux-musl
cross: true
strip: true
cargo_flags: ""
- os: ubuntu-latest
target: i686-unknown-linux-musl
artifact_path: target/i686-unknown-linux-musl/release/homedisk
release_name: i686-unknown-linux-musl
cross: true
strip: true
cargo_flags: ""
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
artifact_path: target/armv7-unknown-linux-musleabihf/release/homedisk
artifact_name: target/armv7-unknown-linux-musleabihf/release/homedisk
release_name: armv7-unknown-linux-musleabihf
cross: true
strip: false
@ -49,7 +45,7 @@ jobs:
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
artifact_path: target/aarch64-unknown-linux-musl/release/homedisk
artifact_name: target/aarch64-unknown-linux-musl/release/homedisk
release_name: aarch64-unknown-linux-musl
cross: true
strip: false
@ -57,7 +53,7 @@ jobs:
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_path: target/x86_64-pc-windows-msvc/release/homedisk.exe
artifact_name: target/x86_64-pc-windows-msvc/release/homedisk.exe
release_name: x86_64-pc-windows-msvc.exe
cross: false
strip: true
@ -65,7 +61,7 @@ jobs:
- os: macos-latest
target: x86_64-apple-darwin
artifact_path: target/x86_64-apple-darwin/release/homedisk
artifact_name: target/x86_64-apple-darwin/release/homedisk
release_name: x86_64-apple-darwin
cross: false
strip: true
@ -73,7 +69,7 @@ jobs:
- os: macos-latest
target: aarch64-apple-darwin
artifact_path: target/aarch64-apple-darwin/release/homedisk
artifact_name: target/aarch64-apple-darwin/release/homedisk
release_name: aarch64-apple-darwin
cross: false
strip: true
@ -106,17 +102,27 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target=${{ matrix.target }}
args: --release --target=${{ matrix.target }} ${{ matrix.cargo_flags }}
use-cross: ${{ matrix.cross }}
- name: Prepare artifact
shell: bash
run: |
mkdir release
mv ${{ matrix.artifact_path }} release/${{ matrix.release_name }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: release-${{ matrix.target }}
path: ./release/*
name: ${{ matrix.target }}
path: ${{ matrix.artifact_name }}
- name: Get tag name
id: tag_name
run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
shell: bash
if: startsWith(github.ref, 'refs/tags/v')
- name: Publish
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ matrix.artifact_name }}
tag: ${{ github.ref }}
asset_name: cloud-$tag-${{ matrix.release_name }}
if: startsWith(github.ref, 'refs/tags/v')

View File

@ -1,99 +0,0 @@
name: Build release binaries (and publish them if this is a tag)
on:
push:
# pull_request:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
build-release:
uses: ./.github/workflows/build-releases.yml
clippy-and-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable, nightly]
name: clippy and tests ${{ matrix.rust }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust toolchain
id: rust-toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: clippy
- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
~/.cargo/registry/cache/
target/
key: clippy-test-${{ runner.os }}-${{ matrix.rust }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --no-deps -- -D warnings
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
upload-release:
runs-on: ubuntu-latest
needs: [build-release]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./
- name: Move artifacts
run: |
mkdir release
mv release-*/* release/
- name: Get tag name
id: tag_name
run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
- name: Upload release files
uses: softprops/action-gh-release@17cd0d34deddf848fc0e7d9be5202c148c270a0a # 0.1.14
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
tag_name: ${{ github.ref }}
draft: true
fail_on_unmatched_files: true
name: ${{ github.ref }} Release
body: |
<!-- Write summary here -->
---
## Features
## Changes
## Bug Fixes
## Internal Changes
files: |
./release/*

View File

@ -1,53 +0,0 @@
name: Nightly
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
build-release:
uses: ./.github/workflows/build-releases.yml
upload-release:
runs-on: ubuntu-latest
needs: [build-release]
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./
- name: Move artifacts
run: |
mkdir release
mv release-*/* release/
echo "Generated $(ls ./release | wc -l) files:"
du -h -d 0 ./release/*
- name: Delete tag and release
uses: dev-drprasad/delete-tag-and-release@085c6969f18bad0de1b9f3fe6692a3cd01f64fe5 # 0.2.0
with:
delete_release: true
tag_name: nightly
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sleep for a few seconds to prevent timing issues between the deletion and creation of the release
run: sleep 10
- name: Upload all release files
uses: softprops/action-gh-release@17cd0d34deddf848fc0e7d9be5202c148c270a0a # 0.1.14
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: "nightly"
draft: false
fail_on_unmatched_files: true
files: |
./release/*

63
.github/workflows/rust.yml vendored Normal file
View File

@ -0,0 +1,63 @@
name: Rust
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable, nightly]
name: ${{ matrix.rust }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust toolchain
id: rust-toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: clippy
- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
~/.cargo/registry/cache/
target/
key: ${{ runner.os }}-${{ matrix.rust }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
- name: cargo build
uses: actions-rs/cargo@v1
with:
command: build
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --no-deps -- -D warnings
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features

111
Cargo.lock generated
View File

@ -107,17 +107,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -303,45 +292,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "clap"
version = "3.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"once_cell",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_derive"
version = "3.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
@ -767,7 +717,6 @@ dependencies = [
"axum-server",
"backtrace",
"byte-unit",
"clap",
"crypto-utils",
"futures-util",
"governor",
@ -1149,12 +1098,6 @@ version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "parking_lot"
version = "0.11.2"
@ -1268,30 +1211,6 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.43"
@ -1682,12 +1601,6 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
version = "2.4.1"
@ -1711,21 +1624,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8"
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thiserror"
version = "1.0.35"
@ -2216,15 +2114,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@ -1,6 +1,5 @@
[package]
name = "homedisk"
description = "Extremely fast and lightweight local cloud for your data written in Rust."
authors = ["MedzikUser <medzik@duck.com>"]
homepage = "https://github.com/HomeDisk/cloud"
repository = "https://github.com/HomeDisk/cloud"
@ -41,11 +40,8 @@ axum = { version = "0.6.0-rc.2", features = ["http2", "multipart"] }
axum-server = { version = "0.4", features = ["tls-rustls"] }
tower-http = { version = "0.3", features = ["full"] }
hyper = { version = "0.14", features = ["full"] }
byte-unit = "4.0"
byte-unit = "4.0.14"
# HTTP rate limiting
once_cell = "1.14"
governor = "0.5"
# CLI
clap = { version = "3.2", features = ["derive"] }
once_cell = "1.14.0"
governor = "0.5.0"

View File

@ -19,8 +19,6 @@ pub struct Database {
pub pool: SqlitePool,
}
pub const DATABASE_TABLES: &str = include_str!("../../sql/tables.sql");
impl Database {
/// Open a SQLite database
pub async fn open(path: &str) -> Result<Self> {
@ -46,7 +44,7 @@ impl Database {
/// Create all required tables for HomeDisk.
pub async fn create_tables(&self) -> Result<SqliteQueryResult> {
self.pool
.execute(DATABASE_TABLES)
.execute(include_str!("../../tables.sql"))
.await
.map_err(|e| Error::CreateTables(e.to_string()))
}

View File

@ -6,83 +6,42 @@
//!
//! Go to [config] module
use std::{
fs::{self, File},
io::Write,
path::Path,
};
use std::{fs::File, path::Path};
use clap::Parser;
use config::Config;
use tracing::{info, warn};
use crate::database::Database;
#[path = "./types/config.rs"]
mod config;
mod database;
mod logger;
mod server;
mod variables;
pub use variables::*;
#[derive(Debug, Parser)]
#[clap(
name = env!("CARGO_PKG_NAME"),
about = env!("CARGO_PKG_DESCRIPTION"),
version = env!("CARGO_PKG_VERSION"),
)]
struct Cli {
#[clap(short = 'c', long = "config", help = "Configuration file path", default_value = DEFAULT_CONFIG_FILE, display_order = 1)]
config: String,
#[clap(short = 'd', long = "database", help = "SQLite database path", default_value = DEFAULT_DATABASE_FILE, display_order = 2)]
database: String,
}
/// Default SQLite file path for the database.
pub const DATABASE_FILE: &str = "homedisk.db";
/// Default configuration file.
pub const CONFIG_FILE: &str = "config.toml";
#[tokio::main]
async fn main() {
logger::init();
let args = Cli::parse();
let config_path = args.config;
let database_path = args.database;
// if configuration file doesn't exist, create it
if !Path::new(&config_path).exists() {
warn!("Configuration file doesn't exists.");
let mut file =
File::create(config_path).expect("notrace - Failed to create configuration file");
file.write_all(DEFAULT_CONFIG_CONTENT)
.expect("notrace - Failed to write default configuration to config file");
info!("Created configuration file. Exiting...");
std::process::exit(0);
}
let config = Config::parse(&config_path).expect("notrace - Failed to parse configuration file");
// if storage directory doesn't exist, create it
if !Path::new(&config.storage.path).exists() {
fs::create_dir_all(&config.storage.path)
.expect("notrace - Failed to create storage directory");
}
let config = Config::parse(CONFIG_FILE).expect("notrace - Failed to parse configuration file");
// open database connection
let db =
// if database file doesn't exists create it
if !Path::new(&database_path).exists() {
if !Path::new(DATABASE_FILE).exists() {
warn!("Database file doesn't exists.");
info!("Creating database file...");
// create an empty database file
File::create(&database_path).expect("notrace - Failed to create a database file");
File::create(DATABASE_FILE).expect("notrace - Failed to create a database file");
// open database file
let db = Database::open(&database_path)
let db = Database::open(DATABASE_FILE)
.await
.expect("notrace - Failed to open database file");
@ -95,7 +54,7 @@ async fn main() {
}
// if database file exists
else {
Database::open(&database_path)
Database::open(DATABASE_FILE)
.await
.expect("notrace - Failed to open database file")
};

View File

@ -89,7 +89,7 @@ async fn redirect_http_to_https(config: Config) {
}
};
debug!("🚀 HTTPS redirect listening on http://{host}");
debug!("🚀 Http redirect listening on http://{host}");
axum::Server::bind(&host.parse().unwrap())
.serve(redirect.into_make_service())

View File

@ -1,6 +0,0 @@
/// Default SQLite file path for the database.
pub const DEFAULT_DATABASE_FILE: &str = "homedisk.db";
/// Default configuration file.
pub const DEFAULT_CONFIG_FILE: &str = "config.toml";
/// Default configuration file content.
pub static DEFAULT_CONFIG_CONTENT: &[u8] = include_bytes!("../config.toml");