Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pc-magas committed Jan 11, 2024
2 parents f8cfaaa + beb0979 commit b31813d
Show file tree
Hide file tree
Showing 36 changed files with 1,015 additions and 1,318 deletions.
137 changes: 101 additions & 36 deletions .github/build_docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#!/bin/bash
#!/bin/bash -e

#############################################################################
# THIS SCRIPT, FOR A SUCCESSFULL RUN, REQUIRES THESE ENVIRONMENTAL VARIABLES:
#
# VERSION : The moodle version without dots eg for moodle 4.3 use 403
# PHP_VERSION : For the PHP version to use.
# DRY_RUN : If set as 1 will not build the docker images it will just print the build arguments
# CACHE_ENABLE : If set 1 it builds the docker images without --no-cache
#
# Also a single argument must be provided for the dockerfile:
#
# dockerfiles/fpm_alpine/Dockerfile : for fpm using alpine
# dockerfiles/fpm/Dockerfile : for debian based fpm
# dockerfiles/fpm_alpine/Dockerfile: for apache
#
# If not provided is it assumes as an apache image
# ###########################################################################


# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "${BASH_SOURCE}")
Expand All @@ -13,33 +31,37 @@ if [ "$PHP_VERSION" == "${DEFAULT_PHP}" ]; then
echo "$PHP_VERSION is same to ${DEFAULT_PHP}"
fi

DOCKERFILE_ALPINE_FPM="dockerfiles/fpm_alpine/Dockerfile"
SERVER_FAVOR="apache"

DOCKERFILE=${1}

case $DOCKERFILE in
"dockerfiles/fpm_alpine/Dockerfile") SERVER_FAVOR="fpm_alpine";;
"dockerfiles/fpm/Dockerfile") SERVER_FAVOR="fpm";;
*) SERVER_FAVOR="apache";;
*) DOCKERFILE="dockerfiles/apache/Dockerfile"; SERVER_FAVOR="apache";;
esac

DB_FLAVOR=""
BUILD_NUMBER=$(date +"%Y%m%d%H%M")
DB_FLAVORS=("mysql_maria" "postgresql" "multibase")

case $DB_TYPE in
"mysqli" ) DB_FLAVOR="mysql_maria" ;;
"pgsql" ) DB_FLAVOR="postgresql";;
*) DB_FLAVOR="mulitibase"
esac
BUILD_NUMBER=$(date +"%Y%m%d%H%M")

TAGS=()
# Aggregates all available tags
FINAL_TAGS=()

COMMON="${DB_FLAVOR}_${SERVER_FAVOR}_${VERSION}"
COMMON_PHP_VERSION="${COMMON}_php${PHP_VERSION}"
MULTIBASE_PARAMS=()
POSTGRES_PARAMS=()
MYSQL_PARAMS=()

