Commit 7bfda980 authored by Fergus Whyte's avatar Fergus Whyte Committed by Robert Lyon
Browse files

Bug 1955620: Adding options for development in PHP 7.4, 8, and 8.1 for Docker setup

tl;dr;

* Focal added for PHP7.4
* XDebug working in Focal
* Jammy added for PHP8.1

---

Added Focal for PHP 7.4.  This is the minimum version of PHP needed for
Behat tests.

To use Focal set DOCKER_PHP_MAJOR_VERSION in the shell you are working
in.

export DOCKER_PHP_MAJOR_VERSION=7.4

XDebug is now available for Focal on port 9000. For VSCode configure
your launch.json file with path mapping set to the path inside the
container.

i.e.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug in Docker",
      "type": "php",
      "request": "launch",
      "port": 9000,
      "pathMappings": {
          "/mahara/": "${workspaceFolder}/",
       },
       "log": true
    }
  ]
}

XDebug is also working for scripts running on the CLI inside
the container.

Added Jammy for PHP 8.1.  This is the minimum version of PHP needed for
Behat tests.

To use Focal set DOCKER_PHP_MAJOR_VERSION in the shell you are working
in.

export DOCKER_PHP_MAJOR_VERSION=8.1

Change-Id: Ibd79677ce8ad6a9e9837a6f6049ad36e03fa248b
parent d1ac5e2f
Loading
Loading
Loading
Loading
+41 −9
Original line number Diff line number Diff line
@@ -5,12 +5,26 @@ BEHAT_TESTS = null
# ask for test reports to be generated possible values are <empty>, 'html', 'junit'
BEHAT_REPORT =
# The Ubuntu version that the Mahara base image will be based on
DOCKER_UBUNTU_VERSION = bionic
TEST_ADMIN_PASSWD = Kupuh1pa!
TEST_ADMIN_EMAIL  = user@example.org
DOCKER_PHP_MAJOR_VERSION ?=7
ifeq "$(strip $(DOCKER_PHP_MAJOR_VERSION))" "8.1"
DOCKER_UBUNTU_VERSION := jammy
COMPOSE_PROJECT_NAME := $(shell basename $$(pwd))-81
else ifeq  "$(strip $(DOCKER_PHP_MAJOR_VERSION))" "8"
DOCKER_UBUNTU_VERSION := impish
COMPOSE_PROJECT_NAME := $(shell basename $$(pwd))-8
else ifeq "$(strip $(DOCKER_PHP_MAJOR_VERSION))" "7.4"
DOCKER_UBUNTU_VERSION := focal
COMPOSE_PROJECT_NAME := $(shell basename $$(pwd))-74
else
DOCKER_UBUNTU_VERSION := bionic
COMPOSE_PROJECT_NAME := $(shell basename $$(pwd))
endif

export DOCKER_UBUNTU_VERSION
# Export these so they are available in the docker-compose calls later.
export COMPOSE_PROJECT_NAME = $(shell basename $$(pwd))
export COMPOSE_PROJECT_NAME
export MAHARA_DB_HOST = ${COMPOSE_PROJECT_NAME}-mahara-db
export MAHARA_REDIS_SERVER = ${COMPOSE_PROJECT_NAME}-mahara-redis
export MAHARA_DOCKER_PORT = 6142
@@ -28,7 +42,8 @@ CCEND=$(shell echo "\033[0m")
# Refer to: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: css clean-css help imageoptim installcomposer initcomposer cleanssphp ssphp \
		cleanpdfexport pdfexport install phpunit behat minaccept jenkinsaccept securitycheck \
		push security docker-image docker-builder
		push security docker-image docker-images docker-builder reload hard-reload \
		docker-bash docker-bash-root

all: css

@@ -229,21 +244,24 @@ security: minaccept
	ssh $(sshargs) gerrit set-reviewers --add \"Mahara Security Managers\" -- $(sha1chain)

# Builds Mahara server docker image
docker-images: docker-image
docker-image:
	$(info Preparing images)
	docker build --pull --file docker/Dockerfile.mahara-base \
	$(info Preparing images for $(DOCKER_UBUNTU_VERSION))
	docker build --pull --file docker/Dockerfile.mahara-base-$(DOCKER_UBUNTU_VERSION) \
	  --build-arg BASE_VERSION=$(DOCKER_UBUNTU_VERSION) \
		--no-cache \
		--tag mahara-base:$(DOCKER_UBUNTU_VERSION) .
	docker build --file docker/Dockerfile.mahara-web \
	docker build --file docker/Dockerfile.mahara-web-$(DOCKER_UBUNTU_VERSION) \
	  --build-arg BASE_IMAGE=mahara-base:$(DOCKER_UBUNTU_VERSION) \
	  --tag mahara .
		--no-cache \
	  --tag mahara:$(DOCKER_UBUNTU_VERSION) .

# Builds a docker image that is able to build Mahara. Useful if you don't want
# to install dependencies on your system.
# The builder is made for the user that will use it. This is so that the built
# files are owned by the user and not some other user (eg not root)
docker-builder:
	docker build --pull --file docker/Dockerfile.mahara-base \
	docker build --pull --file docker/Dockerfile.mahara-base-$(DOCKER_UBUNTU_VERSION) \
	  --build-arg BASE_VERSION=$(DOCKER_UBUNTU_VERSION) \
		--tag mahara-base:$(DOCKER_UBUNTU_VERSION) .
	docker build --file docker/Dockerfile.mahara-builder \
@@ -282,13 +300,20 @@ endif
ifeq (,$(wildcard ./docker/.env))
	cp ./docker/.env-dist ./docker/.env
