diff --git a/README.md b/README.md index 5f52a61c..afdd8934 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,26 @@ To uninstall a plugin: 1. Remove the plugin from the `config.inc.php` file 2. run `php scripts/update.php` + +## Running with Docker + +1. Copy `config.sample.php` to `config.inc.php` and use recommended docker configs +2. Copy `www/sample.htaccess` to `www/.htaccess` and use recommended docker configs +3. Add `127.0.0.1 localhost.unl.edu` to `/etc/hosts` on your host machine +4. Run `docker-compose up` in the root directory to build and run the docker containers +5. Open Maps in the browser using the URL [http://localhost.unl.edu:5502/](http://localhost.unl.edu:5502/) + +Docker will create two containers called app and db. App holds the contents of the root directory as well as any running program. DB only holds mariadb. + +You will be able to edit the files and they will automatically be changed in the container. Every time you use `docker-compose up` it will reinstall/update the +dependencies for composer and npm and recompile grunt. You will need to wait to see the apache log outputs before it will be hosted. If you would like to change the port or URL for the docker container you will need to stop and remove the old containers with `docker-compose down`, then change the `docker-compose.yml` and run `docker-compose up --build` to rebuild the image and container. + +You can run `docker-compose up -d` to not show the outputs from the containers but it will be hard to know when the app container is ready. + +### Stopping Docker Container + +Use `docker-compose down` in the root directory in another terminal window to stop the containers + +### Running other commands with Docker + +Use `docker-compose run app sh` to open an interactive shell in the docker container for the app. This container will have the contents of your root directory in `/var/www/html` and will have node, php, composer, and apache installed. diff --git a/config.sample.php b/config.sample.php index 34b2163e..f9646f27 100644 --- a/config.sample.php +++ b/config.sample.php @@ -19,6 +19,12 @@ Config::set('DB_PASSWORD' , 'password'); Config::set('DB_NAME' , 'sitemaster'); +// If using docker +// Config::set('DB_HOST' , 'db'); +// Config::set('DB_USER' , 'root'); +// Config::set('DB_PASSWORD' , 'mariadb'); +// Config::set('DB_NAME' , 'sitemaster'); + /********************************************************************************************************************** * Other settings, including theme */ @@ -60,6 +66,12 @@ Config::set('TEST_DB_PASSWORD' , 'password'); Config::set('TEST_DB_NAME' , 'sitemaster_test'); +// If using docker +// Config::set('TEST_DB_HOST' , 'db'); +// Config::set('TEST_DB_USER' , 'root'); +// Config::set('TEST_DB_PASSWORD' , 'mariadb'); +// Config::set('TEST_DB_NAME' , 'sitemaster_test'); + /********************************************************************************************************************** * TRAVIS settings */ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..123c58c5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,57 @@ +version: '3.8' + +services: + app: + hostname: app + + # this is the URL to go to + domainname: localhost.unl.edu + build: + context: . + dockerfile: Dockerfile + args: + # Update 'VARIANT' to pick a version of PHP version: 8, 8.1, 8.0, 7, 7.4 + VARIANT: "7.4" + # Optional Node.js version + NODE_VERSION: "14" + + # DIRROOT is where the files will be copied to in the docker container + DIRROOT: "/var/www/html" + + # DOCROOT is where the index.php is located typically the /www directory + DOCROOT: "" + + volumes: + - .:/var/www/html/:cached + + # this port on the left is also used in /www/.htaccess and config.inc.php + # Make sure all are the same + ports: + - "5502:80" + + depends_on: + - db + + stdin_open: true + tty: true + + command: sh -c "git submodule init && git submodule update && composer install && npm install && php scripts/install.php && apachectl -D FOREGROUND" + + db: + image: mariadb:10.4 + restart: unless-stopped + volumes: + - mariadb-data:/var/lib/mysql + - ./init.sql:/data/application/init.sql + command: --init-file /data/application/init.sql + environment: + MYSQL_ROOT_PASSWORD: mariadb + MYSQL_DATABASE: sitemaster + MYSQL_USER: mariadb + MYSQL_PASSWORD: mariadb + + ports: + - "9906:3306" + +volumes: + mariadb-data: null \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..3b587577 --- /dev/null +++ b/dockerfile @@ -0,0 +1,55 @@ +# [Choice] PHP version (use -bullseye variants on local arm64/Apple Silicon): 8, 8.1, 8.0, 7, 7.4, 7.3, 8-bullseye, 8.1-bullseye, 8.0-bullseye, 7-bullseye, 7.4-bullseye, 7.3-bullseye, 8-buster, 8.1-buster, 8.0-buster, 7-buster, 7.4-buster +ARG VARIANT="7.4" +ARG NODE_VERSION="16" +FROM node:${NODE_VERSION}-bullseye AS node +FROM php:${VARIANT}-apache-bullseye + +# copies the node files into the PHP files +COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules +COPY --from=node /usr/local/bin/node /usr/local/bin/node +RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm + +# Install MariaDB client +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y mariadb-client \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y git zip unzip chromium + +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true + +# Install php-mysql driver +RUN docker-php-ext-install mysqli pdo pdo_mysql + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# removes error "Invalid command 'RewriteEngine'" +RUN a2enmod rewrite && service apache2 restart + +# changes the docroot so the domain points to the correct file +ARG DIRROOT="/var/www/html" +ARG DOCROOT="/www" +ENV APACHE_DOCUMENT_ROOT=${DIRROOT}${DOCROOT} +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +WORKDIR ${DIRROOT} + +# can't do this since mounting the volume in the docker compose will remove the files made here +# COPY ./composer.json ${DIRROOT} +# RUN composer install + +# can't do this since mounting the volume in the docker compose will remove the files made here +# COPY ./package.json ${DIRROOT} +# RUN npm install + +COPY . ${DIRROOT} + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 + diff --git a/init.sql b/init.sql new file mode 100644 index 00000000..21d9f616 --- /dev/null +++ b/init.sql @@ -0,0 +1,3 @@ +-- File sets up the inital enviroment for Docker +CREATE DATABASE IF NOT EXISTS sitemaster; +CREATE DATABASE IF NOT EXISTS sitemaster_test; \ No newline at end of file diff --git a/scripts/install.php b/scripts/install.php index a01467e7..742944a4 100644 --- a/scripts/install.php +++ b/scripts/install.php @@ -6,7 +6,7 @@ $root = dirname(__DIR__); //Update composer -passthru('php ' . $root. '/composer.phar install'); +passthru('php ' . $root. '/composer.phar install -n'); require_once($root. '/scripts/update_libs.php'); diff --git a/scripts/update_libs.php b/scripts/update_libs.php index efcbaa68..07f1473a 100644 --- a/scripts/update_libs.php +++ b/scripts/update_libs.php @@ -11,13 +11,13 @@ echo 'This may take some time...' . PHP_EOL; //Update composer -passthru('php ' . \SiteMaster\Core\Util::getRootDir() . '/composer.phar install'); +passthru('php ' . \SiteMaster\Core\Util::getRootDir() . '/composer.phar install -n'); $plugins = $pluginManager->getAllPlugins(); foreach ($plugins as $pluginName) { $plugin = $pluginManager->getPluginInfo($pluginName); - $command = 'cd ' . $plugin->getRootDirectory() . ' && ' . \SiteMaster\Core\Util::getRootDir() . '/composer.phar install'; + $command = 'cd ' . $plugin->getRootDirectory() . ' && ' . \SiteMaster\Core\Util::getRootDir() . '/composer.phar install -n'; passthru($command); }