aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schramm <tobleminer@gmail.com>2018-06-30 05:47:34 +0200
committerTobias Schramm <tobleminer@gmail.com>2018-06-30 05:47:34 +0200
commita77eee438ffb8c29906a8b71dbf18c3628a17ca8 (patch)
tree523b17f152a94744675277a6918d026db767ee8c
parent505a9005e794c1dbe4ed3b8d83590f8d2f80eecd (diff)
Update CI scripts to caching version
-rw-r--r--.gitlab-ci.yml74
-rwxr-xr-xbuild.sh29
-rwxr-xr-xupdate-git.sh29
3 files changed, 97 insertions, 35 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d52ca82..ae425a5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,14 +1,23 @@
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SSL_CAPATH: /etc/ssl/certs/
+ CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/build
+ GLUON_GIT: https://gitlab.toppoint.de/ffki/gluon.git
+ GLUON_BRANCH: v2017.1.8
+cache:
+ key: $CI_COMMIT_REF_SLUG-$GLUON_GIT-$GLUON_BRANCH
+ paths:
+ - gluon
stages:
- prepare
+ - clone
- build
+ - sign
+ - upload
-variables:
- CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/build
+# Preparation
prepare:
stage: prepare
@@ -22,26 +31,71 @@ prepare:
- docker build --cache-from $CONTAINER_IMAGE:latest -t $CONTAINER_IMAGE:$CI_BUILD_REF -t $CONTAINER_IMAGE:latest contrib/build-container
- docker push $CONTAINER_IMAGE:$CI_BUILD_REF
- docker push $CONTAINER_IMAGE:latest
+ cache: {}
+
+# Cache maintenance
+
+clone:
+ stage: clone
+ image: $CI_REGISTRY_IMAGE/build
+ script:
+ - ./update-git.sh | tee -a debug.log
+ artifacts:
+ untracked: false
+ paths:
+ - debug.log
+# Actual building
build:
stage: build
image: $CI_REGISTRY_IMAGE/build
script:
- export FORCE_UNSAFE_CONFIGURE=1
- - echo $SIGNING_KEY > signing_key
- - eval $(ssh-agent -s)
- - ssh-add <(echo "$SSH_KEY")
- - git clone https://gitlab.toppoint.de/ffki/gluon.git -b v2017.1.8 gluon
- - ./build.sh -c update -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
- - ./build.sh -c clean -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
+ # We can't be sure the cache is actually available right now, thus we have to perform all cache steps here, too
+ - ./update-git.sh | tee -a debug.log
+ - ./build.sh -c update -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
+ # We should never need this, should we?
+ - ./build.sh -c clean -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
#- ./build.sh -c download -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
- ./build.sh -c build -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
- - ./build.sh -c sign -b $CI_BUILD_REF_NAME -s $(pwd)/signing_key
- - ./build.sh -c upload -b $CI_BUILD_REF_NAME -n $CI_JOB_ID
+ # Bring gluon repo to cacheable state
+ - ./build.sh -c clean -b $CI_BUILD_REF_NAME -n $CI_JOB_ID -m "-j $(nproc --all) V=s" | tee -a debug.log
artifacts:
untracked: false
paths:
- debug.log
+ - output
expire_in: 1 week
when: always
+
+sign:
+ stage: sign
+ image: $CI_REGISTRY_IMAGE/build
+ script:
+ - echo $SIGNING_KEY > signing_key
+ # Update git in case cache is empty
+ - ./update-git.sh | tee -a debug.log
+ - ./build.sh -c sign -b $CI_BUILD_REF_NAME -s $(pwd)/signing_key
+ artifacts:
+ untracked: false
+ paths:
+ - output
+ cache:
+ key: $CI_COMMIT_REF_SLUG-$GLUON_GIT-$GLUON_BRANCH
+ paths:
+ - gluon
+ policy:
+ # This step does not need to modify the cache
+ pull
+
+upload:
+ stage: upload
+ image: $CI_REGISTRY_IMAGE/build
+ script:
+ - eval $(ssh-agent -s)
+ - ssh-add <(echo "$SSH_KEY")
+ # create fake gluon dir to satisfy build script
+ - mkdir -p gluon
+ - ./build.sh -c upload -b $CI_BUILD_REF_NAME -n $CI_JOB_ID
+ cache: {}
diff --git a/build.sh b/build.sh
index 03b0c14..df57deb 100755
--- a/build.sh
+++ b/build.sh
@@ -172,6 +172,7 @@ COMMIT="$(git describe --always --dirty)"
PRIORITY=1
update() {
+ echo "--- Update Gluon Dependencies"
make ${MAKEOPTS} \
GLUON_SITEDIR="${SITEDIR}" \
GLUON_OUTPUTDIR="${SITEDIR}/output" \
@@ -183,7 +184,7 @@ update() {
clean() {
for TARGET in ${TARGETS}; do
- echo "--- Update Gluon Dependencies for target: ${TARGET}"
+ echo "--- Clean Gluon Build Artifacts for target: ${TARGET}"
make ${MAKEOPTS} \
GLUON_SITEDIR="${SITEDIR}" \
GLUON_OUTPUTDIR="${SITEDIR}/output" \
@@ -274,18 +275,7 @@ upload() {
SSH="${SSH} -o stricthostkeychecking=no -v"
# Determine upload target prefix
- case "${BRANCH}" in
- stable| \
- testing| \
- nightly| \
- development)
- TARGET="${BRANCH}"
- ;;
-
- *)
- TARGET="others/${BRANCH}"
- ;;
- esac
+ TARGET="${BRANCH}"
# Create the target directory on server
${SSH} \
@@ -319,24 +309,13 @@ upload() {
ln -sf \
"/opt/firmware/ffki/${TARGET}/${RELEASE}-${BUILD}/factory" \
"/opt/firmware/ffki/${TARGET}/"
-
}
prepare() {
echo "--- Prepare directory for upload"
# Determine upload target prefix
- case "${BRANCH}" in
- stable| \
- testing| \
- development)
- TARGET="${BRANCH}"
- ;;
-
- *)
- TARGET="others/${BRANCH}"
- ;;
- esac
+ TARGET="${BRANCH}"
# Create the target directory on server
mkdir \
diff --git a/update-git.sh b/update-git.sh
new file mode 100755
index 0000000..b05f4b9
--- /dev/null
+++ b/update-git.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+set -e -o pipefail
+
+function update() {
+ # Kill it with fire
+ rm -rf gluon
+ git clone "$GLUON_GIT" -b "$GLUON_BRANCH" gluon
+}
+
+(
+ if ! [[ -e gluon ]]; then
+ echo "gluon dir nonexistent, updating"
+ update
+ exit 0
+ fi
+
+ REMOTE_REF=$(git ls-remote -qht "$GLUON_GIT" | grep "$GLUON_BRANCH" | cut -f1)
+
+ cd gluon
+ set +e
+ LOCAL_REF=$(git rev-parse HEAD)
+ cd ..
+
+ if [[ $? -ne 0 || $REMOTE_REF != "$LOCAL_REF" ]]; then
+ echo "$REMOTE_REF != $LOCAL_REF, updating"
+ update
+ fi
+)