Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Build version
BUILD_VERSION=v0.1.12
BUILD_VERSION=v0.1.13

# Moodle version
MOODLE_VERSION=3.5.2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v0.1.13] - 2018-10-26
### Added
- Add dc.theme-dev.yml file to expose containers theme files
- Add run.sh script to start and stop Docker containers

## [v0.1.12] - 2018-10-23
### Changed
- Fix `.gitignore` pattern
Expand Down
19 changes: 19 additions & 0 deletions dc.theme-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file contains configuration for theme development
---

version: '3.6'

services:
nginx-php-moodle:
volumes:
- type: volume
source: theme
target: /opt/moodle/app/theme

volumes:
theme:
driver: local
driver_opts:
type: none
o: bind
device: /opt/moodle/theme/
176 changes: 176 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/bin/bash

set -e

VERSION='0.1'

DOCKER_COMPOSE=$(which docker-compose)
BASE_COMPOSE='/etc/moodle-docker/docker-compose.yml'
THEME_COMPOSE='/etc/moodle-docker/dc.theme-dev.yml'
BASE_COMMAND="${DOCKER_COMPOSE} --file ${BASE_COMPOSE}"

THEME_DIR='/opt/moodle/theme'

# Print usage and argument list
function print_usage {
cat << EOF
usage: ${0} options

This script will create an organization and update the associated DNS record.

OPTIONS:
Actions:
clean
down
stop
restart
up
version, -v, --version Print ${0} version and exit

Parameters:
-d Detach from running docker-compose containers
-t Mount theme directory to host for theme development

Examples:
"${0} start -d -t" Start Moodle in detached mode with theme directory mounted to host.

Version: ${VERSION}
EOF
}

function ensure_theme_dir {
if [ ! -d "${THEME_DIR}" ] ; then
echo "Theme directory not found, creating ${THEME_DIR}"
mkdir -p "${THEME_DIR}"
fi
}

function clean_moodle {
local compose_command="${BASE_COMMAND}"

if [ "${THEME_DEV}" == 'True' ] ; then
compose_command="${compose_command} --file ${THEME_COMPOSE}"
fi
compose_command="${compose_command} rm"

eval "${compose_command}"
}

function down_moodle {
local compose_command="${BASE_COMMAND}"

if [ "${THEME_DEV}" == 'True' ] ; then
compose_command="${compose_command} --file ${THEME_COMPOSE}"
fi
compose_command="${compose_command} down"

eval "${compose_command}"
}

function stop_moodle {
local compose_command="${BASE_COMMAND}"

if [ "${THEME_DEV}" == 'True' ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably abstract out this if block into a function and reuse it the other places with the same code

compose_command="${compose_command} --file ${THEME_COMPOSE}"
fi
compose_command="${compose_command} stop"

eval "${compose_command}"
}

function restart_moodle {
local compose_command="${BASE_COMMAND}"

if [ "${THEME_DEV}" == 'True' ] ; then
ensure_theme_dir
compose_command="${compose_command} --file ${THEME_COMPOSE}"
fi
compose_command="${compose_command} restart"

eval "${compose_command}"
}

function up_moodle {
local compose_command="${BASE_COMMAND}"

if [ "${THEME_DEV}" == 'True' ] ; then
ensure_theme_dir
compose_command="${compose_command} --file ${THEME_COMPOSE}"
fi
compose_command="${compose_command} up"

if [ "${DETACH}" == 'True' ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment about true/false

compose_command="${compose_command} --detach"
fi

eval "${compose_command}"
}

subcommand="${1:-}"
shift

while getopts ":dt" opt; do
case ${opt} in
'd') DETACH='True' ;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these true or false and use the builtin booleans

't') THEME_DEV='True' ;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other boolean variable

'?')
color_echo red "Invalid option: -${OPTARG}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you load shtdlib?

print_usage
exit 0
;;
':')
color_echo red "Missing option argument for -${OPTARG}"
print_usage
exit 0
;;
'*') # Anything else
color_echo red "Unknown error while processing options"
print_usage
exit 1
;;
esac
done

# Run the right subcommand
case "${subcommand}" in
'start'|'up')
up_moodle

exit 0
;;
'stop')
stop_moodle

exit 0
;;
'restart')
restart_moodle

exit 0
;;
'down')
down_moodle

exit 0
;;
'clean')
clean_moodle

exit 0
;;
'help'|'--help'|'-h') # Help
print_usage
exit 0
;;
'version'|'--version'|'-v') # Version
color_echo green "Version: ${VERSION}"
exit 0
;;
*) # Invalid subcommand
color_echo red "Invalid subcommand \"${subcommand}\""
print_usage
exit 64
;;
esac