Added initial setup for docker building

This commit is contained in:
Martin Slot 2023-01-20 10:29:10 +01:00
parent 7286397078
commit 30e5c19732
10 changed files with 81 additions and 19 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
target/

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM rust:1.66.0 as build
WORKDIR /bin
COPY . .
RUN cargo build --release
# our final base
FROM debian:buster-slim
# copy the build artifact from the build stage
COPY --from=build /bin/target/release/host .
COPY --from=build /bin/host/Rocket.toml .
# set the startup command to run your binary
CMD ["./host"]

7
host/Rocket.toml Normal file
View File

@ -0,0 +1,7 @@
[debug]
address = "0.0.0.0"
port = 9998
[release]
address = "0.0.0.0"
port = 9999

View File

@ -0,0 +1,10 @@
[Unit]
Description=pixel webserver
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
Type=simple
Restart=always
RestartSec=5s
WorkingDirectory=%h/.local/bin/pixel
ExecStart=%h/.local/bin/pixel/host

24
host/server_install.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
while getopts s:u:l: flag
do
case "${flag}" in
s) server=${OPTARG};;
u) username=${OPTARG};;
l) local_user=${OPTARG};;
esac
done
#
# This could be done more gently by copying a script over and running it, but this is fine for now
#
ssh $username@$server 'systemctl stop --user pixel_webserver'
ssh $username@$server 'mkdir -p ~/.local/bin/pixel/static'
scp ../static/* $username@$server:~/.local/bin/pixel/static
scp ../target/debug/host $username@$server:~/.local/bin/pixel
scp Rocket.toml $username@$server:~/.local/bin/pixel
scp pixel_webserver.service $username@$server:~/.local/bin/pixel
ssh $username@$server sudo -S cp $local_user/.local/bin/pixel/pixel_webserver.service /etc/systemd/user
ssh $username@$server 'systemctl --user daemon-reload'
ssh $username@$server 'systemctl start --user pixel_webserver.service'

View File

@ -1,3 +1,4 @@
//noinspection RsMainFunctionNotFound
use rocket::launch;
use rocket::Rocket;

10
host/test_install.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
systemctl stop --user pixel_webserver
cargo build
mkdir -p ~/.local/bin/pixel/static
cp ../static/* ~/.local/bin/pixel/static
cp ../target/debug/host ~/.local/bin/pixel
sudo cp pixel_webserver.service /etc/systemd
systemctl --user daemon-reload
systemctl start --user pixel_webserver

View File

@ -1,4 +1,4 @@
GET http://127.0.0.1:8000/image
GET http://127.0.0.1:8000/image/a_png.png
Accept: application/json
X-Forwarded-For: 1,2,3
X-PROXYuser: 123

View File

@ -1,7 +1,7 @@
use std::net::SocketAddr;
use std::path::Path;
use std::path::{Path, PathBuf};
use rocket::fs::{NamedFile, relative};
use rocket::http::Status;
use rocket::http::{RawStr, Status};
use rocket::Request;
use rocket::request::{FromRequest, Outcome};
use rocket::response::{content, status};
@ -16,12 +16,10 @@ pub fn launch_server() -> Rocket<Build> {
rocket::build().mount("/", routes![files])
}
#[get("/image")]
async fn files(identificationGuard: IdentificationGuard) -> Result<NamedFile, NotFound<String>> {
println!("identification: {:?}", identificationGuard.identification);
let mut path = Path::new(relative!("../static")).join("a_png.png");
NamedFile::open(&path).await.map_err(|e| NotFound(e.to_string()))
#[get("/image/<file..>")]
async fn files(identification_guard: IdentificationGuard, file: PathBuf) -> Option<NamedFile> {
println!("identification: {:?}", identification_guard.identification);
NamedFile::open(Path::new("static/").join(file)).await.ok()
}
mod guards {
@ -45,16 +43,10 @@ mod guards {
let proxy_user = request.headers().get_one("x-proxyuser");
let ip_address = request.remote();
Outcome::Success(IdentificationGuard { identification: Identification::new(forwarded_for, user_agent, proxy_user, ip_address) })
let identity_guard = IdentificationGuard { identification: Identification::new(forwarded_for, user_agent, proxy_user, ip_address) };
println!("{:?}", identity_guard);
Outcome::Success(identity_guard)
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}

BIN
static/phone.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB