Skip to content

Commit 104745a

Browse files
committed
4.0.2: add defaults for UME_STORAGE_S3_ENABLE_SIGNER_V4_REQUESTS and UME_STORAGE_S3_ENFORCE_PATH_ACCESS_STYLE env vars
1 parent 45e9b7e commit 104745a

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[package]
1717
name = "ume"
1818
description = "🐻‍❄️💐 Easy, self-hostable, and flexible image host made in Rust"
19-
version = "4.0.1"
19+
version = "4.0.2"
2020
authors = ["Noel Towa <[email protected]>"]
2121
edition = "2021"
2222
rust-version = "1.74.0"

distribution/docker/alpine.Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,25 @@ FROM --platform=${TARGETPLATFORM} rust:1.76-alpine3.19 AS build
2020
RUN apk update && apk add --no-cache git ca-certificates curl musl-dev libc6-compat gcompat pkgconfig openssl-dev build-base
2121
WORKDIR /build
2222

23-
COPY . .
23+
ENV RUSTFLAGS="-Ctarget-cpu=native -Ctarget-feature=-crt-static"
2424

2525
# Remove the `rust-toolchain.toml` file since we expect to use `rustc` from the Docker image
2626
# rather from rustup.
2727
RUN rm rust-toolchain.toml
2828

29-
ENV RUSTFLAGS="-Ctarget-cpu=native -Ctarget-feature=-crt-static"
29+
# First, we create an empty Rust project so that dependencies can be cached.
30+
COPY Cargo.toml .
31+
COPY Cargo.lock .
32+
33+
RUN mkdir -p src/ && echo "fn main() {}" > src/dummy.rs && sed -i 's#src/bin/main.rs#src/dummy.rs#' Cargo.toml
34+
RUN --mount=type=cache,target=/build/target/ \
35+
cargo build --release
36+
37+
# Now, we can remove `src/` and copy the whole project
38+
RUN rm src/dummy.rs && sed -i 's#src/dummy.rs#src/bin/main.rs#' Cargo.toml
39+
COPY . .
40+
41+
# Now build the CLI
3042
RUN cargo build --release --bin ume
3143

3244
############ FINAL STAGE

distribution/docker/debian.Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@ FROM --platform=${TARGETPLATFORM} rust:1.76-slim-bullseye AS build
1919

2020
ENV DEBIAN_FRONTEND=noninteractive
2121

22-
RUN apt update && apt install -y libssl-dev pkg-config git ca-certificates protobuf-compiler
22+
RUN apt update && apt install -y libssl-dev pkg-config git ca-certificates
2323
WORKDIR /build
2424

2525
COPY . .
2626

27-
ENV CARGO_INCREMENTAL=1
2827
ENV RUSTFLAGS="-Ctarget-cpu=native"
2928

3029
# Remove the `rust-toolchain.toml` file since we expect to use `rustc` from the Docker image
3130
# rather from rustup.
3231
RUN rm rust-toolchain.toml
32+
33+
# First, we create an empty Rust project so that dependencies can be cached.
34+
COPY Cargo.toml .
35+
36+
RUN mkdir -p src/ && echo "fn main() {}" > src/dummy.rs && sed -i 's#src/bin/main.rs#src/dummy.rs#' Cargo.toml
37+
RUN --mount=type=cache,target=/build/target/ \
38+
cargo build --release
39+
40+
# Now, we can remove `src/` and copy the whole project
41+
RUN rm src/dummy.rs && sed -i 's#src/dummy.rs#src/bin/main.rs#' Cargo.toml
42+
COPY . .
43+
44+
# Now build the CLI
3345
RUN cargo build --release --bin ume
3446

3547
############ FINAL STAGE

src/config/storage.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use noelware_config::{
2626
};
2727
use remi_azure::Credential;
2828
use serde::{Deserialize, Serialize};
29-
use std::{borrow::Cow, path::PathBuf, str::FromStr};
29+
use std::{borrow::Cow, env::VarError, path::PathBuf, str::FromStr};
3030

3131
/// Represents the configuration for configuring
3232
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -65,8 +65,8 @@ impl TryFromEnv for Config {
6565
})),
6666

