diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..449dd53 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +echo "Auto-formatting Rust files" +cargo fmt +echo "Running Rust linter" +cargo clippy -- -D warnings \ No newline at end of file diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..a1c6f8d --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,21 @@ +name: Docker Container Build + +on: + pull_request: + branches: [ "master" ] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build + uses: docker/build-push-action@v5 + with: + context: . + push: false + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..f807c2c --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,27 @@ +name: Backend Checks + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + job: + name: Job + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: clippy + + - name: check + run: | + cargo clippy -- -D warnings \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 0d18beb..53e07a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,16 +21,15 @@ dependencies = [ [[package]] name = "actix-files" -version = "0.6.2" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d832782fac6ca7369a70c9ee9a20554623c5e51c76e190ad151780ebea1cf689" +checksum = "bf0bdd6ff79de7c9a021f5d9ea79ce23e108d8bfc9b49b5b4a2cf6fad5a35212" dependencies = [ "actix-http", "actix-service", "actix-utils", "actix-web", - "askama_escape", - "bitflags 1.3.2", + "bitflags 2.4.0", "bytes", "derive_more", "futures-core", @@ -40,13 +39,14 @@ dependencies = [ "mime_guess", "percent-encoding", "pin-project-lite", + "v_htmlescape", ] [[package]] name = "actix-http" -version = "3.4.0" +version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92ef85799cba03f76e4f7c10f533e66d87c9a7e7055f3391f09000ad8351bc9" +checksum = "129d4c88e98860e1758c5de288d1632b07970a16d59bdf7b8d66053d582bb71f" dependencies = [ "actix-codec", "actix-rt", @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4a5b5e29603ca8c94a77c65cf874718ceb60292c5a5c3e5f4ace041af462b9" +checksum = "e43428f3bf11dee6d166b00ec2df4e3aa8cc1606aaa0b7433c146852e2f4e03b" dependencies = [ "actix-codec", "actix-http", @@ -255,12 +255,6 @@ dependencies = [ "alloc-no-stdlib", ] -[[package]] -name = "askama_escape" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" - [[package]] name = "autocfg" version = "1.1.0" @@ -582,7 +576,7 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "httpserve" -version = "0.1.2" +version = "0.1.3" dependencies = [ "actix-files", "actix-web", @@ -1156,6 +1150,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "v_htmlescape" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8257fbc510f0a46eb602c10215901938b5c2a7d5e70fc11483b1d3c9b5b18c" + [[package]] name = "version_check" version = "0.9.4" @@ -1236,20 +1236,19 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "zstd" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +checksum = "bffb3309596d527cfcba7dfc6ed6052f1d39dfbd7c867aa2e865e4a449c10110" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.6" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +checksum = "43747c7422e2924c11144d5229878b98180ef8b06cca4ab5af37afc8a8d8ea3e" dependencies = [ - "libc", "zstd-sys", ] diff --git a/Cargo.toml b/Cargo.toml index c539b6a..c937e6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "httpserve" -version = "0.1.2" +version = "0.1.3" edition = "2021" [dependencies] -actix-web = "4.4.0" +actix-web = "4.4.1" actix-files = "0.6.2" diff --git a/Dockerfile b/Dockerfile index 27bf323..bfbcb77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # 1. Build rust -FROM rust:1.72 as build +FROM rust:1.75 as build # Create a new empty shell project RUN USER=root cargo new --bin httpserve @@ -21,7 +21,7 @@ RUN rm -f ./target/release/deps/httpserve* RUN cargo install --path . # 2. Package in a small production image -FROM debian:bookworm-slim +FROM debian:stable-slim WORKDIR /web # copy the build artifact from the build stage diff --git a/README.md b/README.md new file mode 100644 index 0000000..19af039 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Simple docker image to serve static files over HTTP and optionally redirect to HTTPS + +## Usage +TODO + +## Contributing +To enable the pre-commit hook which can run the pipeline checks locally before making a PR, run ```git config core.hooksPath .githooks``` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a7198dc..9be64af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,12 @@ -use std::env; -use actix_web::{App, HttpServer, guard, web, HttpRequest, Responder}; use actix_web::web::Redirect; +use actix_web::{guard, web, App, HttpRequest, HttpServer, Responder}; +use std::env; #[actix_web::main] async fn main() -> std::io::Result<()> { - let server = HttpServer::new(move || { - App::new() - .configure(configure) - }); + let server = HttpServer::new(move || App::new().configure(configure)); - server - .bind("0.0.0.0:8080")? - .run() - .await + server.bind("0.0.0.0:8080")?.run().await } pub fn configure(cfg: &mut web::ServiceConfig) { @@ -20,9 +14,10 @@ pub fn configure(cfg: &mut web::ServiceConfig) { let serve_from = env::var("SERVE_FROM"); if let Ok(mount_path) = mount_path { if let Ok(serve_from) = serve_from { - cfg.service(actix_files::Files::new(&mount_path, &serve_from) - .guard(guard::Get()) - .show_files_listing() + cfg.service( + actix_files::Files::new(&mount_path, serve_from) + .guard(guard::Get()) + .show_files_listing(), ); } } @@ -41,4 +36,4 @@ async fn https_redirect_handler(request: HttpRequest) -> impl Responder { request.uri().path() ); Redirect::to(target_url).permanent() -} \ No newline at end of file +}