7 local rematch='^[^=]*=(.*)$'
8 if [[ $2 =~ $rematch ]]; then
9 read -r "$1" <<< "${BASH_REMATCH[1]}"
12 # There is no way to shift our callers args, so
13 # return 1 to indicate they should do it instead.
19 if docker -v |& grep -q podman; then
22 # Docker is actually implemented by podman, and its OCI output
23 # is incompatible with some of the dockerd instances on GitLab
25 export BUILDAH_FORMAT=docker
46 --base|-b) read_arg base "$@" || shift;;
47 --base-version) read_arg base_version "$@" || shift;;
48 --no-login) no_login=1;;
49 *) echo -e "\\e[1;31mERROR\\e[0m: Unknown option '$1'"; exit 1;;
54 if [ $print_help == 1 ]; then
55 echo "$0 - Build and run Docker images"
57 echo "Usage: $0 <command> [options] [basename]"
59 echo "Available commands"
61 echo " build --base=<BASENAME> - Build Docker image <BASENAME>.Dockerfile"
62 echo " run --base=<BASENAME> - Run Docker image <BASENAME>"
63 echo " push --base=<BASENAME> - Push Docker image <BASENAME> to the registry"
64 echo " list - List available images"
65 echo " help - This help message"
72 if [ $list == 1 ]; then
73 echo "Available Docker images:"
74 for f in *.Dockerfile; do
75 filename=$( basename -- "$f" )
76 basename="${filename%.*}"
78 echo -e " \\e[1;39m$basename\\e[0m"
83 # All commands after this require --base to be set
84 if [ -z "${base}" ]; then
85 echo "Usage: $0 <command>"
89 if [ ! -f "$base.Dockerfile" ]; then
90 echo -e "\\e[1;31mERROR\\e[0m: Dockerfile for '$base' not found"
94 if [ -z "${base_version}" ]; then
97 base_version="v$base_version"
100 TAG="registry.gitlab.gnome.org/gnome/glib/${base}:${base_version}"
102 if [ $build == 1 ]; then
103 echo -e "\\e[1;32mBUILDING\\e[0m: ${base} as ${TAG}"
104 $SUDO_CMD docker build \
105 --build-arg HOST_USER_ID="$UID" \
106 --build-arg COVERITY_SCAN_PROJECT_NAME="${COVERITY_SCAN_PROJECT_NAME}" \
107 --build-arg COVERITY_SCAN_TOKEN="${COVERITY_SCAN_TOKEN}" \
109 --file "${base}.Dockerfile" .
113 if [ $push == 1 ]; then
114 echo -e "\\e[1;32mPUSHING\\e[0m: ${base} as ${TAG}"
116 if [ $no_login == 0 ]; then
117 $SUDO_CMD docker login registry.gitlab.gnome.org
120 $SUDO_CMD docker push $TAG
124 if [ $run == 1 ]; then
125 echo -e "\\e[1;32mRUNNING\\e[0m: ${base} as ${TAG}"
126 $SUDO_CMD docker run \
128 --volume "$(pwd)/..:/home/user/app" \
129 --workdir "/home/user/app" \
131 --interactive "${TAG}" \