From 265db331026d41254619df2063a40a455e666c15 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Tue, 26 Jul 2022 11:30:49 -0500 Subject: [PATCH 1/5] added docker --- docker-compose.yml | 54 +++++++++++++++++++++++++++++++++++++++++++++ dockerfile | 55 ++++++++++++++++++++++++++++++++++++++++++++++ init.sql | 3 +++ 3 files changed, 112 insertions(+) create mode 100644 docker-compose.yml create mode 100644 dockerfile create mode 100644 init.sql diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..bfb51fe8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +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: + - "5505:80" + + stdin_open: true + tty: true + + command: sh -c "git submodule init && git submodule update && composer install && npm install && php scripts/update.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 From ed5f330cb17385b03f1acd8a3cd388cc81dc9084 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Tue, 26 Jul 2022 11:31:40 -0500 Subject: [PATCH 2/5] changed install and changed composer to -n --- docker-compose.yml | 2 +- scripts/install.php | 2 +- scripts/update_libs.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bfb51fe8..1285169f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: stdin_open: true tty: true - command: sh -c "git submodule init && git submodule update && composer install && npm install && php scripts/update.php && apachectl -D FOREGROUND" + 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 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); } From d081e4755b98ab0f03e4cdc7e192b8bd4534314c Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Tue, 26 Jul 2022 13:58:30 -0500 Subject: [PATCH 3/5] edited readme and ports --- README.md | 23 +++++++++++++++++++++++ config.sample.php | 12 ++++++++++++ docker-compose.yml | 6 +++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5f52a61c..f7959655 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 +3. Run `docker-compose up` in the root directory to build and run the docker containers +4. 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 index 1285169f..a1174377 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: # this port on the left is also used in /www/.htaccess and config.inc.php # Make sure all are the same ports: - - "5505:80" + - "5502:80" stdin_open: true tty: true @@ -39,8 +39,8 @@ services: restart: unless-stopped volumes: - mariadb-data:/var/lib/mysql - # - ./init.sql:/data/application/init.sql - # command: --init-file /data/application/init.sql + - ./init.sql:/data/application/init.sql + command: --init-file /data/application/init.sql environment: MYSQL_ROOT_PASSWORD: mariadb MYSQL_DATABASE: sitemaster From 2a2c711bb585e61a67763a80660def0b3fdccb59 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Tue, 26 Jul 2022 14:15:36 -0500 Subject: [PATCH 4/5] fixed readme numbers --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7959655..afdd8934 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ To uninstall a plugin: 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 -3. Run `docker-compose up` in the root directory to build and run the docker containers -4. Open Maps in the browser using the URL [http://localhost.unl.edu:5502/](http://localhost.unl.edu:5502/) +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. From b93078fc2d62c080029fb8a51aec7a052ae1385f Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Tue, 26 Jul 2022 16:53:26 -0500 Subject: [PATCH 5/5] added depends on --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index a1174377..123c58c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: ports: - "5502:80" + depends_on: + - db + stdin_open: true tty: true