From 2c95fbd30da5c425ac6d7832df1222267a128e05 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 9 Mar 2025 12:58:03 -0600 Subject: [PATCH] check for docker on build, limit to 60 seconds --- build | 3 ++- package.Dockerfile | 1 + src/config.rs | 2 +- src/example/config.toml | 1 + src/main.rs | 13 +++++++++++-- src/refractr.rs | 1 + 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/build b/build index be3a238..7696eae 100755 --- a/build +++ b/build @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # Create all the different builds for refractr 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 git.brysonsteck.xyz/brysonsteck/refractr:latest docker tag refractr:$version git.brysonsteck.xyz/brysonsteck/refractr:$version +test "$1" = "push" && docker push -a git.brysonsteck.xyz/brysonsteck/refractr # rust build cargo build diff --git a/package.Dockerfile b/package.Dockerfile index 5bc1dc6..5e067f4 100644 --- a/package.Dockerfile +++ b/package.Dockerfile @@ -1,6 +1,7 @@ FROM rust:slim ARG UID="1000" ARG GID="1000" +ENV REFRACTR_DOCKER="true" WORKDIR /usr/src/refractr COPY . . diff --git a/src/config.rs b/src/config.rs index e06fbcd..6924822 100644 --- a/src/config.rs +++ b/src/config.rs @@ -148,7 +148,7 @@ pub fn read_config(paths: Vec, refractr: &Refractr) -> Result Config { if config.schedule.enabled { assert_ne!(config.schedule.interval, None); - assert!(config.schedule.interval.unwrap() >= 15); + assert!(config.schedule.interval.unwrap() >= 60); } assert_ne!("", match &config.work_dir { diff --git a/src/example/config.toml b/src/example/config.toml index 4c30042..461e2a6 100644 --- a/src/example/config.toml +++ b/src/example/config.toml @@ -37,4 +37,5 @@ # The "interval" field is the amount of seconds refractor will wait before # pulling updates from the original repository if the schedule feature is enabled. # 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 diff --git a/src/main.rs b/src/main.rs index 4562cbe..e040ac2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod refractr; use clap::Parser; use std::path::PathBuf; use std::process; +use std::env; use users; use crate::refractr::Refractr; @@ -35,13 +36,21 @@ fn get_config_default() -> &'static str { fn main() -> Result<(), String> { let args = Args::parse(); let refractr = Refractr { - verbose: args.verbose, + docker: match option_env!("REFRACTR_DOCKER") { + Some(v) => match v { + "true" => true, + _ => false, + }, + None => false + }, 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, 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")); if args.create { common::verbose(refractr.verbose, 3, format!("Printing sample config")); diff --git a/src/refractr.rs b/src/refractr.rs index f5fcba0..8feb22a 100644 --- a/src/refractr.rs +++ b/src/refractr.rs @@ -16,6 +16,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; pub struct Refractr { + pub docker: bool, pub verbose: u8, pub pid: u32, pub unix: bool