-
-
Save redstrike/c6aed72650ca636ceb476b214d9907a1 to your computer and use it in GitHub Desktop.
Building Application Stacks With NGINX Unit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "listeners": { | |
| "*:8080": { | |
| "pass": "routes/wordpress" | |
| } | |
| }, | |
| "routes": { | |
| "wordpress": [ | |
| { | |
| "match": { | |
| "uri": [ | |
| "*.php", | |
| "*.php/*", | |
| "/wp-admin/" | |
| ] | |
| }, | |
| "action": { | |
| "pass": "applications/wp_direct" | |
| } | |
| }, | |
| { | |
| "action": { | |
| "share": "/var/apphome", | |
| "fallback": { | |
| "pass": "applications/wp_index" | |
| } | |
| } | |
| } | |
| ] | |
| }, | |
| "applications": { | |
| "wp_direct": { | |
| "type": "php", | |
| "options": { | |
| "file": "/etc/php.ini", | |
| "admin": { | |
| "upload_max_filesize": "20M" | |
| } | |
| }, | |
| "user": "wordpress", | |
| "group": "wordpress", | |
| "root": "/var/apphome" | |
| }, | |
| "wp_index": { | |
| "type": "php", | |
| "options": { | |
| "file": "/etc/php.ini", | |
| "admin": { | |
| "upload_max_filesize": "20M" | |
| } | |
| }, | |
| "user": "wpuser", | |
| "group": "wpgroup", | |
| "root": "/var/apphome", | |
| "script": "index.php" | |
| } | |
| }, | |
| "settings": { | |
| "http": { | |
| "header_read_timeout": 10, | |
| "body_read_timeout": 10, | |
| "send_timeout": 10, | |
| "idle_timeout": 120, | |
| "max_body_size": 6291456, | |
| "static": { | |
| "mime_types": { | |
| "text/plain": [ | |
| ".log", | |
| "README", | |
| "CHANGES" | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -ex | |
| build_container() { | |
| docker build -t YOURIMAGETAG --no-cache . | |
| } | |
| containerize() { | |
| echo "Building Container Image" | |
| build_container | |
| docker tag YOURIMAGETAG:latest REMOTEIMAGETAG:latest | |
| echo "Pushing... " | |
| docker push REMOTEIMAGETAG:latest | |
| } | |
| case $1 in | |
| "push") | |
| echo "Building and Pushing to Registry ..." | |
| containerize | |
| ;; | |
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "require": { | |
| "johnpbloch/wordpress": "*" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ************* DEV DOCKER FILE ************* | |
| FROM nginx/unit:1.16.0-php7.3 | |
| RUN mkdir /var/apphome/ && groupadd -r wordpress && useradd --no-log-init -r -g wordpress wordpress && \ | |
| chown -R wordpress:wordpress /var/apphome/ && \ | |
| apt-get update && apt-get install --no-install-recommends --no-install-suggests -y php7.3-mysql php7.3-gd && \ | |
| curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \ | |
| cp wp-cli.phar /usr/local/bin/wpc | |
| COPY php.ini /etc/php/7.3/cli/conf.d/php-unit.ini | |
| COPY .unit.conf.json /docker-entrypoint.d/.unit.conf.json | |
| CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "listeners": { | |
| "*:8080": { | |
| "pass": "routes/wordpress" | |
| } | |
| }, | |
| "routes": { | |
| "wordpress": [ | |
| { | |
| "match": { | |
| "uri": [ | |
| "*.php", | |
| "*.php/*", | |
| "/wp-admin/" | |
| ] | |
| }, | |
| "action": { | |
| "pass": "applications/wp_direct" | |
| } | |
| }, | |
| { | |
| "action": { | |
| "share": "/var/apphome/wordpress", | |
| "fallback": { | |
| "pass": "applications/wp_index" | |
| } | |
| } | |
| } | |
| ] | |
| }, | |
| "applications": { | |
| "wp_direct": { | |
| "type": "php", | |
| "options": { | |
| "file": "/etc/php.ini", | |
| "admin": { | |
| "upload_max_filesize": "20M" | |
| } | |
| }, | |
| "environment": { | |
| "DB_HOST": "mariadb" | |
| }, | |
| "user": "wordpress", | |
| "group": "wordpress", | |
| "root": "/var/apphome/wordpress" | |
| }, | |
| "wp_index": { | |
| "type": "php", | |
| "options": { | |
| "file": "/etc/php.ini", | |
| "admin": { | |
| "upload_max_filesize": "20M" | |
| } | |
| }, | |
| "environment": { | |
| "DB_HOST": "mariadb" | |
| }, | |
| "user": "wordpress", | |
| "group": "wordpress", | |
| "root": "/var/apphome/wordpress", | |
| "script": "index.php" | |
| } | |
| }, | |
| "settings": { | |
| "http": { | |
| "header_read_timeout": 10, | |
| "body_read_timeout": 10, | |
| "send_timeout": 10, | |
| "idle_timeout": 120, | |
| "max_body_size": 6291456, | |
| "static": { | |
| "mime_types": { | |
| "text/plain": [ | |
| ".log", | |
| "README", | |
| "CHANGES" | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.7" | |
| services: | |
| mariadb: | |
| image: mariadb:latest | |
| ports: | |
| - 3306:3306 | |
| restart: always | |
| volumes: | |
| - ./db-volume:/var/lib/mysql | |
| environment: | |
| MYSQL_USER: wordpressdev | |
| MYSQL_PASSWORD: wordpressdev | |
| MYSQL_DATABASE: wordpress | |
| MYSQL_ROOT_PASSWORD: devpassword | |
| wordpress: | |
| image: YOURIMAGETAG:latest | |
| environment: | |
| DB_USER: wordpressdev | |
| volumes: | |
| - ../wordpress:/var/apphome/wordpress | |
| - ../vendor:/var/apphome/vendor | |
| ports: | |
| - 8044:8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM nginx/unit:1.16.0-php7.3 | |
| RUN mkdir /var/apphome/ && groupadd -r wpgroup && useradd --no-log-init -r -g wpgroup wpuser && \ | |
| chown -R wpuser:wpgroup /var/apphome/ && \ | |
| apt-get update && apt-get install --no-install-recommends --no-install-suggests -y php7.3-mysql php7.3-gd | |
| COPY wordpress /var/apphome | |
| RUN chown -R wordpress:wordpress /var/apphome/ | |
| COPY .unit.conf.json /docker-entrypoint.d/.unit.conf.json | |
| CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "applications": { | |
| "wp": { | |
| "type": "php", | |
| "environment": { | |
| "DB_HOST": "mariadb" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -ex | |
| case $1 in | |
| "dev") | |
| echo "Building local image and mounting code base..." | |
| docker build -t YOURIMAGETAG:latest . | |
| docker-compose up | |
| ;; | |
| "stop") | |
| echo "Stopping services..." | |
| docker-compose down | |
| docker rm --force dev_wordpress_1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment