Skip to content

Commit 4eee208

Browse files
author
SamTV1998
committed
Added build step
1 parent 1f5a10b commit 4eee208

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on:
2+
jobs:
3+
build:
4+
runs-on: ubuntu-latest
5+
steps:
6+
- name: 'Build app with cargo'
7+
run: RUSTFLAGS="-Ctarget-feature=+crt-static" cargo build --release
8+
- uses: actions/upload-artifact@v4
9+
with:
10+
name: 'etherpad-proxy'
11+
path: './target/release/etherpad-proxy'

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ rand = "0.8.5"
1919
hyper-util = "0.1.10"
2020
tower = "0.5.2"
2121
hyper = "1.6.0"
22-
tokio-tungstenite = "0.26.2"
22+
tokio-tungstenite = "0.26.2"
23+
regex = "1.11.1"

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM alpine AS cache
2+
RUN apk add -U --no-cache ca-certificates
3+
4+
5+
FROM lukemathwalker/cargo-chef:latest as chef
6+
WORKDIR /app
7+
8+
FROM chef AS planner
9+
COPY ./Cargo.toml ./Cargo.lock ./
10+
COPY ./src ./src
11+
RUN cargo chef prepare
12+
13+
FROM chef AS builder
14+
COPY --from=planner /app/recipe.json .
15+
RUN cargo chef cook --release
16+
COPY . .
17+
RUN RUSTFLAGS="-Ctarget-feature=+crt-static" cargo build --release
18+
RUN mv ./target/release/etherpad-proxy ./app
19+
20+
FROM scratch AS runtime
21+
WORKDIR /app
22+
COPY --from=builder /app/app /usr/local/bin/
23+
COPY --from=cache /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
24+
ENTRYPOINT ["/usr/local/bin/app"]

src/db.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ pub struct DB {
44
conn: Connection
55
}
66

7-
8-
9-
107
impl DB {
118
pub fn new(filename: &str) -> DB {
129
let conn = Connection::open(filename).expect("Unable to open database");

src/reverse_proxy.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use crate::db::DB;
23
use crate::runtime::AvailableBackends;
34
use crate::settings::{BackendIdentifier, Setting};
@@ -12,6 +13,7 @@ use axum::extract::{Request, State};
1213
use axum::http::{StatusCode, Uri};
1314
use axum::response::{IntoResponse, Response};
1415
use crate::Client;
16+
use regex::Regex;
1517

1618
fn debug_request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
1719
let body_str = format!("{:?}", req);
@@ -97,6 +99,11 @@ pub struct StateOfReverseProxy {
9799
pub setting: Setting,
98100
}
99101

102+
static RESOURCES: LazyLock<HashMap<String, String>> = LazyLock::new(HashMap::new);
103+
104+
static PADINDEX_REGEX: LazyLock<Regex> = LazyLock::new(||Regex::new("^/padbootstrap-[a-zA-Z0-9]+.min.js$").unwrap());
105+
106+
100107
pub async fn handler(State(client): State<StateOfReverseProxy>, mut req: Request) ->
101108
Result<Response,
102109
StatusCode> {
@@ -106,6 +113,8 @@ pub async fn handler(State(client): State<StateOfReverseProxy>, mut req: Request
106113
.path_and_query()
107114
.map(|v| v.as_str())
108115
.unwrap_or(path.path());
116+
117+
109118
let pad_id = get_pad_id(path);
110119
let chosen_backend = create_route(pad_id, client.available_backends.clone(), client.db);
111120
if let Some(backend_id) = chosen_backend {
@@ -117,12 +126,14 @@ pub async fn handler(State(client): State<StateOfReverseProxy>, mut req: Request
117126
}
118127

119128

120-
Ok(client
129+
let response = client
121130
.client
122131
.request(req)
123132
.await
124133
.map_err(|_| StatusCode::BAD_REQUEST)?
125-
.into_response())
134+
.into_response();
135+
136+
Ok(response)
126137
}
127138

128139
pub fn get_pad_id(uri: &Uri) -> Option<String> {
@@ -148,3 +159,14 @@ pub fn get_pad_id(uri: &Uri) -> Option<String> {
148159
}
149160
pad_id
150161
}
162+
163+
164+
mod tests {
165+
use crate::reverse_proxy::PADINDEX_REGEX;
166+
167+
#[test]
168+
fn test_pad_index_regex() {
169+
let path = "/padbootstrap-KK7I7qP9I3E.min.js";
170+
assert!(PADINDEX_REGEX.is_match(path));
171+
}
172+
}

0 commit comments

Comments
 (0)