From e3aca4fe72e802158b54fd1ae2dce4ba06d10c30 Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Sat, 22 Jun 2024 16:49:50 +0200 Subject: [PATCH] Improve README and install some extra files via CMake --- .pre-commit-config.yaml | 2 +- .vscode/settings.json | 1 + CMakeLists.txt | 10 +++++++-- README.md | 48 +++++++++++++++++++++++++++++++++++------ serves3.toml.example | 18 ++++++++++++++++ serves3@.service | 19 ++++++++++++++++ 6 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 serves3@.service diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d6f217f..bd3fea8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,6 +56,6 @@ repos: - id: trufflehog name: TruffleHog description: Detect secrets in your data. - entry: bash -c 'podman run -v "$(pwd):/workdir" --rm docker.io/trufflesecurity/trufflehog:latest git file:///workdir' + entry: bash -c 'podman run -v "$(pwd):/workdir" --rm docker.io/trufflesecurity/trufflehog:latest git file:///workdir' --only-verified language: system stages: ["commit", "push"] diff --git a/.vscode/settings.json b/.vscode/settings.json index b4a7be1..c57aabc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,4 +2,5 @@ // SPDX-License-Identifier: CC0-1.0 { "liveServer.settings.port": 8001, + "cmake.configureOnOpen": true, } diff --git a/CMakeLists.txt b/CMakeLists.txt index 24e91e0..0b5fab1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,15 @@ cmake_minimum_required(VERSION 3.25) -project(serves3 VERSION 1.0.0 LANGUAGES NONE) +project(serves3 VERSION 1.1.0 LANGUAGES C) + +include(GNUInstallDirs) include(FetchContent) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.4.1 + GIT_TAG v0.5.0 ) FetchContent_MakeAvailable(Corrosion) @@ -20,3 +22,7 @@ corrosion_import_crate( message(STATUS "Imported crates: ${imported_crates}") install(IMPORTED_RUNTIME_ARTIFACTS serves3) +install(FILES serves3.toml.example + DESTINATION ${CMAKE_INSTALL_DOCDIR}) +install(FILES serves3@.service + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system) diff --git a/README.md b/README.md index 6f5823a..e1f14a7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ -[//]: # SPDX-FileCopyrightText: © Matteo Settenvini -[//]: # SPDX-License-Identifier: EUPL-1.2 + + # serves3 @@ -11,7 +14,37 @@ Also helpful to do a different TLS termination. ## Configuration -Copy `serves3.toml.example` to `serves3.toml` and adjust your settings. +Copy `serves3.toml.example` to `serves3.toml` from this project's sources and adjust your settings. If the project was built and installed via CMake, a copy of the example settings file is in `/usr/share/doc/serves3`. + +For instance: + +```toml +# apply this configuration to Rocket's "default" profile +[default.s3_bucket] + +# the bucket name +name = "" + # the API endpoint address +endpoint = "https://eu-central-1.linodeobjects.com" +# the bucket region +region = "eu-central-1" +# the access key ID +access_key_id = "" +# the access key secret +secret_access_key = "" +# whether to use path_style S3 URLs, see +# https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access +path_style = false + +# Here you can add any other rocket options, see +# https://rocket.rs/guide/v0.5/configuration/ + +[default] + +[debug] + +[release] +``` You can also use the same file to customize the server options. See the [Rocket documentation](https://rocket.rs/v0.5-rc/guide/configuration/#rockettoml) for a list of understood values. @@ -59,10 +92,10 @@ Then, e.g. for running on port 8000, you would put the corresponding configurati If you want more granular control on installation options, use CMake: ```bash -cmake -B build . +cmake -DCMAKE_INSTALL_PREFIX=/usr -B build . cmake --build build -cmake --install build -cd run-folder # folder with Settings.toml +sudo cmake --install build +cd run-folder # folder with serves3.toml serves3 ``` @@ -70,7 +103,7 @@ Else you can simply rely on `cargo`: ```bash cargo install --root /usr/local --path . # for instance -cd run-folder # folder with Settings.toml +cd run-folder # folder with serves3.toml serves3 ``` @@ -79,6 +112,7 @@ serves3 ## 1.1.0 Reworked configuration file logic * **Breaking change**: configuration file renamed to `serves3.toml`. Please note that the format changed slightly; have a look at the provided `serves3.toml.example` file for reference. +* Fixes #2: URLs to directories not ending with a slash are not redirected properly ## 1.0.0 diff --git a/serves3.toml.example b/serves3.toml.example index c47201f..3096d96 100644 --- a/serves3.toml.example +++ b/serves3.toml.example @@ -1,10 +1,28 @@ # SPDX-FileCopyrightText: Public domain. # SPDX-License-Identifier: CC0-1.0 +# apply this configuration to Rocket's "default" profile [default.s3_bucket] + +# the bucket name name = "" + # the API endpoint address endpoint = "https://eu-central-1.linodeobjects.com" +# the bucket region region = "eu-central-1" +# the access key ID access_key_id = "" +# the access key secret secret_access_key = "" +# whether to use path_style S3 URLs, see +# https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access path_style = false + +# Here you can add any other rocket options, see +# https://rocket.rs/guide/v0.5/configuration/ + +[default] + +[debug] + +[release] diff --git a/serves3@.service b/serves3@.service new file mode 100644 index 0000000..ed88912 --- /dev/null +++ b/serves3@.service @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: © Matteo Settenvini +# SPDX-License-Identifier: CC0-1.0 + +[Unit] +Description=ServeS3, a S3 proxy +StartLimitInterval=100 +StartLimitBurst=10 + +[Service] +Type=simple +ExecStart=/usr/local/bin/serves3 +WorkingDirectory=/etc/serves3/%i/ +Environment=ROCKET_PORT=%i + +Restart=always +RestartSec=5s + +[Install] +WantedBy=multi-user.target