Skip to content

Commit

Permalink
Merge pull request #1 from The-Fireplace/release/0.1.3
Browse files Browse the repository at this point in the history
Release 0.1.3 - minor optimizations and dependency bumps, mainly rebuilding for newer base image
  • Loading branch information
The-Fireplace authored Jan 16, 2024
2 parents bed5e54 + 981e25b commit be3e623
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
echo "Auto-formatting Rust files"
cargo fmt
echo "Running Rust linter"
cargo clippy -- -D warnings
21 changes: 21 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 19 additions & 20 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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```
23 changes: 9 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
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) {
let mount_path = env::var("MOUNT_PATH");
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(),
);
}
}
Expand All @@ -41,4 +36,4 @@ async fn https_redirect_handler(request: HttpRequest) -> impl Responder {
request.uri().path()
);
Redirect::to(target_url).permanent()
}
}

0 comments on commit be3e623

Please sign in to comment.