Skip to content

Commit a2749c6

Browse files
committed
route: add version_alias_maps for aliased repo versions
* We tie r1beta5 -> current on the old repos via symlinks. * Symlinks aren't a thing in s3, so we add a new alias map of versions * Example: If I get a request for r1beta5, look it up in the alias map and see what it should tie to. current:r1beta5,r1beta4 means the request needs to go to current.
1 parent ae9e55d commit a2749c6

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
/target
33
**/*.rs.bk
4+
secrets-mount

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION ?= 0.4.3
1+
VERSION ?= 0.4.4
22
REGISTRY ?= ghcr.io/haiku
33
ENGINE ?= podman
44
default:
@@ -9,4 +9,5 @@ push:
99
enter:
1010
${ENGINE} run -it ${REGISTRY}/hpkgbouncer:$(VERSION) /bin/bash -l
1111
test:
12-
${ENGINE} run -e ROCKET_LOG_LEVEL=debug -e ROCKET_ADDRESS=0.0.0.0 -v /home/kallisti5/secrets-mount:/run/secrets -P ${REGISTRY}/hpkgbouncer:$(VERSION)
12+
${ENGINE} run -e ROCKET_LOG_LEVEL=debug -e ROCKET_ADDRESS=0.0.0.0 -e CACHE_TTL=900 -e S3_PUBLIC="https://haikuports-repository.cdn.haiku-os.org/" -e VERSION_ALIASES="current:r1beta5,r1beta4,r1beta3" -v ./secrets-mount:/run/secrets -P ${REGISTRY}/hpkgbouncer:$(VERSION)
13+
#${ENGINE} run -e ROCKET_LOG_LEVEL=debug -e ROCKET_ADDRESS=0.0.0.0 -e CACHE_TTL=900 -e S3_PUBLIC="https://haikuports-repository.cdn.haiku-os.org/" -v ./secrets-mount:/run/secrets -P ${REGISTRY}/hpkgbouncer:$(VERSION)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This microservice expects repos in the following format:
4040
* S3_REGION - Bucket region (default "us-east-1")
4141
* S3_PREFIX - Prefix within bucket to repos with no leading / (default "", ex: "myrepos/")
4242
* PUBLIC_URL - Public URL of object storage. (default: S3_ENDPOINT + S3_BUCKET)
43+
* VERSION_ALIASES - List of a target version followed by aliases. (ex: "current:ribeta5,r1beta4;whatever:thing")
4344

4445
# Future Feature Ideas
4546

src/routecache/mod.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ use s3::creds::Credentials;
2121

2222
use url::Url;
2323

24+
#[derive(Clone, Debug)]
25+
pub struct AliasMap {
26+
pub target: String,
27+
pub versions: Vec<String>,
28+
}
29+
2430
#[derive(Clone, Debug)]
2531
pub struct RouteConfig {
2632
pub s3_public: Option<String>,
@@ -31,6 +37,7 @@ pub struct RouteConfig {
3137
pub s3_key: Option<String>,
3238
pub s3_secret: Option<String>,
3339
pub s3_prefix: Option<String>,
40+
pub version_alias_maps: Vec<AliasMap>,
3441
}
3542

3643
#[derive(Clone, Debug, Eq)]
@@ -128,6 +135,7 @@ impl RouteConfig {
128135
s3_key: None,
129136
s3_secret: None,
130137
s3_prefix: None,
138+
version_alias_maps: Vec::new(),
131139
}
132140
}
133141

@@ -151,9 +159,39 @@ impl RouteConfig {
151159
// optional env vars
152160
self.s3_prefix = read_from_env("S3_PREFIX", false)?;
153161
self.s3_public = read_from_env("S3_PUBLIC", false)?;
162+
154163
let cache_ttl = read_from_env("CACHE_TTL", false)?;
155164
self.cache_ttl = cache_ttl.unwrap_or("900".to_string()).parse::<u64>()?;
156165

166+
// parse any version aliases
167+
let version_alias_raw = match read_from_env("VERSION_ALIASES", false)? {
168+
Some(raw) => raw,
169+
None => "".to_string(),
170+
};
171+
for field in version_alias_raw.split(';') {
172+
let alias = field.to_string();
173+
if alias.contains(":") {
174+
let mut alias_maj_fields = alias.split(':').into_iter();
175+
let target = match alias_maj_fields.next() {
176+
Some(t) => t.to_string(),
177+
None => "".to_string(),
178+
};
179+
let aliases_raw = match alias_maj_fields.next() {
180+
Some(r) => r.to_string(),
181+
None => "".to_string(),
182+
};
183+
let mut aliases: Vec<String> = Vec::new();
184+
for minor in aliases_raw.split(',') {
185+
aliases.push(minor.to_string())
186+
}
187+
let map = AliasMap {
188+
target: target.to_string(),
189+
versions: aliases,
190+
};
191+
self.version_alias_maps.push(map);
192+
}
193+
}
194+
157195
return Ok(());
158196
}
159197

@@ -314,9 +352,17 @@ impl RouteCache {
314352
return self.version_latest(branch, arch);
315353
}
316354

355+
let mut actual_version = version.clone();
356+
// First, we check for known aliases...
357+
for alias in self.config.version_alias_maps.iter() {
358+
if alias.versions.contains(&version) {
359+
actual_version = alias.target.clone();
360+
}
361+
}
362+
317363
// Otherwise just return requested version.
318364
for route in self.routes.iter() {
319-
if route.branch == branch && route.arch == arch && route.version == version {
365+
if route.branch == branch && route.arch == arch && route.version == actual_version {
320366
return Some(route.clone());
321367
}
322368
}

0 commit comments

Comments
 (0)