Lint all script / make it easy to use with commands (#5)

Add an optional extended description…
This commit is contained in:
Pascal Vizeli 2017-05-05 11:37:04 +02:00 committed by GitHub
parent 245bfb97e7
commit 15de7ee7a1
9 changed files with 363 additions and 152 deletions

View file

@ -1,5 +1,4 @@
#!/bin/bash
set -e
DOCKER_TIMEOUT=20 # Wait 20 seconds for docker to start
@ -10,23 +9,23 @@ cleanup() {
# Stop docker gracefully
echo "[INFO] Stopping in container docker..."
DOCKERPIDFILE=/var/run/docker.pid
if [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; then
kill $(cat $DOCKERPIDFILE)
if [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && pgrep -F $DOCKERPIDFILE; then
kill "$(cat $DOCKERPIDFILE)"
# Now wait for it to die
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
while [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
while [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && pgrep -F $DOCKERPIDFILE; do
if [ $((ENDTIME - STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for in container docker to die."
echo "[ERROR] Timeout while waiting for in container docker to die"
exit 1
fi
done
else
echo "[WARN] Can't stop docker container."
echo "[WARN] Your host might have been left with unreleased resources (ex. loop devices)."
echo "[WARN] Can't stop docker container"
echo "[WARN] Your host might have been left with unreleased resources (ex. loop devices)"
fi
if [ "$1" == "fail" ]; then
@ -36,7 +35,7 @@ cleanup() {
trap 'cleanup fail' SIGINT SIGTERM
# Start docker
echo "[INFO] Setup qemu-arm."
echo "[INFO] Setup crosscompiling feature"
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
update-binfmts --enable qemu-arm
update-binfmts --enable qemu-aarch64
@ -48,29 +47,28 @@ echo "[INFO] Waiting for docker to initialize..."
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
until docker info >/dev/null 2>&1; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
if [ $((ENDTIME - STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for docker to come up."
echo "[ERROR] Timeout while waiting for docker to come up"
exit 1
fi
done
echo "[INFO] Docker was initialized."
echo "[INFO] Docker was initialized"
# Start barys with all the arguments requested
echo "[INFO] Running build..."
# Build
docker build --pull --tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} .
# Tag
docker tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
docker build --pull --tag "$DOCKER_IMAGE:$DOCKER_TAG" .
docker tag "$DOCKER_IMAGE:$DOCKER_TAG" "$DOCKER_IMAGE:latest"
echo "[INFO] Push image"
if [ ${DOCKER_TAG} != "NONE" ]; then
if [ "$DOCKER_PUSH" == "true" ]; then
# push
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
docker push "$DOCKER_IMAGE:$DOCKER_TAG"
docker push "$DOCKER_IMAGE:latest"
fi
cleanup
cleanup "okay"
exit 0