check for docker on build, limit to 60 seconds

This commit is contained in:
Bryson Steck 2025-03-09 12:58:03 -06:00
parent fc80ebc936
commit 2c95fbd30d
Signed by: brysonsteck
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
6 changed files with 17 additions and 4 deletions

3
build
View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/sh
# Create all the different builds for refractr # Create all the different builds for refractr
version=$(cat Cargo.toml | grep -m1 version | awk -F' ' '{print $3}' | sed 's|"||g') version=$(cat Cargo.toml | grep -m1 version | awk -F' ' '{print $3}' | sed 's|"||g')
@ -12,6 +12,7 @@ docker build -t refractr:$version --build-arg UID=$uid --build-arg GID=$gid -f p
docker tag refractr:$version refractr:latest docker tag refractr:$version refractr:latest
docker tag refractr:$version git.brysonsteck.xyz/brysonsteck/refractr:latest docker tag refractr:$version git.brysonsteck.xyz/brysonsteck/refractr:latest
docker tag refractr:$version git.brysonsteck.xyz/brysonsteck/refractr:$version docker tag refractr:$version git.brysonsteck.xyz/brysonsteck/refractr:$version
test "$1" = "push" && docker push -a git.brysonsteck.xyz/brysonsteck/refractr
# rust build # rust build
cargo build cargo build

View file

@ -1,6 +1,7 @@
FROM rust:slim FROM rust:slim
ARG UID="1000" ARG UID="1000"
ARG GID="1000" ARG GID="1000"
ENV REFRACTR_DOCKER="true"
WORKDIR /usr/src/refractr WORKDIR /usr/src/refractr
COPY . . COPY . .

View file

@ -148,7 +148,7 @@ pub fn read_config(paths: Vec<PathBuf>, refractr: &Refractr) -> Result<Vec<Confi
fn verify_config(config: Config) -> Config { fn verify_config(config: Config) -> Config {
if config.schedule.enabled { if config.schedule.enabled {
assert_ne!(config.schedule.interval, None); assert_ne!(config.schedule.interval, None);
assert!(config.schedule.interval.unwrap() >= 15); assert!(config.schedule.interval.unwrap() >= 60);
} }
assert_ne!("", match &config.work_dir { assert_ne!("", match &config.work_dir {

View file

@ -37,4 +37,5 @@
# The "interval" field is the amount of seconds refractor will wait before # The "interval" field is the amount of seconds refractor will wait before
# pulling updates from the original repository if the schedule feature is enabled. # pulling updates from the original repository if the schedule feature is enabled.
# This field is REQUIRED if "enabled" is set to true, otherwise OPTIONAL # This field is REQUIRED if "enabled" is set to true, otherwise OPTIONAL
# To avoid overwhelming servers, this is set to only accept values of >=60
#interval = 300 #interval = 300

View file

@ -5,6 +5,7 @@ mod refractr;
use clap::Parser; use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use std::process; use std::process;
use std::env;
use users; use users;
use crate::refractr::Refractr; use crate::refractr::Refractr;
@ -35,13 +36,21 @@ fn get_config_default() -> &'static str {
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
let args = Args::parse(); let args = Args::parse();
let refractr = Refractr { let refractr = Refractr {
verbose: args.verbose, docker: match option_env!("REFRACTR_DOCKER") {
Some(v) => match v {
"true" => true,
_ => false,
},
None => false
},
pid: process::id(), pid: process::id(),
unix: cfg!(unix) unix: cfg!(unix),
verbose: args.verbose
}; };
common::verbose(refractr.verbose, 1, format!("Level {} verbosity enabled", refractr.verbose.to_string())); common::verbose(refractr.verbose, 1, format!("Level {} verbosity enabled", refractr.verbose.to_string()));
common::verbose(refractr.verbose, 3, format!("Process ID: {}", refractr.pid)); common::verbose(refractr.verbose, 3, format!("Process ID: {}", refractr.pid));
common::verbose(refractr.verbose, 3, format!("Running in Docker: {}", refractr.docker));
common::verbose(refractr.verbose, 2, format!("Checking for create flag")); common::verbose(refractr.verbose, 2, format!("Checking for create flag"));
if args.create { if args.create {
common::verbose(refractr.verbose, 3, format!("Printing sample config")); common::verbose(refractr.verbose, 3, format!("Printing sample config"));

View file

@ -16,6 +16,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
pub struct Refractr { pub struct Refractr {
pub docker: bool,
pub verbose: u8, pub verbose: u8,
pub pid: u32, pub pid: u32,
pub unix: bool pub unix: bool