Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.1.3 - minor optimizations and dependency bumps, mainly rebuilding for newer base image #1

Merged
merged 8 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading