1
0
mirror of https://github.com/lineageos4microg/docker-lineage-cicd synced 2024-09-20 12:22:40 +02:00

Improve overall logging

This commit is contained in:
Julian Xhokaxhiu 2017-01-24 22:31:34 +01:00
parent d6e53000ff
commit 7f5ef167ea
2 changed files with 31 additions and 24 deletions

View File

@ -4,9 +4,10 @@
#
###########################################################
OUTPUT=/dev/null
DOCKER_LOG=/var/log/docker.log
DEBUG_LOG=/dev/null
if [ "$DEBUG" = true ]; then
OUTPUT=/var/log/docker.log
DEBUG_LOG=$DOCKER_LOG
fi
if ! [ -z "$DEVICE_LIST" ]; then
@ -17,41 +18,41 @@ if ! [ -z "$DEVICE_LIST" ]; then
# If the source directory is empty
if ! [ "$(ls -A $SRC_DIR)" ]; then
# Initialize repository
echo ">> [$(date)] Initializing repository"
yes | repo init -u git://github.com/lineageos/android.git -b $BRANCH_NAME 2>&1 >&$OUTPUT
echo ">> [$(date)] Initializing repository" >> $DOCKER_LOG
yes | repo init -u git://github.com/lineageos/android.git -b $BRANCH_NAME 2>&1 >&$DEBUG_LOG
fi
# Copy local manifests to the appropriate folder in order take them into consideration
echo ">> [$(date)] Copying '$LMANIFEST_DIR/*.xml' to '$SRC_DIR/.repo/local_manifests/'"
cp $LMANIFEST_DIR/*.xml $SRC_DIR/.repo/local_manifests/ >&$OUTPUT
echo ">> [$(date)] Copying '$LMANIFEST_DIR/*.xml' to '$SRC_DIR/.repo/local_manifests/'" >> $DOCKER_LOG
cp $LMANIFEST_DIR/*.xml $SRC_DIR/.repo/local_manifests/ >&$DEBUG_LOG
# Go to "vendor/cm" and reset it's current git status ( remove previous changes ) only if the directory exists
if [ -d "vendor/cm" ]; then
cd vendor/cm
git reset --hard 2>&1 >&$OUTPUT
git reset --hard 2>&1 >&$DEBUG_LOG
cd $SRC_DIR
fi
# Sync the source code
echo ">> [$(date)] Syncing repository"
repo sync 2>&1 >&$OUTPUT
echo ">> [$(date)] Syncing repository" >> $DOCKER_LOG
repo sync 2>&1 >&$DEBUG_LOG
# If requested, clean the OUT dir in order to avoid clutter
if [ "$CLEAN_OUTDIR" = true ]; then
echo ">> [$(date)] Cleaning '$ZIP_DIR'"
echo ">> [$(date)] Cleaning '$ZIP_DIR'" >> $DOCKER_LOG
cd $ZIP_DIR
rm *
cd $SRC_DIR
fi
# Prepare the environment
echo ">> [$(date)] Preparing build environment"
source build/envsetup.sh 2>&1 >&$OUTPUT
echo ">> [$(date)] Preparing build environment" >> $DOCKER_LOG
source build/envsetup.sh 2>&1 >&$DEBUG_LOG
# Set a custom updater URI if a OTA URL is provided
if ! [ -z "$OTA_URL" ]; then
echo ">> [$(date)] Adding OTA URL '$OTA_URL' to build.prop"
sed -i "1s;^;PRODUCT_PROPERTY_OVERRIDES += cm.updater.uri=$OTA_URL\n\n;" vendor/cm/config/common.mk >&$OUTPUT
echo ">> [$(date)] Adding OTA URL '$OTA_URL' to build.prop" >> $DOCKER_LOG
sed -i "1s;^;PRODUCT_PROPERTY_OVERRIDES += cm.updater.uri=$OTA_URL\n\n;" vendor/cm/config/common.mk >&$DEBUG_LOG
fi
# Cycle DEVICE_LIST environment variable, to know which one may be executed next
@ -59,22 +60,22 @@ if ! [ -z "$DEVICE_LIST" ]; then
for codename in $DEVICE_LIST; do
if ! [ -z "$codename" ]; then
# Start the build
echo ">> [$(date)] Starting build for $codename"
if brunch $codename 2>&1 >&$OUTPUT; then
echo ">> [$(date)] Starting build for $codename" >> $DOCKER_LOG
if brunch $codename 2>&1 >&$DEBUG_LOG; then
# Move produced ZIP files to the main OUT directory
echo ">> [$(date)] Moving build artifacts for $codename to '$ZIP_DIR'"
echo ">> [$(date)] Moving build artifacts for $codename to '$ZIP_DIR'" >> $DOCKER_LOG
cd $SRC_DIR
find out/target/product/$codename -name '*UNOFFICIAL*.zip*' -exec mv {} $ZIP_DIR \; >&$OUTPUT
find out/target/product/$codename -name '*UNOFFICIAL*.zip*' -exec mv {} $ZIP_DIR \; >&$DEBUG_LOG
# Clean everything, in order to start fresh on next build
if [ "$CLEAN_AFTER_BUILD" = true ]; then
echo ">> [$(date)] Cleaning build for $codename"
make clean 2>&1 >&$OUTPUT
echo ">> [$(date)] Cleaning build for $codename" >> $DOCKER_LOG
make clean 2>&1 >&$DEBUG_LOG
fi
else
echo ">> [$(date)] Failed build for $codename"
echo ">> [$(date)] Failed build for $codename" >> $DOCKER_LOG
fi
echo ">> [$(date)] Finishing build for $codename"
echo ">> [$(date)] Finishing build for $codename" >> $DOCKER_LOG
fi
done

View File

@ -4,9 +4,15 @@
#
###########################################################
DOCKER_LOG=/var/log/docker.log
DEBUG_LOG=/dev/null
if [ "$DEBUG" = true ]; then
DEBUG_LOG=$DOCKER_LOG
fi
# Initialize CCache if it will be used
if [ "$USE_CCACHE" = 1 ]; then
ccache -M 50G
ccache -M 50G 2>&1 >&$DEBUG_LOG
fi
# Initialize Git user information
@ -17,7 +23,7 @@ git config --global user.email $USER_MAIL
cronFile=/tmp/buildcron
printf "SHELL=/bin/bash\n" > $cronFile
printenv -0 | sed -e 's/=\x0/=""\n/g' | sed -e 's/\x0/\n/g' | sed -e "s/_=/PRINTENV=/g" >> $cronFile
printf "\n$CRONTAB_TIME /usr/bin/flock -n /tmp/lock.build /root/build.sh >> /var/log/docker.log 2>&1\n" >> $cronFile
printf "\n$CRONTAB_TIME /usr/bin/flock -n /tmp/lock.build /root/build.sh\n" >> $cronFile
crontab $cronFile
rm $cronFile