From 2614c5d70c748fd7702b8b7595ea9d476823ae57 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Mon, 22 Oct 2018 15:06:02 -0400 Subject: [PATCH 1/5] Add volume to expose theme files to host --- dc.theme-dev.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 dc.theme-dev.yml diff --git a/dc.theme-dev.yml b/dc.theme-dev.yml new file mode 100644 index 0000000..136b349 --- /dev/null +++ b/dc.theme-dev.yml @@ -0,0 +1,19 @@ +# This file contains configuration for theme development +--- + +version: '3.6' + +services: + nginx-php-moodle: + volumes: + - type: volume + source: theme-bind + target: /opt/moodle/moodle-3.5.1/theme + +volumes: + theme-bind: + driver: local + driver_opts: + type: none + o: bind + device: /opt/moodle/theme/ From 7661c8253441df56605bc259c03b8208ef5ddb5c Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Thu, 25 Oct 2018 12:43:44 -0400 Subject: [PATCH 2/5] Add run.sh management script --- dc.theme-dev.yml | 4 +- run.sh | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 2 deletions(-) create mode 100755 run.sh diff --git a/dc.theme-dev.yml b/dc.theme-dev.yml index 136b349..bde08b0 100644 --- a/dc.theme-dev.yml +++ b/dc.theme-dev.yml @@ -7,11 +7,11 @@ services: nginx-php-moodle: volumes: - type: volume - source: theme-bind + source: theme target: /opt/moodle/moodle-3.5.1/theme volumes: - theme-bind: + theme: driver: local driver_opts: type: none diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..49b3814 --- /dev/null +++ b/run.sh @@ -0,0 +1,164 @@ +#!/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}\"" + +# 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 Run Moodle in development mode + -t Mount theme directory to host for theme development + +Examples: +"${0} start -d" Start Moodle in development mode + +Version: ${VERSION} +EOF +} + +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 + 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 + 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 + compose_command="${compose_command} --file ${THEME_COMPOSE}" + fi + compose_command="${compose_command} up" + + if [ "${DETACH}" == 'True' ] ; then + compose_command="${compose_command} --detach" + fi + + eval "${compose_command}" +} + +subcommand="${1:-}" +shift + +while getopts ":dt" opt; do + case ${opt} in + 'd') DETACH='True' ;; + 't') THEME_DEV='True' ;; + '?') + color_echo red "Invalid option: -${OPTARG}" + 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 + + From d30c8fb1679b2c70040622fd3f855afc6d5cb763 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Fri, 26 Oct 2018 09:48:00 -0400 Subject: [PATCH 3/5] Ensure host theme directory exists before starting --- run.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index 49b3814..9031f5c 100755 --- a/run.sh +++ b/run.sh @@ -3,10 +3,13 @@ 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}\"" +BASE_COMMAND="${DOCKER_COMPOSE} --file ${BASE_COMPOSE}" + +THEME_DIR='/opt/moodle/theme' # Print usage and argument list function print_usage { @@ -25,16 +28,23 @@ Actions: version, -v, --version Print ${0} version and exit Parameters: - -d Run Moodle in development mode + -d Detach from running docker-compose containers -t Mount theme directory to host for theme development Examples: -"${0} start -d" Start Moodle in development mode +"${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}" @@ -72,6 +82,7 @@ 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" @@ -83,6 +94,7 @@ 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" From c02fc2b7be25777d2ec22eddccb79a4702f358d6 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Fri, 26 Oct 2018 13:41:33 -0400 Subject: [PATCH 4/5] Fix path to target volume --- dc.theme-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dc.theme-dev.yml b/dc.theme-dev.yml index bde08b0..65e117b 100644 --- a/dc.theme-dev.yml +++ b/dc.theme-dev.yml @@ -8,7 +8,7 @@ services: volumes: - type: volume source: theme - target: /opt/moodle/moodle-3.5.1/theme + target: /opt/moodle/app/theme volumes: theme: From 1049a0ba4976fd832bd41d9fbd5bd18a4ef709af Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Fri, 26 Oct 2018 15:12:32 -0400 Subject: [PATCH 5/5] Bump version to v0.1.13 --- .env | 2 +- CHANGELOG.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env b/.env index dd31063..7937e62 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ # Build version -BUILD_VERSION=v0.1.12 +BUILD_VERSION=v0.1.13 # Moodle version MOODLE_VERSION=3.5.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 824115c..829252c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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