function generateTags(){
local TAG=${1}

local TAG=${2}
local DB_FLAVOR=${1}

# VERSION is env variable, and indicates the moodle version we build upon
local COMMON_WITHOUT_VERSION="${DB_FLAVOR}_${SERVER_FAVOR}"
local COMMON="${COMMON_WITHOUT_VERSION}_${VERSION}"
local COMMON_PHP_VERSION="${COMMON}_php${PHP_VERSION}"

#trim
TAG=$TAG

Expand All @@ -49,48 +71,91 @@ function generateTags(){

if [ "$PHP_VERSION" == "${DEFAULT_PHP}" ]; then
VERSIONS+=( "${COMMON}${TAG}" "${COMMON}${TAG}_${BUILD_NUMBER}")

# Check is done outside the function
if [[ "$TAG" == '_latest' ]] || [[ "$TAG" == '_lts' ]] ; then
VERSIONS+=("${COMMON_WITHOUT_VERSION}${TAG}" "${COMMON_WITHOUT_VERSION}_${BUILD_NUMBER}${TAG}")
fi
fi


echo ${VERSIONS[*]}

}

TAGS+=( $(generateTags) )
# Pulling extention installer
docker pull mlocati/php-extension-installer

if [[ $VERSION == $LATEST_LTS ]]; then
TAGS+=( $(generateTags lts) )
fi
for DB_FLAVOR in ${DB_FLAVORS[@]}; do

if [[ $VERSION == $LATEST ]]; then
TAGS+=( $(generateTags latest ) )
TAGS+=( $(generateTags ${SERVER_FAVOR} ))
echo "GENERATING TAGS for ${DB_FLAVOR} and ${SERVER_FAVOR}"

if [ "$PHP_VERSION" == "${DEFAULT_PHP}" ]; then
TAGS+=("${DB_FLAVOR}_${SERVER_FAVOR}_${BUILD_NUMBER}")
TAGS=( $(generateTags $DB_FLAVOR) )

if [[ $VERSION == $LATEST_LTS ]]; then
TAGS+=( $(generateTags $DB_FLAVOR lts) )
fi

TAGS+=("${DB_FLAVOR}_${SERVER_FAVOR}_php${PHP_VERSION}_${BUILD_NUMBER}")

if [[ $SERVER_FAVOR == "apache" ]] && [[ $DB_FLAVOR = "mulitbase" ]]; then
if [ $PHP_VERSION==${DEFAULT_PHP} ];then
TAGS+=("latest" "latest_${BUILD_NUMBER}")
if [[ $VERSION == $LATEST ]]; then
TAGS+=( $(generateTags ${DB_FLAVOR} latest ) )
TAGS+=( $(generateTags ${DB_FLAVOR} ${SERVER_FAVOR} ))

TAGS+=("${DB_FLAVOR}_${SERVER_FAVOR}_php${PHP_VERSION}_${BUILD_NUMBER}")

if [[ $SERVER_FAVOR == "apache" ]] && [[ $DB_FLAVOR = "multibase" ]]; then
if [ $PHP_VERSION==${DEFAULT_PHP} ];then
TAGS+=("latest" "latest_${BUILD_NUMBER}")
fi

TAGS+=("latest_php${PHP_VERSION}" "latest_php${PHP_VERSION}_${BUILD_NUMBER}")
fi

TAGS+=("latest_php${PHP_VERSION}" "latest_php${PHP_VERSION}_${BUILD_NUMBER}")

fi

PARAMS=${TAGS[@]/#/"-t ellakcy/moodle:"}

case $DB_FLAVOR in
"mysql_maria" ) MYSQL_PARAMS=$PARAMS ;;
"postgresql" ) POSTGRES_PARAMS=$PARAMS;;
*) MULTIBASE_PARAMS=$PARAMS
esac

FINAL_TAGS+=($TAGS)
done

if [ "$DRY_RUN" == "1" ]; then

echo "DRY RUN MODE NO IMAGES ARE BUILT"
echo "# MYSQL #" > ./debug.txt
echo ${MYSQL_PARAMS} >> ./debug.txt
echo "# POSTGRES #" >> ./debug.txt
echo ${POSTGRES_PARAMS} >> ./debug.txt
echo "# MULTIBASE #" >> ./debug.txt
echo ${MULTIBASE_PARAMS} >> ./debug.txt

sed -i 's/\s*-t\s*/\n/g' ./debug.txt

cat ./debug.txt

exit 0;
fi

PARAMS=${TAGS[@]/#/"-t ellakcy/moodle:"}
CACHE_ARG="--no-cache"

echo "Running:"
echo "docker build --build-arg DB_TYPE=${DB_TYPE} -f ${DOCKERFILE} ${PARAMS} --force-rm . "
if [ "$CACHE_ENABLE" == "1" ]; then
CACHE_ARG=""
fi

DOCKER_BUILDKIT=1 docker build --target multibase ${CACHE_ARG} --pull --build-arg PHP_VERSION=${PHP_VERSION} --build-arg VERSION=${VERSION} -f ${DOCKERFILE} ${MULTIBASE_PARAMS} .
DOCKER_BUILDKIT=1 docker build --target postgres --build-arg CACHEBUST=${BUILD_NUMBER} --build-arg PHP_VERSION=${PHP_VERSION} --build-arg VERSION=${VERSION} -f ${DOCKERFILE} ${POSTGRES_PARAMS} .
DOCKER_BUILDKIT=1 docker build --target mysql_maria --build-arg CACHEBUST=${BUILD_NUMBER} --build-arg PHP_VERSION=${PHP_VERSION} --build-arg VERSION=${VERSION} -f ${DOCKERFILE} ${MYSQL_PARAMS} .

docker build --pull --build-arg PHP_VERSION=${PHP_VERSION} --build-arg DB_TYPE=${DB_TYPE} --build-arg VERSION=${VERSION} -f ${DOCKERFILE} ${PARAMS} --force-rm --no-cache .

BRANCH=${GITHUB_REF##*/}

if [[ $BRANCH == 'master' ]]; then
for tag in "${TAGS[@]}"; do
for tag in "${FINAL_TAGS[@]}"; do
docker image push ellakcy/moodle:$tag
done

fi
fi
4 changes: 2 additions & 2 deletions .github/config.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LATEST=402
LATEST=403
LATEST_LTS=401
DEFAULT_PHP="7.4"
DEFAULT_PHP="8.0"
23 changes: 19 additions & 4 deletions .github/workflows/deploy-alpine-fpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
moodle_version: [39,311,400,401,402]
database: ['all','mysqli','pgsql']
moodle_version: [311,400,401,402,403]
php_version: ['7.4','8.0','8.1','8.2']
exclude:
- moodle_version: 311
php_version: '8.1'
- moodle_version: 311
php_version: '8.2'
- moodle_version: 400
php_version: 8.1
- moodle_version: 401
php_version: '8.2'
- moodle_version: 402
php_version: '7.4'
- moodle_version: 402
php_version: '8.2'
- moodle_version: 403
php_version: '7.4'
env:
VERSION: ${{ matrix.moodle_version }}
DB_TYPE: ${{ matrix.database }}
PHP_VERSION: "${{ matrix.php_version }}"
steps:
- name: Check Out Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Login to Docker Hub
if: github.ref != 'refs/heads/dev'
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/deploy-apache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
moodle_version: [39,311,400,401,402]
database: ['all','mysqli','pgsql']
moodle_version: [311,400,401,402,403]
php_version: ['7.4','8.0','8.1','8.2']
exclude:
- moodle_version: 311
php_version: '8.1'
- moodle_version: 311
php_version: '8.2'
- moodle_version: 400
php_version: 8.1
- moodle_version: 401
php_version: '8.2'
- moodle_version: 402
php_version: '7.4'
- moodle_version: 402
php_version: '8.2'
- moodle_version: 403
php_version: '7.4'
env:
VERSION: ${{ matrix.moodle_version }}
DB_TYPE: ${{ matrix.database }}
PHP_VERSION: "${{ matrix.php_version }}"
steps:
- name: Check Out Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Login to Docker Hub
if: github.ref != 'refs/heads/dev'
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/deploy-fpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
moodle_version: [39,311,400,401,402]
database: ['all','mysqli','pgsql']
moodle_version: [311,400,401,402,403]
php_version: ['7.4','8.0','8.1','8.2']
exclude:
- moodle_version: 311
php_version: '8.1'
- moodle_version: 311
php_version: '8.2'
- moodle_version: 400
php_version: 8.1
- moodle_version: 401
php_version: '8.2'
- moodle_version: 402
php_version: '7.4'
- moodle_version: 402
php_version: '8.2'
- moodle_version: 403
php_version: '7.4'
env:
VERSION: ${{ matrix.moodle_version }}
DB_TYPE: ${{ matrix.database }}
PHP_VERSION: "${{ matrix.php_version }}"
steps:
- name: Check Out Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Login to Docker Hub
if: github.ref != 'refs/heads/dev'
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/php_80.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/php_80_alpine_fpm.yml

This file was deleted.

Loading

0 comments on commit b31813d

Please sign in to comment.