Skip to content

Commit 7c59c52

Browse files
committed
Lots of cleanup to docker-related scripts
1 parent 35d51ac commit 7c59c52

4 files changed

Lines changed: 217 additions & 192 deletions

File tree

docker/common.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
#
6+
# This Source Code Form is "Incompatible With Secondary Licenses", as
7+
# defined by the Mozilla Public License, v. 2.0.
8+
9+
##################################################
10+
# Common checks and functions for docker scripts #
11+
##################################################
12+
13+
# Function to print text in red if terminal supports it
14+
echo_red() {
15+
if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ $(tput colors 2>/dev/null || echo 0) -ge 8 ]; then
16+
echo -e "\033[31m$1\033[0m"
17+
else
18+
echo "$1"
19+
fi
20+
}
21+
22+
# Function to print text in green if terminal supports it
23+
echo_green() {
24+
if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ $(tput colors 2>/dev/null || echo 0) -ge 8 ]; then
25+
echo -e "\033[32m$1\033[0m"
26+
else
27+
echo "$1"
28+
fi
29+
}
30+
31+
# Check that we're in the root of the Bugzilla source tree
32+
if [ ! -e 'Makefile.PL' ]; then
33+
echo
34+
echo_red "Please run this from the root of the Bugzilla source tree."
35+
echo
36+
exit -1
37+
fi
38+
39+
# Find and validate the Docker executable
40+
if [ -z "$DOCKER" ]; then
41+
DOCKER=`which docker`
42+
fi
43+
if [ -n "$DOCKER" ] && [ ! -x "$DOCKER" ]; then
44+
echo
45+
echo_red "You specified a custom Docker executable via the DOCKER"
46+
echo_red "environment variable at $DOCKER"
47+
echo_red "which either does not exist or is not executable."
48+
echo "Please fix it to point at a working Docker or remove the"
49+
echo "DOCKER environment variable to use the one in your PATH"
50+
echo "if it exists."
51+
echo
52+
exit -1
53+
fi
54+
if [ -z "$DOCKER" ]; then
55+
echo
56+
echo_red "You do not appear to have docker installed or I can't find it."
57+
echo "Windows and Mac versions can be downloaded from"
58+
echo "https://www.docker.com/products/docker-desktop"
59+
echo "Linux users can install using your package manager."
60+
echo
61+
echo "Please install docker or specify the location of the docker"
62+
echo "executable in the DOCKER environment variable and try again."
63+
echo
64+
exit -1
65+
fi
66+
67+
# Check that Docker daemon is running
68+
$DOCKER info 1>/dev/null 2>/dev/null
69+
if [ $? != 0 ]; then
70+
echo
71+
echo_red "The docker daemon is not running or I can't connect to it."
72+
echo "Please make sure it's running and try again."
73+
echo
74+
exit -1
75+
fi
76+
77+
# Disable Docker CLI hints
78+
export DOCKER_CLI_HINTS=false

docker/gen-cpanfile-snapshot.sh

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,9 @@
66
# This Source Code Form is "Incompatible With Secondary Licenses", as
77
# defined by the Mozilla Public License, v. 2.0.
88

9-
if [ ! -e 'Makefile.PL' ]; then
10-
echo
11-
echo "Please run this from the root of the Bugzilla source tree."
12-
echo
13-
exit -1
14-
fi
15-
if [ -z "$DOCKER" ]; then
16-
DOCKER=`which docker`
17-
fi
18-
if [ -n "$DOCKER" ] && [ ! -x "$DOCKER" ]; then
19-
echo
20-
echo "You specified a custom Docker executable via the DOCKER"
21-
echo "environment variable at $DOCKER"
22-
echo "which either does not exist or is not executable."
23-
echo "Please fix it to point at a working Docker or remove the"
24-
echo "DOCKER environment variable to use the one in your PATH"
25-
echo "if it exists."
26-
echo
27-
exit -1
28-
fi
29-
if [ -z "$DOCKER" ]; then
30-
echo
31-
echo "You do not appear to have docker installed or I can't find it."
32-
echo "Windows and Mac versions can be downloaded from"
33-
echo "https://www.docker.com/products/docker-desktop"
34-
echo "Linux users can install using your package manager."
35-
echo
36-
echo "Please install docker or specify the location of the docker"
37-
echo "executable in the DOCKER environment variable and try again."
38-
echo
39-
exit -1
40-
fi
41-
$DOCKER info 1>/dev/null 2>/dev/null
42-
if [ $? != 0 ]; then
43-
echo
44-
echo "The docker daemon is not running or I can't connect to it."
45-
echo "Please make sure it's running and try again."
46-
echo
47-
exit -1
48-
fi
9+
# Source common Docker script checks and functions
10+
source "$(dirname "$0")/common.sh"
11+
4912
if [ ! -f "docker/images/Dockerfile.cpanfile" ]; then
5013
echo
5114
echo "Can't locate the Dockerfile, try running from the root of"
@@ -54,7 +17,6 @@ if [ ! -f "docker/images/Dockerfile.cpanfile" ]; then
5417
exit -1
5518
fi
5619

57-
export DOCKER_CLI_HINTS=false
5820
$DOCKER build -t bugzilla-cpanfile -f docker/images/Dockerfile.cpanfile .
5921
$DOCKER run -it -v "$(pwd):/app/result" bugzilla-cpanfile cp cpanfile cpanfile.snapshot /app/result
6022

0 commit comments

Comments
 (0)