diff --git a/.env b/.env index 0b99a88cb5..2b7fb7d447 100644 --- a/.env +++ b/.env @@ -2,3 +2,4 @@ COURSES_DIRECTORY_ON_HOST=../ww-docker-data/courses WEBWORK2_HTTP_PORT_ON_HOST=8080 WEBWORK_DB_USER=webworkWrite WEBWORK_DB_PASSWORD=passwordRWsetItBeforeFirstStartingTheDBcontainer +WEBWORK_MYSQL_ROOT_PASSWORD=sqlRootPasswordSetThisPasswordBEFOREfirstStartingTheDBcontainer diff --git a/.gitignore b/.gitignore index 58aa926198..906c39d60a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.conf *-config +.env applets tmp logs diff --git a/README b/README index 5994eb525b..e5f5f5c736 100644 --- a/README +++ b/README @@ -4,7 +4,8 @@ Branch: github.com/openwebwork http://webwork.maa.org/wiki/Release_notes_for_WeBWorK_2.16 - Copyright 2000-2019, The WeBWorK Project + Copyright 2000-2021, The WeBWorK Project + http://webwork.maa.org All rights reserved. diff --git a/docker-compose.yml b/docker-compose.yml index 8acac6cf91..7a9dbec30a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,7 @@ services: # When the MariaDB container is first started it will set the # the MYSQL_ROOT_PASSWORD if there is no mysql database in the # data volume. - MYSQL_ROOT_PASSWORD: sqlRootPasswordSetThisPasswordBEFOREfirstStartingTheDBcontainer + MYSQL_ROOT_PASSWORD: ${WEBWORK_MYSQL_ROOT_PASSWORD} # When the MariaDB container is first started it will create # the WW database and WW DB user based on: @@ -88,7 +88,7 @@ services: - PG_BRANCH=PG-2.16 # If you are using the 2 stage build process uncomment the next line - #dockerfile: DockerfileStage2 + dockerfile: DockerfileStage2 # and first run # docker build --tag webwork-base:forWW216 -f DockerfileStage1 . # and then @@ -225,7 +225,7 @@ services: #ADD_LOCALES: "he_IL ISO-8859-8\nhe_IL.UTF-8 UTF-8\n" # Extra Ubuntu packages to install during startup - #ADD_APT_PACKAGES: vim telnet + ADD_APT_PACKAGES: nano less # The system timezone for the container can be set using #SYSTEM_TIMEZONE: zone/city diff --git a/docker-config/docker-entrypoint.sh b/docker-config/docker-entrypoint.sh index a63628fa94..462238114b 100755 --- a/docker-config/docker-entrypoint.sh +++ b/docker-config/docker-entrypoint.sh @@ -79,16 +79,30 @@ if [ "$1" = 'apache2' ]; then -e 's/^\$database_username ="webworkWrite"/$database_username =$ENV{"WEBWORK_DB_USER"}/' \ -e 's/^\$database_password ='\''passwordRW'\''/$database_password =$ENV{"WEBWORK_DB_PASSWORD"}/' \ -e 's/mail{smtpServer} = '\'''\''/mail{smtpServer} = $ENV{"WEBWORK_SMTP_SERVER"}/' \ - -e 's/mail{smtpSender} = '\'''\''/mail{smtpSender} = $ENV{"WEBWORK_SMTP_SENDER"}/' \ -e 's/siteDefaults{timezone} = "America\/New_York"/siteDefaults{timezone} = $ENV{"WEBWORK_TIMEZONE"}/' \ -e 's/^# $server_userID = '\''www-data/$server_userID = '\''www-data/' \ - -e 's/^# $server_groupID = '\''www-data/$server_groupID = '\''www-data/' \ - $WEBWORK_ROOT/conf/site.conf + -e 's/^# $server_groupID = '\''www-data/$server_groupID = '\''www-data/' $WEBWORK_ROOT/conf/site.conf + + echo "$WEBWORK_ROOT/conf/$i has been modified." + fi + + if [ $i == 'localOverrides.conf' ]; then + sed -i -e 's/#$pg{specialPGEnvironmentVars}{Rserve} = {host => "r"};/$pg{specialPGEnvironmentVars}{Rserve} = {host => "r"};/' \ + -e 's/#$problemLibrary{showLibraryLocalStats} = 0;/$problemLibrary{showLibraryLocalStats} = 0;/' $WEBWORK_ROOT/conf/localOverrides.conf + echo "$WEBWORK_ROOT/conf/$i has been modified." fi fi + done # create admin course if not existing - if [ ! -d "$APP_ROOT/courses/admin" ]; then + # check first if the admin courses directory exists then check that at + # least one of the tables associated with the course (the admin_user table) exists + + echo "check admin course and admin tables" + wait_for_db + ADMIN_TABLE_EXISTS=`mysql -u $WEBWORK_DB_USER -p$WEBWORK_DB_PASSWORD -B -N -h db -e "select count(*) from information_schema.tables where table_schema='webwork' and table_name = 'admin_user';" 2>/dev/null` + + if [ ! -d "$APP_ROOT/courses/admin" ]; then newgrp www-data umask 2 cd $APP_ROOT/courses @@ -96,7 +110,26 @@ if [ "$1" = 'apache2' ]; then $WEBWORK_ROOT/bin/addcourse admin --db-layout=sql_single --users=$WEBWORK_ROOT/courses.dist/adminClasslist.lst --professors=admin chown www-data:www-data -R $APP_ROOT/courses echo "Admin course is created." + echo "user: admin password: admin added to course admin and tables upgraded" + elif [ $ADMIN_TABLE_EXISTS == 0 ]; then + echo "admin course db tables need updating" + $WEBWORK_ROOT/bin/upgrade_admin_db.pl + $WEBWORK_ROOT/bin/wwsh admin $WEBWORK_ROOT/bin/addadmin + echo "admin course tables created with one user: admin whose password is admin" + else + echo "using pre-existing admin course and admin tables" fi + + # use case for the extra check for the admin: + # In rebuilding a docker box one might clear out the docker containers, + # images and volumes including mariaDB, BUT leave the + # contents of ww-docker-data directory in place. It now holds the shell of the courses + # including the admin course directory. This means that once you rebuild the box + # you can't access the admin course (because the admin_user table is missing) + # and you need to run bin/upgrade_admin_db.pl from inside the container. + # This check insures that if the admin_user table is missing the whole admin course is rebuilt + # even if the admin directory is in place. + # modelCourses link if not existing if [ ! -d "$APP_ROOT/courses/modelCourse" ]; then echo "create modelCourse subdirectory" @@ -208,8 +241,14 @@ if [ "$1" = 'apache2' ]; then # This change significantly speeds up Docker startup time on production # servers with many files/courses (on Linux). - chown -R www-data:www-data logs tmp DATA - chmod -R ug+w logs tmp DATA + chown -R www-data:www-data logs tmp DATA + chmod -R ug+w logs tmp DATA + chown www-data:www-data htdocs/tmp + chmod ug+w htdocs/tmp + + # even if the admin and courses directories already existed their permissions might not have been correct + # chown www-data:www-data $APP_ROOT/courses + chown www-data:www-data $APP_ROOT/courses/admin/* # Symbolic links which have no target outside the Docker container # cause problems duringt the rebuild process on some systems.