docker deploy

This commit is contained in:
OMGeeky
2024-04-21 23:26:05 +02:00
parent 51bfc72f56
commit cbb13296e2
7 changed files with 113 additions and 8 deletions

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
target

53
.run/Dockerfile.run.xml Normal file
View File

@@ -0,0 +1,53 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="twba-twitch-fetcher"/>
<option name="buildArgs">
<list>
<DockerEnvVarImpl>
<option name="name" value="PROGNAME"/>
<option name="value" value="twba-twitch-fetcher"/>
</DockerEnvVarImpl>
</list>
</option>
<option name="buildKitEnabled" value="true"/>
<option name="containerName" value="twba-twitch-fetcher"/>
<option name="envVars">
<list>
<DockerEnvVarImpl>
<option name="name" value="TWBA_CONFIG"/>
<option name="value" value="/twba/configs/config.toml"/>
</DockerEnvVarImpl>
</list>
</option>
<option name="commandLineOptions" value="--restart=unless-stopped"/>
<option name="showCommandPreview" value="true"/>
<option name="sourceFilePath" value="Dockerfile"/>
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/twba/configs/"/>
<option name="hostPath" value="/twba/"/>
<option name="readOnly" value="true"/>
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/twba/tmp/"/>
<option name="hostPath" value="/var/tmp/twba/"/>
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/twba/data/"/>
<option name="hostPath" value="/twba/data/"/>
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/etc/ssl/certs"/>
<option name="hostPath" value="/etc/ssl/certs"/>
<option name="readOnly" value="true"/>
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2"/>
</configuration>
</component>

19
Cargo.lock generated
View File

@@ -2048,6 +2048,7 @@ dependencies = [
"http", "http",
"http-body", "http-body",
"hyper", "hyper",
"hyper-rustls 0.24.2",
"hyper-tls", "hyper-tls",
"ipnet", "ipnet",
"js-sys", "js-sys",
@@ -2057,6 +2058,7 @@ dependencies = [
"once_cell", "once_cell",
"percent-encoding 2.3.1", "percent-encoding 2.3.1",
"pin-project-lite", "pin-project-lite",
"rustls 0.21.11",
"rustls-pemfile 1.0.4", "rustls-pemfile 1.0.4",
"serde", "serde",
"serde_json", "serde_json",
@@ -2065,6 +2067,7 @@ dependencies = [
"system-configuration", "system-configuration",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls 0.24.1",
"tokio-util", "tokio-util",
"tower-service", "tower-service",
"url 2.5.0", "url 2.5.0",
@@ -2072,6 +2075,7 @@ dependencies = [
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasm-streams", "wasm-streams",
"web-sys", "web-sys",
"webpki-roots",
"winreg", "winreg",
] ]
@@ -2626,9 +2630,9 @@ dependencies = [
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.1" version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@@ -3068,18 +3072,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -3371,7 +3375,8 @@ dependencies = [
[[package]] [[package]]
name = "twba-twitch-data" name = "twba-twitch-data"
version = "0.3.0" version = "0.3.2"
source = "git+https://github.com/OMGeeky/twitch_data.git#64635bef670e4feb6ca423d0da286db52e687965"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-recursion", "async-recursion",

44
Dockerfile Normal file
View File

@@ -0,0 +1,44 @@
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
FROM chef AS planner
COPY /src ./src
COPY /Cargo.toml .
COPY /Cargo.lock .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/home/root/app/target \
cargo chef cook --release --locked --recipe-path recipe.json
# Build application
COPY /src ./src
COPY /Cargo.toml .
COPY /Cargo.lock .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/home/root/app/target \
cargo build --release --locked
# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm AS runtime
WORKDIR /app
ARG PROGNAME
RUN apt-get update && apt-get install -y libssl-dev coreutils
# Create a script to run the command and sleep for one hour after the command is done
RUN echo "#!/bin/bash \n \
echo \"Running command: '$PROGNAME'\" \n \
# Run your command \n \
$PROGNAME \n \
echo \"Done with normal command. Sleeping for one hour\" \n \
# Sleep for one hour \n \
sleep 3600 \n \
echo \"Done with sleep. Exiting\" \
" > /app/entrypoint.sh
# Make the script executable
RUN chmod +x /app/entrypoint.sh
COPY --from=builder /app/target/release/$PROGNAME /usr/local/bin/$PROGNAME
CMD ["/app/entrypoint.sh"]

View File

@@ -2,7 +2,7 @@ use crate::prelude::*;
use twba_backup_config::Conf; use twba_backup_config::Conf;
use twba_local_db::entities::users::Model; use twba_local_db::entities::users::Model;
use twba_local_db::entities::videos::ActiveModel; use twba_local_db::entities::videos::ActiveModel;
use twba_local_db::prelude::{Status, Users, UsersColumn, Videos, VideosColumn, VideosModel}; use twba_local_db::prelude::{Status, Users, UsersColumn, Videos, VideosColumn};
use twba_local_db::re_exports::sea_orm::{ use twba_local_db::re_exports::sea_orm::{
ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter,
}; };

View File

@@ -26,6 +26,7 @@ async fn run() -> Result<()> {
.env() .env()
.file("./settings.toml") .file("./settings.toml")
.file(shellexpand::tilde("~/twba/config.toml").into_owned()) .file(shellexpand::tilde("~/twba/config.toml").into_owned())
.file(std::env::var("TWBA_CONFIG").unwrap_or_else(|_| "~/twba/config.toml".to_string()))
.load() .load()
.map_err(|e| FetcherError::LoadConfig(e.into()))?; .map_err(|e| FetcherError::LoadConfig(e.into()))?;

View File

@@ -1,5 +1,6 @@
pub use crate::errors::FetcherError; pub use crate::errors::FetcherError;
pub(crate) use std::result::Result as StdResult; pub(crate) use std::result::Result as StdResult;
#[allow(unused_imports)]
pub(crate) use tracing::{debug, error, info, trace, warn}; pub(crate) use tracing::{debug, error, info, trace, warn};
pub type Result<T> = StdResult<T, FetcherError>; pub type Result<T> = StdResult<T, FetcherError>;