docker support

This commit is contained in:
subcrip 2024-04-02 11:15:12 +08:00
parent dfd7c6c9fd
commit 7ecba7528f
Signed by: subcrip
SSH Key Fingerprint: SHA256:dFPFi68d8C87YkFkEBU4TkcrYRySWpekRR1hbnDWUCw
5 changed files with 44 additions and 22 deletions

32
Cargo.lock generated
View File

@ -1279,6 +1279,22 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "myoauth"
version = "0.1.0"
dependencies = [
"async-std",
"crypto-hash",
"futures",
"rand 0.8.5",
"serde",
"serde_json",
"tide",
"tokio",
"tokio-postgres",
"uuid",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.18" version = "0.2.18"
@ -1298,22 +1314,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "oauth"
version = "0.1.0"
dependencies = [
"async-std",
"crypto-hash",
"futures",
"rand 0.8.5",
"serde",
"serde_json",
"tide",
"tokio",
"tokio-postgres",
"uuid",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.32.2" version = "0.32.2"

View File

@ -1,5 +1,5 @@
[package] [package]
name = "oauth" name = "myoauth"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
@ -13,6 +13,6 @@ serde_json = "1.0"
tokio = { version = "1.37.0", features = ["full"] } tokio = { version = "1.37.0", features = ["full"] }
tokio-postgres = { version = "0.7.10", features = ["with-uuid-1"] } tokio-postgres = { version = "0.7.10", features = ["with-uuid-1"] }
futures = "0.3.30" futures = "0.3.30"
uuid = { verion = "1.0.0", features = ["v4", "fast-rng", "macro-diagnostics"] } uuid = { version = "1.0.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
rand = "0.8.5" rand = "0.8.5"
crypto-hash = "0.3.4" crypto-hash = "0.3.4"

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM rust:1.74.1 as builder
WORKDIR /app
ADD . /app
RUN cargo build --release
FROM debian:12.5
RUN mkdir /myoauth
COPY --from=builder /app/target/release/myoauth /myoauth
CMD ["/myoauth/myoauth"]

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
pack:
sudo docker build -t myoauth . --no-cache
publish:
sudo docker tag myoauth arielherself/myoauth && sudo docker push arielherself/myoauth

View File

@ -6,10 +6,18 @@ mod misc;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let mut b = db::OAuthDatabase::connect("localhost", 5432, "postgres", "configjson", "myoauth").await.unwrap(); let postgres_host = std::env::var("POSTGRES_HOST").unwrap_or(String::from("localhost"));
// b.init().await.unwrap(); let postgres_port = std::env::var("POSTGRES_PORT").unwrap_or(String::from("5432"));
let u = b.trusted_register_user().await.unwrap(); let postgres_user = std::env::var("POSTGRES_USER").unwrap_or(String::from("postgres"));
println!("Successfully registered user with uid = {}", u.user_id); let postgres_password = std::env::var("POSTGRES_PASSWORD").unwrap();
loop {
if let Ok(mut b) = db::OAuthDatabase::connect(postgres_host.as_str(), str::parse(postgres_port.as_str()).unwrap(), postgres_user.as_str(), postgres_password.as_str(), "myoauth").await {
b.init().await.unwrap();
break;
}
}
// let u = b.trusted_register_user().await.unwrap();
// println!("Successfully registered user with uid = {}", u.user_id);
} }
#[tokio::test] #[tokio::test]