6767
"s3" => Ok(Config::S3(remi_s3::S3StorageConfig {
68-
enable_signer_v4_requests: env!("UME_STORAGE_S3_ENABLE_SIGNER_V4_REQUESTS", to: bool),
69-
enforce_path_access_style: env!("UME_STORAGE_S3_ENFORCE_PATH_ACCESS_STYLE", to: bool),
68+
enable_signer_v4_requests: env!("UME_STORAGE_S3_ENABLE_SIGNER_V4_REQUESTS", to: bool, or_else: false),
69+
enforce_path_access_style: env!("UME_STORAGE_S3_ENFORCE_PATH_ACCESS_STYLE", to: bool, or_else: false),
7070
default_object_acl: env!("UME_STORAGE_S3_DEFAULT_OBJECT_ACL", {
7171
or_else: Some(ObjectCannedAcl::BucketOwnerFullControl);
7272
mapper: |val| ObjectCannedAcl::from_str(val.as_str()).ok();
@@ -77,17 +77,21 @@ impl TryFromEnv for Config {
7777
mapper: |val| BucketCannedAcl::from_str(val.as_str()).ok();
7878
}),
7979

80-
secret_access_key: env!("UME_STORAGE_S3_SECRET_ACCESS_KEY")
81-
.expect("required env variable [UME_STORAGE_S3_SECRET_ACCESS_KEY]"),
80+
secret_access_key: env!("UME_STORAGE_S3_SECRET_ACCESS_KEY").map_err(|e| match e {
81+
VarError::NotPresent => eyre!("you're required to add the [UME_STORAGE_S3_SECRET_ACCESS_KEY] environment variable"),
82+
VarError::NotUnicode(_) => eyre!("wanted valid UTF-8 for env `UME_STORAGE_S3_SECRET_ACCESS_KEY`")
83+
})?,
8284

83-
access_key_id: env!("UME_STORAGE_S3_ACCESS_KEY_ID")
84-
.expect("required env variable [UME_STORAGE_S3_ACCESS_KEY_ID]"),
85+
access_key_id: env!("UME_STORAGE_S3_ACCESS_KEY_ID").map_err(|e| match e {
86+
VarError::NotPresent => eyre!("you're required to add the [UME_STORAGE_S3_ACCESS_KEY_ID] environment variable"),
87+
VarError::NotUnicode(_) => eyre!("wanted valid UTF-8 for env `UME_STORAGE_S3_ACCESS_KEY_ID`")
88+
})?,
8589

8690
app_name: env!("UME_STORAGE_S3_APP_NAME", is_optional: true),
8791
endpoint: env!("UME_STORAGE_S3_ENDPOINT", is_optional: true),
8892
prefix: env!("UME_STORAGE_S3_PREFIX", is_optional: true),
8993
region: env!("UME_STORAGE_S3_REGION", {
90-
or_else: Some(Region::new(Cow::Owned("us-east-1".to_owned())));
94+
or_else: Some(Region::new(Cow::Borrowed("us-east-1")));
9195
mapper: |val| Some(Region::new(Cow::Owned(val)));
9296
}),
9397

@@ -330,7 +334,20 @@ fn to_env_location() -> eyre::Result<azure_storage::CloudLocation> {
330334
address: env!("UME_STORAGE_AZURE_EMULATOR_ADDRESS")
331335
.context("missing required env [UME_STORAGE_AZURE_EMULATOR_ADDRESS]")?,
332336

333-
port: env!("UME_STORAGE_AZURE_EMULATOR_PORT", to: u16),
337+
port: match env!("UME_STORAGE_AZURE_EMULATOR_PORT") {
338+
Ok(res) => res.parse::<u16>()?,
339+
Err(VarError::NotPresent) => {
340+
return Err(eyre!(
341+
"missing `UME_STORAGE_AZURE_EMULATOR_PORT` environment variable"
342+
))
343+
}
344+
345+
Err(VarError::NotUnicode(_)) => {
346+
return Err(eyre!(
347+
"`UME_STORAGE_AZURE_EMULATOR_PORT` env was not in valid UTF-8"
348+
))
349+
}
350+
},
334351
}),
335352

336353
"custom" => Ok(azure_storage::CloudLocation::Custom {

0 commit comments

Comments
 (0)