Signed-off-by: Uwe Hermann <uh@uleenucks.de>
This commit is contained in:
@@ -6,12 +6,13 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: build_and_push
|
name: build_and_push
|
||||||
runs-on: ubuntu-latest
|
runs-on: docker-stable
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: sh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install docker
|
- name: Login to docker
|
||||||
run: curl -fsSL https://get.docker.com | sh
|
run: docker login -u uleenucks -p ${{ secrets.CI_TOKEN }}
|
||||||
- name: Install parallel
|
- name: Build docker container
|
||||||
run: apt install parallel -y
|
run: ./build-all.sh
|
||||||
- name: build_and_push
|
|
||||||
run: ./build-all.sh
|
|
||||||
+63
-59
@@ -16,83 +16,87 @@ dcleanup(){
|
|||||||
"${DOCKER}" rmi $("${DOCKER}" images --filter dangling=true -q 2>/dev/null) 2>/dev/null
|
"${DOCKER}" rmi $("${DOCKER}" images --filter dangling=true -q 2>/dev/null) 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
build_and_push_kaniko(){
|
build_and_push(){
|
||||||
base=$1
|
base=$1
|
||||||
suite=$2
|
suite=$2
|
||||||
build_dir=$3
|
build_dir=$3
|
||||||
|
|
||||||
echo "Building ${REPO_URL}/${base}:${suite} for context ${build_dir}"
|
echo "Building ${REPO_URL}/${base}:${suite} for context ${build_dir}"
|
||||||
docker run \
|
docker build --rm --force-rm -t "${REPO_URL}/${base}:${suite}" "${build_dir}" || return 1
|
||||||
-v "$(pwd)/config.json:/kaniko/.docker/config.json:ro" \
|
|
||||||
-v "$(pwd)/${build_dir}:/workspace" \
|
|
||||||
gcr.io/kaniko-project/executor:debug \
|
|
||||||
--destination "${REPO_URL}/${base}:${suite}" --force \
|
|
||||||
--context dir:///workspace/ \
|
|
||||||
|| return 1
|
|
||||||
|
|
||||||
# on successful build, push the image
|
# on successful build, push the image
|
||||||
echo " --- "
|
echo " --- "
|
||||||
echo "Successfully built and pushed ${base}:${suite} with context ${build_dir}"
|
echo "Successfully built ${base}:${suite} with context ${build_dir}"
|
||||||
echo " --- "
|
echo " --- "
|
||||||
|
|
||||||
|
# try push a few times because notary server sometimes returns 401 for
|
||||||
|
# absolutely no reason
|
||||||
|
n=0
|
||||||
|
until [ $n -ge 5 ]; do
|
||||||
|
docker push --disable-content-trust=false "${REPO_URL}/${base}:${suite}" && break
|
||||||
|
echo "Try #$n failed... sleeping for 15 seconds"
|
||||||
|
n=$((n+1))
|
||||||
|
sleep 15
|
||||||
|
done
|
||||||
|
|
||||||
|
# also push the tag latest for "stable" (chrome), "tools" (wireguard) or "3.5" tags for zookeeper
|
||||||
|
if [[ "$suite" == "stable" ]] || [[ "$suite" == "3.6" ]] || [[ "$suite" == "tools" ]]; then
|
||||||
|
docker tag "${REPO_URL}/${base}:${suite}" "${REPO_URL}/${base}:latest"
|
||||||
|
docker push --disable-content-trust=false "${REPO_URL}/${base}:latest"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
dofile() {
|
dofile() {
|
||||||
f=$1
|
f=$1
|
||||||
image=${f%Dockerfile}
|
image=${f%Dockerfile}
|
||||||
base=${image%%\/*}
|
base=${image%%\/*}
|
||||||
build_dir=$(dirname "$f")
|
build_dir=$(dirname "$f")
|
||||||
suite=${build_dir##*\/}
|
suite=${build_dir##*\/}
|
||||||
|
|
||||||
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then
|
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then
|
||||||
suite=latest
|
suite=latest
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{
|
{
|
||||||
$SCRIPT build_and_push_kaniko "${base}" "${suite}" "${build_dir}"
|
$SCRIPT build_and_push "${base}" "${suite}" "${build_dir}"
|
||||||
} || {
|
} || {
|
||||||
# add to errors
|
# add to errors
|
||||||
echo "${base}:${suite}" >> "$ERRORS"
|
echo "${base}:${suite}" >> "$ERRORS"
|
||||||
}
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
echo
|
||||||
prescript(){
|
echo
|
||||||
cd "${DOCKERFILESPATH}"
|
|
||||||
rm -f errors
|
|
||||||
git pull
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main(){
|
main(){
|
||||||
# get the dockerfiles
|
# get the dockerfiles
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
files=( $(find . -iname '*Dockerfile' | sed 's|./||' | sort) )
|
mapfile -t files < <(find -L . -iname '*Dockerfile' | sed 's|./||' | sort)
|
||||||
unset IFS
|
unset IFS
|
||||||
|
|
||||||
# build all dockerfiles
|
# build all dockerfiles
|
||||||
echo "Running in parallel with ${JOBS} jobs."
|
echo "Running in parallel with ${JOBS} jobs."
|
||||||
parallel --tag --verbose --ungroup -j"${JOBS}" "$SCRIPT" dofile "{1}" ::: "${files[@]}"
|
parallel --tag --verbose --ungroup -j"${JOBS}" "$SCRIPT" dofile "{1}" ::: "${files[@]}"
|
||||||
|
|
||||||
if [[ ! -f $ERRORS ]]; then
|
if [[ ! -f "$ERRORS" ]]; then
|
||||||
echo "No errors, hooray!"
|
echo "No errors, hooray!"
|
||||||
else
|
else
|
||||||
echo "[ERROR] Some images did not build correctly, see below." >&2
|
echo "[ERROR] Some images did not build correctly, see below." >&2
|
||||||
echo "These images failed: $(cat "$ERRORS")" >&2
|
echo "These images failed: $(cat "$ERRORS")" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run(){
|
run(){
|
||||||
args=$@
|
args=$*
|
||||||
f=$1
|
f=$1
|
||||||
|
|
||||||
if [[ "$f" == "" ]]; then
|
if [[ "$f" == "" ]]; then
|
||||||
main "$args"
|
main "$args"
|
||||||
else
|
else
|
||||||
$args
|
$args
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run "$@"
|
||||||
#prescript
|
#prescript
|
||||||
run $@
|
|
||||||
dcleanup
|
dcleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user