First commit

Application works, but repository was never really tested standalone
from scratch.
This commit is contained in:
GOLEM 2018-11-30 15:24:09 +01:00
commit d01c1d14c9
8 changed files with 135 additions and 0 deletions

32
README Normal file
View File

@ -0,0 +1,32 @@
dailybuilder for GOLEM
==========================
Daily builds given repositories.
Usage
-----
Just copy (or soft link) an example config file in repos-enabled directory, and edit as you like.
Use comments to understand meaning of various options.
How it works
------------
cron must call the dailybuilder.sh bash script at least once per day
dailybuilder.sh retrieves its settings in config.sh script.
Then it searchs for repositories config files in repos-enabled directory, and runs lib/build.sh for each of them.
build.sh exctracts the current repository settings from its config file, then looks for the $REPONAME file inside $LAST_PULL_DIR: if does not exist, then this is the first time that build is required for this repository, so it clones it and also prepares an output directory in the $OUTPUT_DIR directory. Else, if file exists, it means that the repository has already been pulled in the past, and file contains the Unix timestamp representing this event. So build.sh simply does a math calc to determine wether its "build time" is expired (eg, build.sh is run after 60 minutes from last pull of a daily repository, so nothing has to be done; eg, build.sh is run after 25hours from last pull of a daily repository, so the repository is flagged to be built).
If repository is flagged to be built, then build.sh changes its current path directory and goes inside the repository root, then pulls updates (if any), executes the given command in the repository config file (eg. ./configure && make), then copies the ojects given in the config file to the output dir (eg. build/release/binary.elf) and finally updates last Unix timestamp.
Tip: to test config, dailybuilder.sh can also be run manually in its directory.
Note that this could trigger the build of configured repositories and take some time, at least on first manual run.
Warning: no safety checks are done, so be very careful when doing anything!
Note: of course, the system that runs the dailybuilder must have installed
all the dependencies needed for the configured repositories.
Crontab example:
30 * * * * cd ~/bin/dailybuilder/ && ./dailybuilder.sh

6
config.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
REPOS_ENABLED_DIR="$HOME/bin/dailybuilder/repos-enabled/"
LAST_PULL_DIR="$HOME/bin/dailybuilder/var/last-pull/"
REPOS_DIR="$HOME/bin/dailybuilder/var/repos/"
OUTPUT_DIR="/raid/www/html-pubblici/pubblici/dailybuilds/"

5
dailybuilder.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
. config.sh
find "$REPOS_ENABLED_DIR" -iname "*.conf" -exec lib/build.sh {} \;

59
lib/build.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
. config.sh
STREAM=$(grep -v -e "^#" -e "^\s*$" "$1")
REPONAME=$(echo "$STREAM" | grep 'name:' | cut -d':' -f2- | sed -e 's/^[ \t]*//')
ADDRESS=$(echo "$STREAM" | grep 'address:' | cut -d':' -f2- | sed -e 's/^[ \t]*//')
COMMAND=$(echo "$STREAM" | grep 'command:' | cut -d':' -f2- | sed -e 's/^[ \t]*//')
OBJECTS=$(echo "$STREAM" | grep 'objects:' | cut -d':' -f2- | sed -e 's/^[ \t]*//')
RATE=$(echo "$STREAM" | grep 'rate:' | cut -d':' -f2- | sed -e 's/^[ \t]*//')
case "$RATE" in
d) # daily
RATESEC="86400"
;;
w) # weekly
RATESEC="604800"
;;
m) # monthly
RATESEC="2592000"
;;
*) # default, every time this script is run
RATESEC="0"
;;
esac
echo "Repository name: $REPONAME"
echo "Last pull dir: $LAST_PULL_DIR"
# If it has been pulled before, decide wether to pull or not
if [ -f "$LAST_PULL_DIR/$REPONAME" ]; then
LASTPULL=$(cat "$LAST_PULL_DIR/$REPONAME")
if [ $(("$LASTPULL" + "$RATESEC")) -le $(date +"%s") ]; then
echo "dailybuilder: repository needs to be built"
TO_BUILD="yes"
else
TO_BUILD="no"
echo "dailybuilder: nothing to do"
fi
# If it was never pulled before, clone
else
echo "dailybuilder: first clone..."
git clone "$ADDRESS" "$REPOS_DIR/$REPONAME/"
mkdir -p "$OUTPUT_DIR/$REPONAME"
TO_BUILD="yes"
fi
# Actually build
if [ "$TO_BUILD" == "yes" ]; then
echo "dailybuilder: cloning... $REPONAME"
cd "$REPOS_DIR/$REPONAME"
git pull
eval "$COMMAND"
cp -r "$OBJECTS" "$OUTPUT_DIR/$REPONAME"
git log | sed 's/<.*>//g' > "$OUTPUT_DIR/$REPONAME/log.txt"
date +"%s" > "$LAST_PULL_DIR/$REPONAME"
touch "$OUTPUT_DIR/$REPONAME"
fi

View File

@ -0,0 +1,23 @@
# Repository for example-reponame
# Name of the repository
# Repositories names must be unique
# I suggest to name the config file as the repository
name: example-reponame
# Address of git repository
# Obviously user needs (at least) read access on that repository
# Tip: use a passwordless login with ssh key
address: ssh://user@example.org/home/git/example-reponame.git
# Command to execute in the root directory of the repository
command: make
# Objects to copy in the output directory after the build
objects: src/a.out
# How frequently should I build this repository?
# Use d, w, m to build daily, weekly and monthly
# Any other value forces the build every time lib/build.sh is executed
rate: w

3
repos-enabled/README.md Normal file
View File

@ -0,0 +1,3 @@
# repos-enabled
This directory contains enabled configurations

4
var/last-pull/README.md Normal file
View File

@ -0,0 +1,4 @@
# last-pull
This directory will be populated with information about last pull time of each repository.
For each repository, a file will be created with the same name of the repository and its content will be the Unix timestamp of last pull.

3
var/repos/README.md Normal file
View File

@ -0,0 +1,3 @@
# repos
This directory will contain all pulled repositories.