diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3fa4fe03..7f632a186 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,15 +14,16 @@ on: jobs: test_sanity: + name: Sanity Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install docker-compose run: sudo apt-get update && sudo apt-get install -y docker-compose - name: Build the Docker images - run: docker compose -f docker-compose.test.yml build + run: docker compose -f docker-compose.test-mysql.yml build - name: Run sanity tests - run: docker compose -f docker-compose.test.yml run --no-deps bugzilla6.test test_sanity t/*.t extensions/*/t/*.t + run: docker compose -f docker-compose.test-mysql.yml run --no-deps bugzilla6.test test_sanity t/*.t extensions/*/t/*.t # test_webservices: # runs-on: ubuntu-latest @@ -31,22 +32,24 @@ jobs: # - name: Install docker-compose # run: sudo apt-get update && sudo apt-get install -y docker-compose # - name: Build the Docker images -# run: docker compose -f docker-compose.test.yml build +# run: docker compose -f docker-compose.test-mysql.yml build # - name: Run webservice tests -# run: docker compose -f docker-compose.test.yml run bugzilla6.test test_webservices +# run: docker compose -f docker-compose.test-mysql.yml run bugzilla6.test test_webservices test_bugzilla6_mysql: + name: Interactive Tests with MySQL runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install docker-compose run: sudo apt-get update && sudo apt-get install -y docker-compose - name: Build the Docker images - run: docker compose -f docker-compose.test.yml build + run: docker compose -f docker-compose.test-mysql.yml build - name: Run bmo specific tests - run: docker compose -f docker-compose.test.yml run -e CI=1 bugzilla6.test test_bmo -q -f t/bmo/*.t + run: docker compose -f docker-compose.test-mysql.yml run -e CI=1 bugzilla6.test test_bmo -q -f t/bmo/*.t test_bugzilla6_mariadb: + name: Interactive Tests with MariaDB runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -58,6 +61,7 @@ jobs: run: docker compose -f docker-compose.test-mariadb.yml run -e CI=1 bugzilla6.test test_bmo -q -f t/bmo/*.t test_bugzilla6_pg: + name: Interactive Tests with PostgreSQL runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -69,6 +73,7 @@ jobs: run: docker compose -f docker-compose.test-pg.yml run -e CI=1 bugzilla6.test test_bmo -q -f t/bmo/*.t test_bugzilla6_sqlite: + name: Interactive Tests with SQLite runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -79,3 +84,26 @@ jobs: - name: Run bmo specific tests run: docker compose -f docker-compose.test-sqlite.yml run -e CI=1 bugzilla6.test test_bmo -q -f t/bmo/*.t + test_release: + name: Perl Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + - name: Build Docker image + run: docker build -t bugzilla-release-test -f docker/images/Dockerfile.perl-testsuite . + - name: Run tests + run: docker run --rm bugzilla-release-test + + shellcheck: + name: ShellCheck (linting for shell scripts) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install ShellCheck + run: sudo apt-get update && sudo apt-get install -y shellcheck + - name: Run ShellCheck on all scripts + run: | + find . -type f -name '*.sh' | while read -r file; do + shellcheck -x "$file" + done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 97a8af1d7..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,73 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Release Tests - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the main branch -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - ubuntu: - name: Release Tests on Ubuntu 24.04 - runs-on: ubuntu-24.04 - steps: - - name: Checkout the repository - uses: actions/checkout@v4 - - name: Cache CPAN packages - uses: actions/cache@v4 - with: - path: | - ~/.perl-cpm/cache - ~/.perl-cpm/builds - **/local/ - key: ${{ runner.os }}-ubuntu-24.04 - restore-keys: | - ${{ runner.os }}-ubuntu-24.04 - - name: apt install - run: | - sudo apt-get update - sudo apt-get -y dist-upgrade - sudo apt-get install --ignore-hold --allow-downgrades -y \ - apache2 \ - cpanminus \ - mariadb-client \ - netcat-traditional \ - build-essential \ - libapache2-mod-perl2 \ - libapache2-mod-perl2-dev \ - libgd3 \ - libgd-dev \ - perlmagick \ - graphviz \ - curl libssl-dev zlib1g-dev openssl \ - libexpat-dev cmake git libcairo-dev \ - unzip wget - - name: Run Makefile.PL - run: | - perl Makefile.PL - cpanm --notest --quiet --local-lib="$GITHUB_WORKSPACE/.github/cpm/lib/perl5" Module::CPANfile - make cpanfile GEN_CPANFILE_ARGS='-A -U oracle' - - name: cpm install - run: | - perl -I"$GITHUB_WORKSPACE/.github/cpm/lib/perl5" "$GITHUB_WORKSPACE/.github/cpm/bin/cpm" install \ - && tar -C "$GITHUB_WORKSPACE" \ - --exclude 'local/cache/*' \ - --exclude 'local/man/*' \ - --exclude '*.pod' \ - -zcvf local-lib.tar.gz local - - name: Save dependencies - uses: actions/upload-artifact@v4 - with: - name: ubuntu-24.04-local-lib.tar.gz - path: local-lib.tar.gz - - name: Run checksetup - run: 'perl checksetup.pl --no-database --default-localconfig --no-templates' - - name: Run tests - run: 'prove -Ilocal/lib/perl5 t' diff --git a/.gitignore b/.gitignore index c22c12e75..f64bec8dd 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ version.json __lbheartbeat__ .perl-version +*.bak /skins/contrib/Dusk/admin.css /skins/contrib/Dusk/bug.css diff --git a/Dockerfile b/Dockerfile index 85a88cd97..1f3858599 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ARG BZDB="-mysql" FROM bugzilla/bugzilla-perl-slim${BZDB}:20250925.1 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive ENV LOG4PERL_CONFIG_FILE=log4perl-json.conf diff --git a/docker-compose.test.yml b/docker-compose.test-mysql.yml similarity index 100% rename from docker-compose.test.yml rename to docker-compose.test-mysql.yml diff --git a/docker/common.sh b/docker/common.sh new file mode 100644 index 000000000..e0ce1fc11 --- /dev/null +++ b/docker/common.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +################################################## +# Common checks and functions for docker scripts # +################################################## + +# Function to print text in red if terminal supports it +echo_red() { + if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then + echo -e "\033[31m$1\033[0m" + else + echo "$1" + fi +} + +# Function to print text in green if terminal supports it +echo_green() { + if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then + echo -e "\033[32m$1\033[0m" + else + echo "$1" + fi +} + +# Check that we're in the root of the Bugzilla source tree +if [ ! -e 'Makefile.PL' ]; then + echo + echo_red "Please run this from the root of the Bugzilla source tree." + echo + exit 1 +fi + +# Find and validate the Docker executable +if [ -z "$DOCKER" ]; then + DOCKER=$(which docker) +fi +if [ -n "$DOCKER" ] && [ ! -x "$DOCKER" ]; then + echo + echo_red "You specified a custom Docker executable via the DOCKER" + echo_red "environment variable at $DOCKER" + echo_red "which either does not exist or is not executable." + echo "Please fix it to point at a working Docker or remove the" + echo "DOCKER environment variable to use the one in your PATH" + echo "if it exists." + echo + exit 1 +fi +if [ -z "$DOCKER" ]; then + echo + echo_red "You do not appear to have docker installed or I can't find it." + echo "Windows and Mac versions can be downloaded from" + echo "https://www.docker.com/products/docker-desktop" + echo "Linux users can install using your package manager." + echo + echo "Please install docker or specify the location of the docker" + echo "executable in the DOCKER environment variable and try again." + echo + exit 1 +fi + +# Check that Docker daemon is running +if ! $DOCKER info >/dev/null 2>&1; then + echo + echo_red "The docker daemon is not running or I can't connect to it." + echo "Please make sure it's running and try again." + echo + exit 1 +fi + +# Disable Docker CLI hints +export DOCKER_CLI_HINTS=false diff --git a/docker/gen-cpanfile-snapshot.sh b/docker/gen-cpanfile-snapshot.sh index 38676b4cc..cbca373d4 100644 --- a/docker/gen-cpanfile-snapshot.sh +++ b/docker/gen-cpanfile-snapshot.sh @@ -6,49 +6,18 @@ # This Source Code Form is "Incompatible With Secondary Licenses", as # defined by the Mozilla Public License, v. 2.0. -if [ -z "$DOCKER" ]; then - DOCKER=`which docker` -fi -if [ ! -x "$DOCKER" ]; then - echo - echo "You specified a custom Docker executable via the DOCKER" - echo "environment variable at $DOCKER" - echo "which either does not exist or is not executable." - echo "Please fix it to point at a working Docker or remove the" - echo "DOCKER environment variable to use the one in your PATH" - echo "if it exists." - echo - exit -1 -fi -if [ -z "$DOCKER" ]; then - echo - echo "You do not appear to have docker installed or I can't find it." - echo "Windows and Mac versions can be downloaded from" - echo "https://www.docker.com/products/docker-desktop" - echo "Linux users can install using your package manager." - echo - echo "Please install docker or specify the location of the docker" - echo "executable in the DOCKER environment variable and try again." - echo - exit -1 -fi -$DOCKER info 1>/dev/null 2>/dev/null -if [ $? != 0 ]; then - echo - echo "The docker daemon is not running or I can't connect to it." - echo "Please make sure it's running and try again." - echo - exit -1 -fi +# Source common Docker script checks and functions +# shellcheck source=docker/common.sh +source "$(dirname "$0")/common.sh" + if [ ! -f "docker/images/Dockerfile.cpanfile" ]; then echo echo "Can't locate the Dockerfile, try running from the root of" echo "your Bugzilla checkout." echo - exit -1 + exit 1 fi -export DOCKER_CLI_HINTS=false $DOCKER build -t bugzilla-cpanfile -f docker/images/Dockerfile.cpanfile . $DOCKER run -it -v "$(pwd):/app/result" bugzilla-cpanfile cp cpanfile cpanfile.snapshot /app/result diff --git a/docker/gen-docker-image.sh b/docker/gen-docker-image.sh index 1268d23d2..314720689 100755 --- a/docker/gen-docker-image.sh +++ b/docker/gen-docker-image.sh @@ -6,49 +6,31 @@ # This Source Code Form is "Incompatible With Secondary Licenses", as # defined by the Mozilla Public License, v. 2.0. -if [ ! -e 'Makefile.PL' ]; then - echo - echo "Please run this from the root of the Bugzilla source tree." - echo - exit -1 -fi -if [ -z "$DOCKER" ]; then - DOCKER=`which docker` -fi -if [ ! -x "$DOCKER" ]; then - echo - echo "You specified a custom Docker executable via the DOCKER" - echo "environment variable at $DOCKER" - echo "which either does not exist or is not executable." - echo "Please fix it to point at a working Docker or remove the" - echo "DOCKER environment variable to use the one in your PATH" - echo "if it exists." - echo - exit -1 -fi -if [ -z "$DOCKER" ]; then - echo - echo "You do not appear to have docker installed or I can't find it." - echo "Windows and Mac versions can be downloaded from" - echo "https://www.docker.com/products/docker-desktop" - echo "Linux users can install using your package manager." - echo - echo "Please install docker or specify the location of the docker" - echo "executable in the DOCKER environment variable and try again." - echo - exit -1 -fi -$DOCKER info 1>/dev/null 2>/dev/null -if [ $? != 0 ]; then - echo - echo "The docker daemon is not running or I can't connect to it." - echo "Please make sure it's running and try again." - echo - exit -1 +# Ensure this script is run with bash +# BASH_VERSION can be set in some shells; instead, verify declare -A works. +if ! (declare -A __test_assoc 2>/dev/null); then + echo "This script requires bash. Checking if you have it..." + bash=$(which bash) + if [ -n "$bash" ] && [ -x "$bash" ]; then + echo "Found bash at $bash. Re-running script with bash..." + echo + exec bash "$0" "$@" + else + echo_red "Could not find bash. Put it in your PATH and try again." + exit 1 + fi fi -FILES=`ls -1 docker/images/Dockerfile.b* | sed -e 's@^docker/images/Dockerfile\.@@'` + +# Source common Docker script checks and functions +# shellcheck source=docker/common.sh +source "$(dirname "$0")/common.sh" + +FILES=() +for f in docker/images/Dockerfile.b*; do + [[ "$f" != *.bak ]] && FILES+=("${f#docker/images/Dockerfile.}") +done PS3="Choose an image to build or CTRL-C to abort: " -select IMAGE in $FILES; do +select IMAGE in "All images" "${FILES[@]}"; do CACHE="" if [ "$1" == "--no-cache" ]; then CACHE="--no-cache" @@ -59,63 +41,124 @@ select IMAGE in $FILES; do export CIRCLE_SHA1="" export CIRCLE_BUILD_URL="" - # Figure out the tag name to use for the image. We'll do this by generating - # a code based on today's date, then attempt to pull it from DockerHub. If - # we successfully pull, then it already exists, and we bump the interation - # number on the end. - DATE=`date +"%Y%m%d"` - ITER=1 - $DOCKER pull bugzilla/${IMAGE}:${DATE}.${ITER} >/dev/null 2>/dev/null - while [ $? == 0 ]; do - # as long as we succesfully pull, keep bumping the number on the end - ((ITER++)) - $DOCKER pull bugzilla/${IMAGE}:${DATE}.${ITER} >/dev/null 2>/dev/null - done - LINE="Building bugzilla/${IMAGE}:${DATE}.${ITER}" - echo "##${LINE//?/#}##" - echo "# ${LINE} #" - echo "##${LINE//?/#}##" - $DOCKER build $CACHE -t bugzilla/${IMAGE}:${DATE}.${ITER} -f docker/images/Dockerfile.${IMAGE} . - if [ $? == 0 ]; then - echo - echo "The build appears to have succeeded. Don't forget to change the FROM line" - echo "at the top of Dockerfile to use:" - echo " bugzilla/${IMAGE}:${DATE}.${ITER}" - echo "to make use of this image." - echo - # check if the user is logged in - if [ -z "$PYTHON" ]; then - PYTHON=`which python` - fi - if [ -z "$PYTHON" ]; then - PYTHON=`which python3` - fi - if [ ! -x "$PYTHON" ]; then - echo "The python executable specified in your PYTHON environment value or your PATH is not executable or I can't find it." - exit -1 - fi - AUTHINFO=`$PYTHON -c "import json; print(len(json.load(open('${HOME}/.docker/config.json','r',encoding='utf-8'))['auths']))"` - if [ $AUTHINFO -gt 0 ]; then - # user is logged in - read -p "Do you wish to push to DockerHub? [y/N]: " yesno - case $yesno in - [Yy]*) - echo "Pushing..." - $DOCKER push bugzilla/${IMAGE}:${DATE}.${ITER} - $DOCKER tag bugzilla/${IMAGE}:${DATE}.${ITER} bugzilla/${IMAGE}:latest - $DOCKER push bugzilla/${IMAGE}:latest - ;; - *) - echo "Not pushing. You can just run this script again when you're ready" - echo "to push. The prior build result is cached." - ;; - esac - fi + # Determine which images to build + if [ "$IMAGE" == "All images" ]; then + IMAGES_TO_BUILD=("${FILES[@]}") else + IMAGES_TO_BUILD=("$IMAGE") + fi + + # Track successfully built images + declare -A BUILT_IMAGES + + for IMAGE in "${IMAGES_TO_BUILD[@]}"; do + # Figure out the tag name to use for the image. We'll do this by generating + # a code based on today's date, then attempt to pull it from DockerHub. If + # we successfully pull, then it already exists, and we bump the interation + # number on the end. + DATE=$(date +"%Y%m%d") + ITER=1 + while $DOCKER pull "bugzilla/${IMAGE}:${DATE}.${ITER}" >/dev/null 2>/dev/null; do + # as long as we succesfully pull, keep bumping the number on the end + ((ITER++)) + done + LINE="Building bugzilla/${IMAGE}:${DATE}.${ITER}" + echo "##${LINE//?/#}##" + echo "# ${LINE} #" + echo "##${LINE//?/#}##" + if $DOCKER build $CACHE -t "bugzilla/${IMAGE}:${DATE}.${ITER}" -f "docker/images/Dockerfile.${IMAGE}" .; then + echo + echo_green "The build appears to have succeeded." + + # Only update Dockerfiles when building the perl-slim image specifically (not variants like perl-slim-mysql) + if [[ "$IMAGE" == "bugzilla-perl-slim" ]]; then + echo "Updating FROM lines in Dockerfiles to use bugzilla/${IMAGE}:${DATE}.${ITER}..." + echo + + # Update all Dockerfiles that reference this image + for dockerfile in Dockerfile docker/images/Dockerfile.*; do + # Skip backups and temp files + case "$dockerfile" in + *.bak|*.tmp) continue ;; + esac + if [ -f "$dockerfile" ]; then + # Check for both direct references and BZDB variable references + if grep -q "FROM bugzilla/${IMAGE}:" "$dockerfile" || grep -q "FROM bugzilla/${IMAGE}\${BZDB}:" "$dockerfile"; then + # Create a backup + cp "$dockerfile" "${dockerfile}.bak" + echo " Created backup: ${dockerfile}.bak" + # Update the FROM line - handle both direct and BZDB variable patterns + sed -i.tmp "s|FROM bugzilla/${IMAGE}:[^ ]*|FROM bugzilla/${IMAGE}:${DATE}.${ITER}|g" "$dockerfile" + sed -i.tmp "s|FROM bugzilla/${IMAGE}\${BZDB}:[^ ]*|FROM bugzilla/${IMAGE}\${BZDB}:${DATE}.${ITER}|g" "$dockerfile" + rm -f "${dockerfile}.tmp" + echo " Updated: $dockerfile" + fi + fi + done + echo + fi + + # Track the successfully built image + BUILT_IMAGES["${IMAGE}"]="${DATE}.${ITER}" + else + echo + echo_red "Docker build failed for ${IMAGE}. See output above." + echo + if [ ${#IMAGES_TO_BUILD[@]} -eq 1 ]; then + exit 1 + fi + fi + done + + # Check if any images were built successfully + if [ ${#BUILT_IMAGES[@]} -eq 0 ]; then + echo_red "No images were built successfully." + exit 1 + fi + echo + echo_green "Successfully built ${#BUILT_IMAGES[@]} image(s):" + for img in "${!BUILT_IMAGES[@]}"; do + echo " - bugzilla/${img}:${BUILT_IMAGES[$img]}" + done + + # check if the user is logged in + if [ -z "$PYTHON" ]; then + PYTHON=$(which python) + fi + if [ -z "$PYTHON" ]; then + PYTHON=$(which python3) + fi + if [ ! -x "$PYTHON" ]; then + echo "The python executable specified in your PYTHON environment value or your PATH is not executable or I can't find it." + exit 1 + fi + AUTHINFO=$($PYTHON -c "import json; print(len(json.load(open('${HOME}/.docker/config.json','r',encoding='utf-8'))['auths']))") + if [ "$AUTHINFO" -gt 0 ]; then + # user is logged in echo - echo "Docker build failed. See output above." - echo - exit -1 + read -rp "Do you wish to push to DockerHub? [y/N]: " yesno + case $yesno in + [Yy]*) + echo + echo "Pushing images..." + for img in "${!BUILT_IMAGES[@]}"; do + tag="${BUILT_IMAGES[$img]}" + echo "Pushing bugzilla/${img}:${tag}..." + $DOCKER push "bugzilla/${img}:${tag}" + echo "Tagging bugzilla/${img}:${tag} as bugzilla/${img}:latest..." + $DOCKER tag "bugzilla/${img}:${tag}" "bugzilla/${img}:latest" + $DOCKER push "bugzilla/${img}:latest" + done + echo_green "All images pushed successfully." + ;; + *) + echo + echo "Not pushing. You can just run this script again when you're ready" + echo "to push. The prior build results are cached." + echo_red "Remember DO NOT commit any changes to the FROM lines of Dockerfiles until" + echo_red "you've pushed to DockerHub. Doing so will break tests on GitHub Actions." + ;; + esac fi break done diff --git a/docker/images/Dockerfile.bugzilla-perl-slim b/docker/images/Dockerfile.bugzilla-perl-slim index bd4258ed0..d9d0692c1 100644 --- a/docker/images/Dockerfile.bugzilla-perl-slim +++ b/docker/images/Dockerfile.bugzilla-perl-slim @@ -43,7 +43,7 @@ RUN find local -name '*.so' -exec ldd {} \; \ FROM perl:5.38.2-slim -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive COPY --from=builder /app/local /app/local COPY --from=builder /app/PACKAGES /app/PACKAGES diff --git a/docker/images/Dockerfile.bugzilla-perl-slim-mariadb b/docker/images/Dockerfile.bugzilla-perl-slim-mariadb index d5acd77fe..d4b7e6642 100644 --- a/docker/images/Dockerfile.bugzilla-perl-slim-mariadb +++ b/docker/images/Dockerfile.bugzilla-perl-slim-mariadb @@ -40,7 +40,7 @@ RUN find local -name '*.so' -exec ldd {} \; \ FROM bugzilla/bugzilla-perl-slim:20250925.1 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive COPY --from=builder /app/local /app/local COPY --from=builder /app/PACKAGES /app/PACKAGES diff --git a/docker/images/Dockerfile.bugzilla-perl-slim-mysql b/docker/images/Dockerfile.bugzilla-perl-slim-mysql index a807fca41..64562cec7 100644 --- a/docker/images/Dockerfile.bugzilla-perl-slim-mysql +++ b/docker/images/Dockerfile.bugzilla-perl-slim-mysql @@ -50,7 +50,7 @@ RUN find local -name '*.so' -exec ldd {} \; \ FROM bugzilla/bugzilla-perl-slim:20250925.1 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive COPY --from=builder /app/local /app/local COPY --from=builder /app/PACKAGES /app/PACKAGES diff --git a/docker/images/Dockerfile.bugzilla-perl-slim-pg b/docker/images/Dockerfile.bugzilla-perl-slim-pg index d2fe4b575..3601a0d4e 100644 --- a/docker/images/Dockerfile.bugzilla-perl-slim-pg +++ b/docker/images/Dockerfile.bugzilla-perl-slim-pg @@ -51,7 +51,7 @@ RUN find local -name '*.so' -exec ldd {} \; \ # developer tools FROM bugzilla/bugzilla-perl-slim:20250925.1 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive # copy the stuff we built over from the temporary image COPY --from=builder /app/local /app/local diff --git a/docker/images/Dockerfile.perl-testsuite b/docker/images/Dockerfile.perl-testsuite new file mode 100644 index 000000000..a3b2b2964 --- /dev/null +++ b/docker/images/Dockerfile.perl-testsuite @@ -0,0 +1,46 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +ARG BZDB="" +FROM bugzilla/bugzilla-perl-slim${BZDB}:20250925.1 + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get -y dist-upgrade && \ + apt-get install --ignore-hold --allow-downgrades -y \ + apache2 \ + cpanminus \ + mariadb-client \ + netcat-traditional \ + build-essential \ + libapache2-mod-perl2 \ + libapache2-mod-perl2-dev \ + libgd3 \ + libgd-dev \ + perlmagick \ + graphviz \ + curl libssl-dev zlib1g-dev openssl \ + libexpat-dev cmake git libcairo-dev \ + unzip wget && \ + rm -rf /var/lib/apt/lists/* + +# Copy the source code +COPY . /app/ + +# Run Makefile.PL and install dependencies +RUN perl Makefile.PL && \ + cpanm --notest --quiet --local-lib="/app/local" Module::CPANfile && \ + make cpanfile GEN_CPANFILE_ARGS='-A -U oracle -U mariadb -U pg -U mysql' && \ + cpanm --notest --quiet --local-lib="/app/local" -f --installdeps . + +# Run checksetup +RUN perl checksetup.pl --no-database --default-localconfig --no-templates + +# Set the default command to run tests +ENTRYPOINT ["prove", "-Ilocal/lib/perl5", "t"] +CMD [] diff --git a/docker/run-tests-in-docker.sh b/docker/run-tests-in-docker.sh index 592878f41..1b3d5f219 100644 --- a/docker/run-tests-in-docker.sh +++ b/docker/run-tests-in-docker.sh @@ -6,63 +6,65 @@ # This Source Code Form is "Incompatible With Secondary Licenses", as # defined by the Mozilla Public License, v. 2.0. -if [ ! -e 'Makefile.PL' ]; then - echo - echo "Please run this from the root of the Bugzilla source tree." - echo - exit -1 -fi -if [ -z "$DOCKER" ]; then - DOCKER=`which docker` -fi -if [ ! -x "$DOCKER" ]; then - echo - echo "You specified a custom Docker executable via the DOCKER" - echo "environment variable at $DOCKER" - echo "which either does not exist or is not executable." - echo "Please fix it to point at a working Docker or remove the" - echo "DOCKER environment variable to use the one in your PATH" - echo "if it exists." - echo - exit -1 -fi -if [ -z "$DOCKER" ]; then - echo - echo "You do not appear to have docker installed or I can't find it." - echo "Windows and Mac versions can be downloaded from" - echo "https://www.docker.com/products/docker-desktop" - echo "Linux users can install using your package manager." - echo - echo "Please install docker or specify the location of the docker" - echo "executable in the DOCKER environment variable and try again." - echo - exit -1 -fi -$DOCKER info 1>/dev/null 2>/dev/null -if [ $? != 0 ]; then - echo - echo "The docker daemon is not running or I can't connect to it." - echo "Please make sure it's running and try again." - echo - exit -1 -fi +# Source common Docker script checks and functions +# shellcheck source=docker/common.sh +source "$(dirname "$0")/common.sh" -export DOCKER_CLI_HINTS=false export CI="" export CIRCLE_SHA1="" export CIRCLE_BUILD_URL="" -DOCKER_COMPOSE_FILE=docker-compose.test.yml -if [ "$1" == "pg" ]; then + +TEST_NAME="test_bmo" +DOCKER_COMPOSE_FILE=docker-compose.test-mysql.yml +if [ "$#" -eq 0 ]; then + echo "Available test options:" + echo " 1) sanity - Run sanity tests" + echo " 2) mysql - Run BMO tests with MySQL (default)" + echo " 3) pg - Run BMO tests with PostgreSQL" + echo " 4) sqlite - Run BMO tests with SQLite" + echo " 5) mariadb - Run BMO tests with MariaDB" + echo " 6) release - Run release tests" + echo + read -rp "Select a test option (1-6, default is mysql): " choice + case "$choice" in + 1) set -- "sanity" ;; + 2|"") set -- "mysql" ;; + 3) set -- "pg" ;; + 4) set -- "sqlite" ;; + 5) set -- "mariadb" ;; + 6) set -- "release" ;; + *) echo "Invalid choice. Using default (mysql)"; set -- "mysql" ;; + esac +fi +if [ "$1" == "sanity" ]; then + DOCKER_COMPOSE_FILE=docker-compose.test-mysql.yml + TEST_NAME="test_sanity" +elif [ "$1" == "mysql" ]; then + DOCKER_COMPOSE_FILE=docker-compose.test-mysql.yml +elif [ "$1" == "pg" ]; then DOCKER_COMPOSE_FILE=docker-compose.test-pg.yml elif [ "$1" == "sqlite" ]; then DOCKER_COMPOSE_FILE=docker-compose.test-sqlite.yml elif [ "$1" == "mariadb" ]; then DOCKER_COMPOSE_FILE=docker-compose.test-mariadb.yml +elif [ "$1" == "release" ]; then + DOCKER_FILE=docker/images/Dockerfile.perl-testsuite + if $DOCKER build -t bugzilla-release-test -f "$DOCKER_FILE" .; then + $DOCKER run --rm bugzilla-release-test + else + echo "docker build failed." + fi + exit $? fi -$DOCKER compose -f $DOCKER_COMPOSE_FILE build -if [ $? == 0 ]; then - $DOCKER compose -f $DOCKER_COMPOSE_FILE run --rm --name bugzilla6.test bugzilla6.test test_bmo -q -f t/bmo/*.t - $DOCKER compose -f $DOCKER_COMPOSE_FILE down +if $DOCKER compose -f "$DOCKER_COMPOSE_FILE" build; then + if $DOCKER compose -f "$DOCKER_COMPOSE_FILE" run --rm --name bugzilla6.test bugzilla6.test "$TEST_NAME" -q -f t/bmo/*.t; then + $DOCKER compose -f "$DOCKER_COMPOSE_FILE" down + else + echo "docker compose run failed." + $DOCKER compose -f "$DOCKER_COMPOSE_FILE" down + exit 1 + fi else echo "docker compose build failed." + exit 1 fi