get it to work on the server with docker

This commit is contained in:
OMGeeky
2023-10-29 19:36:30 +01:00
parent f92a6e3248
commit d26c4ebad4
8 changed files with 154 additions and 4 deletions

15
.cargo/config.toml Normal file
View File

@@ -0,0 +1,15 @@
[net]
git-fetch-with-cli = true
#[patch."https://github.com/OMGeeky/backup_config.git"]
#backup-config = { path = "../backup_config" }
#
#[patch."https://github.com/OMGeeky/twitch_backup.local_db.git"]
#local-db = { path = "../local_db" }
#
#[patch."https://github.com/OMGeeky/twba_reqwest_backoff.git"]
#reqwest-backoff = { path = "../reqwest_backoff" }
[patch.crates-io]
yup-oauth2 = { git = "https://github.com/dermesser/yup-oauth2.git" }
google-youtube3 = { git = "https://github.com/OMGeeky/google-apis-rs.git", branch = "scope-derives" }

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
/target

5
Cargo.lock generated
View File

@@ -1964,6 +1964,7 @@ dependencies = [
"http",
"http-body",
"hyper",
"hyper-rustls",
"hyper-tls",
"ipnet",
"js-sys",
@@ -1973,12 +1974,16 @@ dependencies = [
"once_cell",
"percent-encoding 2.3.0",
"pin-project-lite",
"rustls",
"rustls-native-certs",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"system-configuration",
"tokio",
"tokio-native-tls",
"tokio-rustls",
"tower-service",
"url 2.4.1",
"wasm-bindgen",

View File

@@ -21,7 +21,7 @@ thiserror = "1.0"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = "0.11"
reqwest = { version = "0.11" , features = ["rustls-tls-native-roots"], default-features = false}
chrono = "0.4"
futures = "0.3"
futures-util = "0.3"

73
Dockerfile Normal file
View File

@@ -0,0 +1,73 @@
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
################################################################################
# Create a stage for building the application.
ARG RUST_VERSION=1.73.0
ARG APP_NAME=uploader
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app
RUN apt-get update
RUN apt-get install -y pkg-config
RUN apt-get install -y libssl-dev
RUN apt-get install -y libudev-dev
RUN apt-get install -y git
# Build the application.
# Leverage a cache mount to /usr/local/cargo/registry/
# for downloaded dependencies and a cache mount to /app/target/ for
# compiled dependencies which will speed up subsequent builds.
# Leverage a bind mount to the src directory to avoid having to copy the
# source code into the container. Once built, copy the executable to an
# output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=bind,source=.cargo/config.toml,target=.cargo/config.toml \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
# --mount=type=bind,source=migrations,target=migrations \
<<EOF
set -e
cargo build --locked --release
cp ./target/release/$APP_NAME /bin/server
EOF
################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
#
# The example below uses the debian bullseye image as the foundation for running the app.
# By specifying the "bullseye-slim" tag, it will also use whatever happens to be the
# most recent version of that tag when you build your Dockerfile. If
# reproducability is important, consider using a digest
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
FROM debian:bullseye-slim AS final
RUN apt-get update
RUN apt-get install -y ca-certificates
# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ #user
#ARG UID=10001
#RUN adduser \
# --disabled-password \
# --gecos "" \
# --home "/nonexistent" \
# --shell "/sbin/nologin" \
# --no-create-home \
# --uid "${UID}" \
# appuser
#USER appuser
# Copy the executable from the "build" stage.
COPY --from=build /bin/server /bin/
# What the container should run when it is started.
CMD ["/bin/server"]

39
compose.yaml Normal file
View File

@@ -0,0 +1,39 @@
version: "3.8"
services:
uploader:
build:
context: .
volumes:
- data:/etc/twba/
- files:/var/tmp/twba/files
environment:
- TWBA_CONFIG=/etc/twba/config.toml
# web:
# im age: tw
debug:
image: debian:stable-slim
command:
- /bin/bash
stdin_open: true
tty: true
restart: "no"
volumes:
- data:/etc/twba/
- files:/var/tmp/twba/files
profiles:
- no-autostart
volumes:
data:
driver: local
driver_opts:
type: "none"
o: "bind"
device: "/etc/twba/"
files:
driver: local
driver_opts:
type: "none"
o: "bind"
device: "/var/tmp/twba/"

View File

@@ -27,7 +27,7 @@ impl<USER: EasyString> CustomFlowDelegate<USER> {
}
}
impl<USER: EasyString> InstalledFlowDelegate for CustomFlowDelegate<USER> {
#[tracing::instrument]
#[tracing::instrument(skip(self))]
fn redirect_uri(&self) -> Option<&str> {
if !(&crate::CONF.google.local_auth_redirect) {
let url = "https://game-omgeeky.de:7443/googleapi/auth";
@@ -48,7 +48,7 @@ impl<USER: EasyString> InstalledFlowDelegate for CustomFlowDelegate<USER> {
}
}
impl<USER: EasyString> CustomFlowDelegate<USER> {
#[tracing::instrument]
#[tracing::instrument(skip(self, url, need_code))]
async fn present_user_url(&self, url: &str, need_code: bool) -> StdResult<String, String> {
let user: String = self
.user
@@ -114,6 +114,10 @@ async fn get_auth_code() -> Result<String> {
break;
}
println!(
"sleeping for {} second before trying again",
crate::CONF.google.auth_file_read_timeout
);
tokio::time::sleep(tokio::time::Duration::from_secs(
crate::CONF.google.auth_file_read_timeout,
))

View File

@@ -11,6 +11,19 @@ pub mod prelude;
lazy_static! {
pub(crate) static ref CONF: Conf = Conf::builder()
.env()
.file(
std::env::var("TWBA_CONFIG")
.map(|v| {
dbg!(&v);
info!("using {} as primary config source after env", v);
v
})
.unwrap_or_else(|x| {
dbg!(x);
error!("could not get config location from env");
"./settings.toml".to_string()
})
)
.file("./settings.toml")
.file(shellexpand::tilde("~/twba/config.toml").into_owned())
.load()
@@ -39,7 +52,7 @@ async fn run() -> Result<()> {
let x = &CONF.google;
debug!("{:?}", x);
trace!("creating db-connection");
trace!("creating db-connection with db url: {}", &CONF.db_url);
let db = local_db::open_database(Some(&CONF.db_url)).await?;
trace!("migrating db");
local_db::migrate_db(&db).await?;