endif
	$(info Docker php version: ${DOCKER_PHP_MAJOR_VERSION})
	$(MAKE) shared-up
	$(MAKE) dev-up
	$(MAKE) css

# Reload a single development instance.
reload: down up

# Dev reload - shut it down, rebuild images, bring it back up.
hard-reload: down docker-images up

# Take down a single development instance. See `make shared-down`.
down:
	$(info Shutting down site containers.)
	$(info Shutting down site containers: $(COMPOSE_PROJECT_NAME):$(DOCKER_UBUNTU_VERSION))
	docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.dev.yaml down

# Spins up the shared containers. Has a static project name so that only one
@@ -306,8 +331,15 @@ shared-down:
	$(shell export COMPOSE_PROJECT_NAME=shared-mahara && docker-compose -f docker/docker-compose.shared.yaml down)

docker-bash:
	$(info Docker php version: ${DOCKER_PHP_MAJOR_VERSION})
	$(info Connected as the Webserver user)
	docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.dev.yaml run --user=www-data web /bin/bash

docker-bash-root:
	$(info Docker php version: ${DOCKER_PHP_MAJOR_VERSION})
	$(info Connected as the root user)
	docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.dev.yaml run web /bin/bash

# Brings up a new development instance, that assumes the presense of shared
# mailhog and nginx containers.
dev-up:
+8 −3
Original line number Diff line number Diff line
@@ -29,14 +29,19 @@ MAHARA_SMTP_PORT=1025
#MAHARA_PROBATION_ENABLED=
#MAHARA_SHOW_LOGIN_INSIDE_BLOCK=
#MAHARA_EXTERNAL_LOGIN=
MAHARA_URL_SECRET=
MAHARA_PASSWORD_SALT_MAIN=

# If your development environment is available on any network you should change
# these
MAHARA_URL_SECRET=replaceMe
MAHARA_PASSWORD_SALT_MAIN=replaceMe


#MAHARA_PASSWORD_SALT_ALT1=
MAHARA_SESSION_HANDLER=redis
MAHARA_REDIS_SERVER=mahara-redis
#MAHARA_REDIS_SENTINEL_SERVERS=
#MAHARA_REDIS_MASTER_GROUP=
#MAHARA_REDIS_PREFIX=
MAHARA_REDIS_PREFIX=mahara
#MAHARA_ELASTICSEARCH_HOST=
#MAHARA_ELASTICSEARCH_PORT=
#MAHARA_ELASTICSEARCH_SCHEME=
+4 −3
Original line number Diff line number Diff line
# Base Mahara image containing packages that are needed to build/test and
# run a Mahara instance
ARG BASE_UBUNTU=docker.catalyst.net.nz/catalyst/ubuntu:bionic
ARG BASE_UBUNTU=ubuntu:bionic
FROM ${BASE_UBUNTU}

# enviroment variable as non interactive
@@ -24,7 +24,8 @@ RUN apt-get update && \
        php-redis \
        php-xmlrpc \
        php-zip \
        php-xml
        php-xml \
        curl

RUN mkdir -p /mahara/data && \
    chmod 777 /mahara/data
+52 −0
Original line number Diff line number Diff line
# Base Mahara image containing packages that are needed to build/test and
# run a Mahara instance
ARG BASE_UBUNTU=ubuntu:focal
FROM ${BASE_UBUNTU}

# enviroment variable as non interactive
ARG DEBIAN_FRONTEND=noninteractive

# update packages

# RUN apt-get update && \
#     apt-get install -y \
#         curl \
#         gnupg2

# Google Chrome stable for Behat headless testing
# RUN curl -s https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
#     echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main'>> /etc/apt/sources.list.d/google-chrome.list && \
#     apt-get update && \
#     apt-get install -y \
#         google-chrome-stable

# Chromium is used for pdf exports and for behat tests
RUN apt-get update && \
    apt-get install -y \
        ca-certificates \
        chromium-browser \
        php-cli \
        php-curl \
        php-dom \
        php-gd \
        php-intl \
        php-json \
        php-ldap \
        php-mbstring \
        php-pgsql \
        php-redis \
        php-xmlrpc \
        php-zip \
        php-xml \
        php-xdebug \
        openjdk-8-jre-headless \
        curl \
        lsof

COPY docker/web/etc/php/7.4/apache2/conf.d/20-xdebug.ini /etc/php/7.4/apache2/conf.d/20-xdebug.ini
COPY docker/web/etc/php/7.4/cli/conf.d/20-xdebug.ini /etc/php/7.4/cli/conf.d/20-xdebug.ini

RUN mkdir -p /mahara/data && \
    chmod 777 /mahara/data

VOLUME /mahara/data
+34 −0
Original line number Diff line number Diff line
# Base Mahara image containing packages that are needed to build/test and
# run a Mahara instance
ARG BASE_UBUNTU=ubuntu:impish
FROM ${BASE_UBUNTU}

# enviroment variable as non interactive
ARG DEBIAN_FRONTEND=noninteractive

# update packages
# Chromium is used for pdf exports and for behat tests
RUN apt-get update && \
    apt-get install -y \
        ca-certificates \
        chromium-browser \
        php-cli \
        php-curl \
        php-dom \
        php-gd \
        php-intl \
        php-json \
        php-ldap \
        php-mbstring \
        php-pgsql \
        php-redis \
        php-zip \
        php-xml \
        curl \
        openjdk-8-jre-headless \
        lsof

RUN mkdir -p /mahara/data && \
    chmod 777 /mahara/data

VOLUME /mahara/data
Loading