1
0
Fork 0
mirror of https://github.com/lineageos4microg/docker-lineage-cicd synced 2024-05-18 03:06:07 +02:00

Add external scripts support

This commit is contained in:
Nicola Corna 2017-10-27 08:07:37 +02:00
parent 5552c1922a
commit 4ef85b9fe3
3 changed files with 59 additions and 0 deletions

View File

@ -11,6 +11,7 @@ ENV LMANIFEST_DIR /srv/local_manifests
ENV DELTA_DIR /srv/delta
ENV KEYS_DIR /srv/keys
ENV LOGS_DIR /srv/logs
ENV USERSCRIPTS_DIR /srv/userscripts
ENV DEBIAN_FRONTEND noninteractive
ENV USER root
@ -107,6 +108,15 @@ ENV DELETE_OLD_LOGS 0
# Requires ZIP_SUBDIR.
ENV OPENDELTA_BUILDS_JSON ''
# You can optionally specify a USERSCRIPTS_DIR volume containing these scripts:
# * begin.sh, run at the very beginning
# * before.sh, run after the syncing and patching, before starting the builds
# * pre-build.sh, run before the build of every device
# * post-build.sh, run after the build of every device
# * end.sh, run at the very end
# Each script will be run in $SRC_DIR and must be owned and writeable only by
# root
# Create Volume entry points
############################
VOLUME $SRC_DIR
@ -116,6 +126,7 @@ VOLUME $LMANIFEST_DIR
VOLUME $DELTA_DIR
VOLUME $KEYS_DIR
VOLUME $LOGS_DIR
VOLUME $USERSCRIPTS_DIR
# Copy required files
#####################
@ -130,6 +141,7 @@ RUN mkdir -p $LMANIFEST_DIR
RUN mkdir -p $DELTA_DIR
RUN mkdir -p $KEYS_DIR
RUN mkdir -p $LOGS_DIR
RUN mkdir -p $USERSCRIPTS_DIR
# Install build dependencies
############################

View File

@ -22,6 +22,11 @@ if ! [ -z "$DEVICE_LIST" ]; then
# cd to working directory
cd $SRC_DIR
if [ -f /root/userscripts/begin.sh ]; then
echo ">> [$(date)] Running begin.sh"
/root/userscripts/begin.sh
fi
# If the source directory is empty
if ! [ "$(ls -A $SRC_DIR)" ]; then
# Initialize repository
@ -115,6 +120,11 @@ if ! [ -z "$DEVICE_LIST" ]; then
sed -i "1s;^;PRODUCT_DEFAULT_DEV_CERTIFICATE := $KEYS_DIR/releasekey\nPRODUCT_OTA_PUBLIC_KEYS := $KEYS_DIR/releasekey\nPRODUCT_EXTRA_RECOVERY_KEYS := $KEYS_DIR/releasekey\n\n;" vendor/cm/config/common.mk
fi
if [ -f /root/userscripts/before.sh ]; then
echo ">> [$(date)] Running before.sh"
/root/userscripts/before.sh
fi
# Cycle DEVICE_LIST environment variable, to know which one may be executed next
IFS=','
for codename in $DEVICE_LIST; do
@ -142,6 +152,12 @@ if ! [ -z "$DEVICE_LIST" ]; then
los_ver_major=$(sed -n -e 's/^\s*PRODUCT_VERSION_MAJOR = //p' vendor/cm/config/common.mk)
los_ver_minor=$(sed -n -e 's/^\s*PRODUCT_VERSION_MINOR = //p' vendor/cm/config/common.mk)
DEBUG_LOG="$LOGS_DIR/$logsubdir/lineage-$los_ver_major.$los_ver_minor-$builddate-$RELEASE_TYPE-$codename.log"
if [ -f /root/userscripts/pre-build.sh ]; then
echo ">> [$(date)] Running pre-build.sh for $codename" >> $DEBUG_LOG 2>&1
/root/userscripts/pre-build.sh $codename >> $DEBUG_LOG 2>&1
fi
# Start the build
echo ">> [$(date)] Starting build for $codename" | tee -a $DEBUG_LOG
if brunch $codename >> $DEBUG_LOG 2>&1; then
@ -189,6 +205,10 @@ if ! [ -z "$DEVICE_LIST" ]; then
echo ">> [$(date)] Cleaning build for $codename" | tee -a $DEBUG_LOG
rm -rf $SRC_DIR/out/target/product/$codename/ >> $DEBUG_LOG 2>&1
fi
if [ -f /root/userscripts/post-build.sh ]; then
echo ">> [$(date)] Running post-build.sh for $codename" >> $DEBUG_LOG 2>&1
/root/userscripts/post-build.sh $codename >> $DEBUG_LOG 2>&1
fi
echo ">> [$(date)] Finishing build for $codename" | tee -a $DEBUG_LOG
fi
done
@ -206,4 +226,9 @@ if ! [ -z "$DEVICE_LIST" ]; then
if [ "$CLEAN_SRCDIR" = true ]; then
rm -rf "$SRC_DIR/*"
fi
if [ -f /root/userscripts/end.sh ]; then
echo ">> [$(date)] Running end.sh"
/root/userscripts/end.sh
fi
fi

View File

@ -17,6 +17,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function check_and_copy {
if [ -f $1/$2 ]; then
if [[ $(stat --format '%U' $1/$2) == "root" ]]; then
if [[ $(stat --format '%A' $1/$2) =~ .r.x.-..-. ]]; then
echo ">> [$(date)] Valid $2 found"
cp $1/$2 /root/userscripts/
else
echo ">> [$(date)] $2 has wrong permissions, ignoring"
fi
else
echo ">> [$(date)] $2 isn't owned by root, ignoring"
fi
fi
}
userscripts="begin.sh before.sh pre-build.sh post-build.sh end.sh"
mkdir -p /root/userscripts
for f in $userscripts; do
check_and_copy $USERSCRIPTS_DIR $f
done
# Initialize CCache if it will be used
if [ "$USE_CCACHE" = 1 ]; then
ccache -M 100G 2>&1