diff --git a/.travis.yml b/.travis.yml index 0bfe22a20..cfd082170 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,17 @@ language: minimal services: - docker -before_script: cd docker +before_install: + # update docker + - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + - sudo apt-get update + - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce + - cd docker script: - bash run_tests_ci.sh after_success: - - bash run_build_release_package.sh + - bash run_build_github_release_package.sh deploy: skip_cleanup: true provider: releases diff --git a/docker/.env b/docker/.env new file mode 100644 index 000000000..1e623086c --- /dev/null +++ b/docker/.env @@ -0,0 +1,22 @@ +# important: this tag must be updated +# when theres a change to any dockerfile +# +# to update: use the next upcoming git tag +# dockerub builds an image for every tag +TAG=v5.0.0 + +FUEL_ENV=development + +# Database settings +DB_HOST=mysql +MYSQL_ROOT_PASSWORD=drRoots +MYSQL_USER=materia +MYSQL_PASSWORD=odin +MYSQL_DATABASE=materia + +# Fake S3 +INPUT_BUCKET=fakes3_uploads +OUTPUT_BUCKET=fakes3_assets +OUTPUT_MAX_DIMENSIONS=75x75, 0x0 +OUTPUT_BASE_KEY=media +IS_FAKES3=True diff --git a/docker/docker-compose.admin.yml b/docker/docker-compose.admin.yml index 9e484ad15..a355115ee 100644 --- a/docker/docker-compose.admin.yml +++ b/docker/docker-compose.admin.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3.2' # Docker Compose file meant for tasks like building assets and running tests services: @@ -6,16 +6,23 @@ services: environment: - FUEL_ENV=test volumes: - - static_files_test:/var/www/html/public/widget + - static_widget_files_test:/var/www/html/public/widget - uploaded_media_test:/var/www/html/fuel/packages/materia/media command: echo "yay" # We use a node container to compile js, css, etc node: - image: ucfopen/materia-node:latest + container_name: materia-node + image: ucfopen/materia-node:${TAG} + build: + context: ./dockerfiles + dockerfile: materia-node + networks: + - backend volumes: - ../:/var/www/html:rw - node_modules:/var/www/html/node_modules + - build_app_root:/build:rw mysql: environment: @@ -28,6 +35,7 @@ services: # - /var/lib/mysql volumes: - static_files_test: {} - uploaded_media_test: {} + build_app_root: {} + static_widget_files_test: {} # contain widgets installed in tests + uploaded_media_test: {} # contain files uploaded in tests node_modules: {} # node modules for npm diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 098e80bb8..4eb2c46df 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,11 +1,14 @@ -version: '2' +version: '3.2' services: nginx: + container_name: materia-nginx image: nginx:stable-alpine ports: - "80:80" # main materia - "8008:8008" # static files + networks: + - frontend volumes: - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ../public:/var/www/html/public:ro @@ -13,13 +16,21 @@ services: - phpfpm phpfpm: - image: ucfopen/materia-web-base:latest + container_name: materia-phpfpm + image: ucfopen/materia-web-base:${TAG} # TAG default value is in .env file + build: + context: ./dockerfiles + dockerfile: materia-web environment: - - FUEL_ENV=development - - DB_HOST=mysql - - DB_NAME=materia - - DB_USER=materia - - DB_PASS=odin + # See .env for default values + - FUEL_ENV + - DB_HOST + - DB_NAME=${MYSQL_DATABASE} + - DB_USER=${MYSQL_USER} + - DB_PASS=${MYSQL_DATABASE} + networks: + - frontend + - backend volumes: - ../:/var/www/html:rw - ./config/php/php.ini:/usr/local/etc/php/conf.d/php.ini:ro @@ -30,33 +41,54 @@ services: - fakes3 mysql: + container_name: materia-mysql image: mysql:5.7.18 environment: - - MYSQL_ROOT_PASSWORD=drRoots - - MYSQL_USER=materia - - MYSQL_PASSWORD=odin - - MYSQL_DATABASE=materia + - MYSQL_ROOT_PASSWORD + - MYSQL_USER + - MYSQL_PASSWORD + - MYSQL_DATABASE ports: - "3306:3306" # allow mysql access from the host - use /etc/hosts to set mysql to your docker-machine ip + networks: + - backend volumes: - "./config/mysql/01_create_test.sql:/docker-entrypoint-initdb.d/01_create_test.sql" memcached: + container_name: materia-memcached image: memcached:1.4.27-alpine + networks: + - backend fakes3: - image: ucfopen/materia-fake-s3:latest + container_name: materia-fakes3 + image: ucfopen/materia-fake-s3:${TAG} # TAG default value is in .env file + build: + context: . + dockerfile: ./dockerfiles/materia-fakes3 environment: - - INPUT_BUCKET=fakes3_uploads - - OUTPUT_BUCKET=fakes3_assets - - OUTPUT_MAX_DIMENSIONS=75x75, 0x0 - - OUTPUT_BASE_KEY=media - - IS_FAKES3=True + - INPUT_BUCKET + - OUTPUT_BUCKET + - OUTPUT_MAX_DIMENSIONS + - OUTPUT_BASE_KEY + - IS_FAKES3 ports: - "10001:10001" + networks: + - frontend + - backend volumes: - uploaded_media:/s3mnt/fakes3_root/fakes3_uploads/media/ +networks: + frontend: + # ommited till we can eaily use composer v3.5 on travis + # name: materia_frontend + backend: + # ommited till we can eaily use composer v3.5 on travis + # name: materia_backend + volumes: # static_files: {} # compiled js/css and uploaded widgets uploaded_media: {} # uploaded media files diff --git a/docker/dockerfiles/materia-node b/docker/dockerfiles/materia-node index a0735a887..afdeb05ab 100644 --- a/docker/dockerfiles/materia-node +++ b/docker/dockerfiles/materia-node @@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y \ fontconfig \ git \ python-dev \ + zip \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/docker/run_assets_build.sh b/docker/run_build_assets.sh similarity index 100% rename from docker/run_assets_build.sh rename to docker/run_build_assets.sh diff --git a/docker/run_build_github_release_package.sh b/docker/run_build_github_release_package.sh new file mode 100755 index 000000000..3afbe64c5 --- /dev/null +++ b/docker/run_build_github_release_package.sh @@ -0,0 +1,116 @@ +#!/bin/bash +####################################################### +# ABOUT THIS SCRIPT +# +# Install and build a base release package +# This should try to include as many constructed +# assets as possible to reduce the work needed +# to deploy Materia. This build will not +# disrupt the current files on disk - +# ex: no need to install node # or npm packages +# to build js - just include the js +# +# EX: ./run_build_release_package.sh +####################################################### +set -e + +# declare files that should have been created +declare -a FILES_THAT_SHOULD_EXIST=( + "public/js/materia.enginecore.js" + "public/css/widget-play.css" +) + +# declare files to omit from zip +declare -a FILES_TO_EXCLUDE=( + ".git*" + ".gitignore" + "app.json" + "nginx_app.conf" + "Procfile" + "node_modules*" + "githooks" + "phpcs.xml" + "src*" + "fuel/app/config/development*" + "fuel/app/config/heroku*" + "fuel/app/config/test*" + "fuel/app/config/production*" + "public/widget*" + "githooks*" + "coverage.xml" + "coverage*" +) + +# combine the files to exclude +EXCLUDE='' +for i in "${FILES_TO_EXCLUDE[@]}" +do + EXCLUDE="$EXCLUDE --exclude=\"./$i\"" +done + +# store the docker compose command to shorten the following commands +DC="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" + +set -o xtrace + +# # stop and remove docker containers +$DC down --volumes --remove-orphans + +$DC pull --ignore-pull-failures node + +# get rid of any left over package files +rm -rf clean_build_clone || true +rm -rf ../materia-pkg* || true +git clone ../ ./clean_build_clone + +# gather build info +DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +GITUSER=$(git config user.name) +GITEMAIL=$(git config user.email) +GITCOMMIT=$(cd clean_build_clone && git rev-parse HEAD) +GITREMOTE=$(cd clean_build_clone&& git remote get-url origin) + +# remove .git dir for slightly faster copy +rm -rf clean_build_clone/.git + +# start a build container +$DC run --no-deps --detach --workdir /build/clean_build_clone --name materia-build node tail -f /dev/null + +# copy the clean build clone into the container +docker cp ./clean_build_clone materia-build:/build + +# clean up +rm -rf clean_build_clone || true + +# install production node_modules +docker exec materia-build yarn install --frozen-lockfile --non-interactive --production + +# verify all files we expect to be created exist +for i in "${FILES_THAT_SHOULD_EXIST[@]}" +do + docker exec materia-build stat /build/clean_build_clone/$i +done + +# zip, excluding some files +docker exec materia-build bash -c "zip -r $EXCLUDE ../materia-pkg.zip ./" + +# calulate hashes +MD5=$(docker exec materia-build md5sum ../materia-pkg.zip) +SHA1=$(docker exec materia-build sha1sum ../materia-pkg.zip) +SHA256=$(docker exec materia-build sha256sum ../materia-pkg.zip) + +# copy zip file from container to host +docker cp materia-build:/build/materia-pkg.zip ../materia-pkg.zip + +# write build info file +echo "build_date: $DATE" > ../materia-pkg-build-info.yml +echo "git: $GITREMOTE" >> ../materia-pkg-build-info.yml +echo "git_version: $GITCOMMIT" >> ../materia-pkg-build-info.yml +echo "git_user: $GITUSER" >> ../materia-pkg-build-info.yml +echo "git_user_email: $GITEMAIL" >> ../materia-pkg-build-info.yml +echo "sha1: $SHA1" >> ../materia-pkg-build-info.yml +echo "sha256: $SHA256" >> ../materia-pkg-build-info.yml +echo "md5: $MD5" >> ../materia-pkg-build-info.yml + +# clean environment and configs +$DC down --volumes --remove-orphans diff --git a/docker/run_build_release_package.sh b/docker/run_build_release_package.sh deleted file mode 100755 index cfd49eb55..000000000 --- a/docker/run_build_release_package.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash -set -e - -NODE_DC_COMMAND="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" -DOCKER_IP="localhost" - -# install composer deps -docker-compose run -e "COMPOSER_ALLOW_SUPERUSER=1" --rm --no-deps phpfpm composer install --no-progress --optimize-autoloader --no-scripts --no-suggest --no-dev - -# install production node libs -$NODE_DC_COMMAND run --rm --no-deps node yarn install --frozen-lockfile --non-interactive --production - -# declare files that should have been created -declare -a FILES_THAT_SHOULD_EXIST=( - "public/js/materia.enginecore.js" - "public/css/widget.css" -) - -# nloop through all the files we expect to exist -for i in "${FILES_THAT_SHOULD_EXIST[@]}" -do - if [ ! -f "../$i" ]; then - echo "A file that should exist seems to be missing: $i" - exit 1 - fi -done - -# Accumulate licenses from composer -docker-compose run -e "COMPOSER_ALLOW_SUPERUSER=1" --rm --no-deps phpfpm ash -c "composer licenses --no-dev > licenses/LICENSES_COMPOSER" - -# accumulate node licenses -$NODE_DC_COMMAND run --rm --no-deps node bash -c "yarn licenses list --no-color > licenses/LICENSES_NPM" - -# lets, eh, zip it up? -if [ -f "../materia-pkg.zip" ]; then - rm ../materia-pkg.zip -fi - -# lets, eh, zip it up? -if [ -f "../materia-build-info.yml" ]; then - rm ../materia-build-info.yml -fi - -# declare files to omit from zip -declare -a FILES_TO_EXCLUDE=( - ".git*" - ".gitignore" - "app.json" - "nginx_app.conf" - "Procfile" - "node_modules*" - "githooks" - "phpcs.xml" - "src*" - "fuel/app/config/development*" - "fuel/app/config/heroku*" - "fuel/app/config/test*" - "fuel/app/config/production*" - "public/widget*" -) - -## now loop through excludes to build args for zip -EXCLUDE='' -for i in "${FILES_TO_EXCLUDE[@]}" -do - EXCLUDE="$EXCLUDE --exclude=\"../$i\"" -done - -bash -c "zip -r $EXCLUDE ../materia-pkg.zip ../" - -# now calulate hashes and gather build info -GITUSER=$(git config user.name) -GITEMAIL=$(git config user.email) -GITCOMMIT=$(git rev-parse HEAD) -GITREMOTE=$(git remote get-url origin) -DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -# we'll use the php box to keep things working on all systems -MD5=$(docker-compose run --rm --no-deps phpfpm php -r "echo hash_file('md5', 'materia-pkg.zip');") -SHA1=$(docker-compose run --rm --no-deps phpfpm php -r "echo hash_file('sha1', 'materia-pkg.zip');") -SHA256=$(docker-compose run --rm --no-deps phpfpm php -r "echo hash_file('sha256', 'materia-pkg.zip');") - -echo "build_date: $DATE" > ../materia-pkg-build-info.yml -echo "git: $GITREMOTE" >> ../materia-pkg-build-info.yml -echo "git_version: $GITCOMMIT" >> ../materia-pkg-build-info.yml -echo "git_user: $GITUSER" >> ../materia-pkg-build-info.yml -echo "git_user_email: $GITEMAIL" >> ../materia-pkg-build-info.yml -echo "sha1: $SHA1" >> ../materia-pkg-build-info.yml -echo "sha256: $SHA256" >> ../materia-pkg-build-info.yml -echo "md5: $MD5" >> ../materia-pkg-build-info.yml diff --git a/docker/run_create_me.sh b/docker/run_create_me.sh new file mode 100755 index 000000000..d6cecdfa6 --- /dev/null +++ b/docker/run_create_me.sh @@ -0,0 +1,19 @@ +#!/bin/bash +####################################################### +# ABOUT THIS SCRIPT +# +# Create an admin user based on the +# current user of this machine +# +# EX: ./run_create_me.sh +####################################################### + +# create an admin for the current host user +# customize your password by setting MATERIA_DEV_PASS +PASS=${MATERIA_DEV_PASS:-kogneato} + +# create or update the user and pw +docker-compose run --rm phpfpm bash -c "php oil r admin:new_user $USER $USER M Lastname $USER@mail.com $PASS || php oil r admin:reset_password $USER $PASS" + +# give them super_user and basic_author +docker-compose run --rm phpfpm bash -c "php oil r admin:give_user_role $USER super_user || true && php oil r admin:give_user_role $USER basic_author" diff --git a/docker/run_docker_build_fakes3.sh b/docker/run_docker_build_fakes3.sh deleted file mode 100755 index af1b60a59..000000000 --- a/docker/run_docker_build_fakes3.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -####################################################### -# ABOUT THIS SCRIPT -# -# Builds a new materia-node container using a dockerfile -# Usefull for updating that container and uploading it -# to our AWS Docker Container Repository -# -# EX: ./run_docker_build_node.sh -####################################################### -set -e - -BOX_NAME="materia-fake-s3" -DOCKERFILE="dockerfiles/materia-fakes3" -DCR="ucfopen" - -docker build -t $BOX_NAME:latest -f $DOCKERFILE . - -echo "===================================================" -echo "To tag the latest build as a specific version, use:" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:X.X.X" -echo "To publish the 'latest' container:" -echo "> docker push $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker push $DCR/$BOX_NAME:X.X.X" diff --git a/docker/run_docker_build_node.sh b/docker/run_docker_build_node.sh deleted file mode 100755 index 1ad44e9d2..000000000 --- a/docker/run_docker_build_node.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -####################################################### -# ABOUT THIS SCRIPT -# -# Builds a new materia-node container using a dockerfile -# Usefull for updating that container and uploading it -# to our AWS Docker Container Repository -# -# EX: ./run_docker_build_node.sh -####################################################### -set -e - -BOX_NAME="materia-node" -DOCKERFILE="materia-node" -DCR="ucfopen" - -cd ./dockerfiles -docker build -t $BOX_NAME:latest -f $DOCKERFILE . - -echo "===================================================" -echo "To tag the latest build as a specific version, use:" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:X.X.X" -echo "To publish the 'latest' container:" -echo "> docker push $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker push $DCR/$BOX_NAME:X.X.X" diff --git a/docker/run_docker_build_web.sh b/docker/run_docker_build_web.sh deleted file mode 100755 index 2f97f86a7..000000000 --- a/docker/run_docker_build_web.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -####################################################### -# ABOUT THIS SCRIPT -# -# Builds a new materia-node container using a dockerfile -# Usefull for updating that container and uploading it -# to our AWS Docker Container Repository -# -# EX: ./run_docker_build_node.sh -####################################################### -set -e - -BOX_NAME="materia-web-base" -DOCKERFILE="materia-web" -DCR="ucfopen" - -cd ./dockerfiles -docker build -t $BOX_NAME:latest -f $DOCKERFILE . - -echo "===================================================" -echo "To tag the latest build as a specific version, use:" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker tag $BOX_NAME:latest $DCR/$BOX_NAME:X.X.X" -echo "To publish the 'latest' container:" -echo "> docker push $DCR/$BOX_NAME:latest" -echo "or" -echo "> docker push $DCR/$BOX_NAME:X.X.X" diff --git a/docker/run_first.sh b/docker/run_first.sh index 104242e3b..681aaf4ff 100755 --- a/docker/run_first.sh +++ b/docker/run_first.sh @@ -22,27 +22,21 @@ # Build your own using ./run_widgets_build.sh ####################################################### set -e +# set -o xtrace -NODE_DC_COMMAND="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" DOCKER_IP="localhost" -# docker-compose pull +# clean environment and configs +# clean migration files in every environment +rm -f ../fuel/app/config/**/migrations.php -# create and migrate the database -docker-compose build +# store the docker compose command to shorten the following commands +DC="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" -# create the contaners and setup networking -docker-compose create +$DC pull --ignore-pull-failures # install composer deps -docker-compose run --rm phpfpm composer install - -# run install if migration file is not there -# sometimes it's left behind when copying or re-installing -# it needs to be removed for install to work correctly -if [ -f ../fuel/app/config/development/migrations.php ]; then - rm -f ../fuel/app/config/development/migrations.php -fi +docker-compose run --rm --no-deps phpfpm composer install # setup mysql docker-compose run --rm phpfpm /wait-for-it.sh mysql:3306 -t 20 -- composer oil-install-quiet @@ -51,13 +45,14 @@ docker-compose run --rm phpfpm /wait-for-it.sh mysql:3306 -t 20 -- composer oil- docker-compose run --rm phpfpm bash -c 'php oil r widget:install_from_config' # Install any widgets in the tmp dir -docker-compose run --rm phpfpm bash -c 'php oil r widget:install fuel/app/tmp/widget_packages/*.wigt' +source run_widgets_install.sh '*.wigt' + +# build all the js/css assets +source run_build_assets.sh -source run_assets_build.sh +# create a dev user based on your current user +source run_create_me.sh -# run that beast -# Use docker or set up the docker-machine environment echo -e "Materia will be hosted on \033[32m$DOCKER_IP\033[0m" -echo -e "\033[1mBuild Assets:\033[0m ./run_assets_build.sh" echo -e "\033[1mRun an oil comand:\033[0m ./run.sh php oil r widget:show_engines" echo -e "\033[1mRun the web app:\033[0m docker-compose up" diff --git a/docker/run_tests_ci.sh b/docker/run_tests_ci.sh index 2d9c4de3e..aebb5391a 100755 --- a/docker/run_tests_ci.sh +++ b/docker/run_tests_ci.sh @@ -2,28 +2,18 @@ ####################################################### # ABOUT THIS SCRIPT # -# Jenkins script for reliably running clean tests with current boxes +# CI script for reliably running clean tests with current boxes # # Continuously builds assets using the included node container # Doesn't seem to stop properly with ctrl-c # use "docker stop " to kill it ####################################################### set -e +set -o xtrace -# clean migration files -rm -f $DIR/app/fuel/app/config/development/migrations.php -rm -f $DIR/app/fuel/app/config/test/migrations.php - -# store the docker compose command to shorten the following commands DC="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" -# stop and remove docker containers -$DC stop -$DC rm -f - -$DC pull -$DC build mysql -$DC build phpfpm +$DC pull --ignore-pull-failures phpfpm fakes3 # install php deps $DC run --rm phpfpm composer install --no-progress @@ -32,11 +22,10 @@ $DC run --rm phpfpm composer install --no-progress $DC run --rm phpfpm env COMPOSER_ALLOW_SUPERUSER=1 composer sniff-ci # install widgets and run tests -source ./run_tests_coverage.sh +source run_tests_coverage.sh # turn off failure stop on error set +e # stop and remove docker containers -$DC stop -$DC rm -f +$DC rm --force --stop diff --git a/docker/run_tests_coverage.sh b/docker/run_tests_coverage.sh index 630964d5f..bf6fc073d 100755 --- a/docker/run_tests_coverage.sh +++ b/docker/run_tests_coverage.sh @@ -1,11 +1,23 @@ #!/bin/bash +####################################################### +# ABOUT THIS SCRIPT +# +# RUNS TESTS WITH COVERAGE +# +# place .wigt files in app/fuel/app/tmp/widget_packages/ +# Supports globs, but you have to quote them so they aren't +# expanded in your host's shell instead of the container's +# +# EX: ./run_tests_coverage.sh +# EX: ./run_tests_coverage.sh --group=Lti +####################################################### set -e -echo "remember you can limit your test groups with './run_tests_coverage.sh --group=Lti'" +DC="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" -# If you have an issue with a broken widget package breaking this script, run the following to clear the widgets -# docker-compose -f docker-compose.yml -f docker-compose.admin.yml run --rm phpfpm bash -c -e 'rm /var/www/html/fuel/packages/materia/vendor/widget/test/*' +echo "remember you can limit your test groups with './run_tests_coverage.sh --group=Lti'" +echo "If you have an issue with a broken widget, clear the widgets with:" +echo "$DC run --rm phpfpm bash -c -e 'rm /var/www/html/fuel/packages/materia/vendor/widget/test/*'" # store the docker compose command to shorten the following commands -DC="docker-compose -f docker-compose.yml -f docker-compose.admin.yml" $DC run --rm phpfpm /wait-for-it.sh mysql:3306 -t 20 -- env COMPOSER_ALLOW_SUPERUSER=1 composer run coverageci -- "$@" diff --git a/docker/run_widgets_install.sh b/docker/run_widgets_install.sh index 142b4e0a4..2b806e6ff 100755 --- a/docker/run_widgets_install.sh +++ b/docker/run_widgets_install.sh @@ -1,8 +1,16 @@ #!/bin/bash -set -e +####################################################### +# ABOUT THIS SCRIPT +# # INSTALLS WIDGETS FROM EXISTING WIGT FILE +# # place .wigt files in app/fuel/app/tmp/widget_packages/ -# run with: ./install_widget.sh adventure.wigt -# this does support globs, but you have to quote them so they arent processed in your term -# run w wildcards: ./install_widget.sh '*.wigt' OR ./install_widget.sh 'popup*.wigt' +# Supports globs, but you have to quote them so they aren't +# expanded in your host's shell instead of the container's +# +# EX: ./install_widget.sh adventure.wigt +# EX: ./install_widget.sh '*.wigt' +####################################################### +set -e + docker-compose run --rm phpfpm bash -c 'php oil r widget:install fuel/app/tmp/widget_packages/'$1 diff --git a/fuel/app/tasks/admin.php b/fuel/app/tasks/admin.php index 86e767cb2..6f4e582d2 100644 --- a/fuel/app/tasks/admin.php +++ b/fuel/app/tasks/admin.php @@ -223,12 +223,8 @@ public static function create_default_users() } else { - // create - // create user static::new_user($user['name'], $user['first_name'], '', $user['last_name'], $user['email'], $user['password']); - \Cli::write("adding user {$user['name']}"); - \Cli::write(\Cli::color("password set to '{$user['password']}'", 'red')); if ( ! empty($user['roles'])) { @@ -438,46 +434,55 @@ public static function populate_roles() \Cli::write(\Cli::color("Roles Added: $roles", 'green')); } - public static function give_user_role($user_name, $role_name) + public static function give_user_role($username, $role_name) { - if ($user = \Model_User::find_by_username($user_name)) + if ($user = \Model_User::find_by_username($username)) { if (\Materia\Perm_Manager::add_users_to_roles_system_only([$user->id], [$role_name])) { - if ( ! \Fuel::$is_test) \Cli::write(\Cli::color("$user_name now in role: $role_name", 'green')); + if ( ! \Fuel::$is_test) \Cli::write(\Cli::color("$username now in role: $role_name", 'green')); return true; } else { \Cli::beep(1); - \Cli::write(\Cli::color("couldn't add user $user_name to role $role_name", 'red')); + \Cli::write(\Cli::color("couldn't add user $username to role $role_name", 'red')); exit(1); // linux exit code 1 = error } } else { \Cli::beep(1); - \Cli::write(\Cli::color("$user_name doesnt exist", 'red')); + \Cli::write(\Cli::color("$username doesnt exist", 'red')); exit(1); // linux exit code 1 = error } } - public static function reset_password($username) + public static function reset_password(String $username, String $password=null) :void { - $newpassword = \Auth::instance()->reset_password($username); + if ( ! empty($password)) + { + \Auth::instance()->update_user(['password' => $password], $username); + $newpassword = $password; + } + else + { + $newpassword = \Auth::instance()->reset_password($username); + } + if ( ! \Fuel::$is_test) { - \Cli::write("New password is $username ".\Cli::color($newpassword, 'yellow')); + \Cli::write("New password for $username is: ".\Cli::color($newpassword, 'yellow')); } } - public static function new_user($user_name, $first_name, $mi, $last_name, $email, $password) + public static function new_user($username, $first_name, $mi, $last_name, $email, $password) { try { // Auth instance must be MateriaAuth or similar auth module // SimpleAuth does not work!! - $user_id = \Auth::instance('Materiaauth')->create_user($user_name, $password, $email, 1, [], $first_name, $last_name); + $user_id = \Auth::instance('Materiaauth')->create_user($username, $password, $email, 1, [], $first_name, $last_name); if ($user_id === false) { @@ -489,7 +494,7 @@ public static function new_user($user_name, $first_name, $mi, $last_name, $emai } else { - if ( ! \Fuel::$is_test) \Cli::write('User Created', 'green'); + if ( ! \Fuel::$is_test) \Cli::write("User Created: $username password: $password", 'green'); return $user_id; } } @@ -511,19 +516,18 @@ public static function instant_user($name = null, $role = 'basic_author') if ( ! empty($name)) { $first = $last = $name; - $pass = '123456'; } else { $name = 'test'.\Model_User::count(); $first = 'Unofficial Test User'; - $last = substr(str_shuffle(md5(time())),0,10); //generates a random 10-digit alphanumeric string - $pass = 'test'; + $last = \Str::random('alnum', 10); } + $pass = \Str::random('alnum', 16); + $user_id = static::new_user($name, $first, '', $last, $name.'@test.com', $pass); - static::reset_password($name); static::give_user_role($name, $role); return $user_id; @@ -546,8 +550,8 @@ public static function clear_cache($quiet=false) public static function anonymize_users() { - $skip_user_names = func_get_args(); - if (empty($skip_user_names)) $skip_user_names = []; + $skip_usernames = func_get_args(); + if (empty($skip_usernames)) $skip_usernames = []; require(APPPATH.'vendor/php-faker/faker.php'); @@ -555,7 +559,7 @@ public static function anonymize_users() $users = \DB::select() ->from('users') - ->where('username', 'NOT IN', $skip_user_names) + ->where('username', 'NOT IN', $skip_usernames) ->execute(); if ($users->count() > 0) diff --git a/fuel/app/tasks/widget.php b/fuel/app/tasks/widget.php index 44da33d2e..d4eaf40f3 100644 --- a/fuel/app/tasks/widget.php +++ b/fuel/app/tasks/widget.php @@ -229,7 +229,7 @@ public static function install() if ( ! $count) { - self::write("No widgets found in '".implode(',', func_get_args()), true); + self::write('No widgets found in '.implode(',', func_get_args()), true); return; }