From cca6a84591bc9b36c70e0bf9313e2549197d6098 Mon Sep 17 00:00:00 2001 From: cytopia Date: Wed, 27 Sep 2017 19:01:49 +0200 Subject: [PATCH 1/8] REL-0.10 Apache 2.2 based on official Apache Docker --- .ci/.lib.sh | 53 ++++ .ci/00.sh | 58 ++++ .ci/01.sh | 72 +++++ .ci/start-ci.sh | 56 ++++ .travis.yml | 325 +---------------------- Dockerfile | 123 +++++++-- README.md | 202 ++++++++++---- build/docker-build.sh | 8 + build/docker-rebuild.sh | 8 + build/docker-start.sh | 6 +- data/docker-entrypoint.sh | 495 +++++++++++++++++++++++++++++++++++ data/supervisord.conf | 26 ++ data/vhost-gen/conf.yml | 126 +++++++++ data/vhost-gen/main.yml | 126 +++++++++ scripts/docker-entrypoint.sh | 178 ------------- scripts/docker-install.sh | 315 ---------------------- 16 files changed, 1296 insertions(+), 881 deletions(-) create mode 100755 .ci/.lib.sh create mode 100755 .ci/00.sh create mode 100755 .ci/01.sh create mode 100755 .ci/start-ci.sh create mode 100755 data/docker-entrypoint.sh create mode 100644 data/supervisord.conf create mode 100644 data/vhost-gen/conf.yml create mode 100644 data/vhost-gen/main.yml delete mode 100755 scripts/docker-entrypoint.sh delete mode 100755 scripts/docker-install.sh diff --git a/.ci/.lib.sh b/.ci/.lib.sh new file mode 100755 index 0000000..a47cfa2 --- /dev/null +++ b/.ci/.lib.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +### +### Variables +### +CWD="$( dirname "${0}" )" + + +### +### Run +### +run() { + _cmd="${1}" + + _red="\033[0;31m" + _green="\033[0;32m" + _yellow="\033[0;33m" + _reset="\033[0m" + _user="$(whoami)" + + printf "${_yellow}[%s] ${_red}%s \$ ${_green}${_cmd}${_reset}\n" "$(hostname)" "${_user}" + sh -c "LANG=C LC_ALL=C ${_cmd}" +} + + + +### +### Get 15 character random word +### +function get_random_name() { + local chr=(a b c d e f g h i j k l m o p q r s t u v w x y z) + local len="${#chr[@]}" + local name= + + for i in {1..15}; do + rand="$( shuf -i 0-${len} -n 1 )" + rand=$(( rand - 1 )) + name="${name}${chr[$rand]}" + i="${i}" # simply to get rid of shellcheck complaints + done + echo "${name}" +} + + +DOCKER_IMAGE="$( grep 'image=".*"' "${CWD}/../Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +DOCKER_VENDOR="$( grep 'vendor=".*"' "${CWD}/../Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +# shellcheck disable=SC2034 +DOCKER_NAME="${DOCKER_VENDOR}/${DOCKER_IMAGE}" diff --git a/.ci/00.sh b/.ci/00.sh new file mode 100755 index 0000000..6b25c23 --- /dev/null +++ b/.ci/00.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + + +### +### Load Library +### +# shellcheck disable=SC1090 +. ${CWD}/.lib.sh + + + +### +### Preparation +### +RAND_DIR="$( mktemp -d )" +RAND_NAME="$( get_random_name )" +echo "hello world" > "${RAND_DIR}/index.html" + + +### +### Build container +### +run "docker build -t ${DOCKER_NAME} ${CWD}/.." + + +### +### Startup container +### +run "docker run -d --rm \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + -p 127.0.0.1:80:80 \ + -e DEBUG_ENTRYPOINT=2 \ + -e DEBUG_RUNTIME=1 \ + -e NEW_UID=$( id -u ) \ + -e NEW_GID=$( id -g ) \ + --name ${RAND_NAME} ${DOCKER_NAME}" + + +### +### Tests +### +sleep 5 +run "docker ps" +run "docker logs ${RAND_NAME}" +run "curl localhost" +run "curl localhost | grep 'hello world'" + + +### +### Cleanup +### +run "docker stop ${RAND_NAME}" diff --git a/.ci/01.sh b/.ci/01.sh new file mode 100755 index 0000000..03158cb --- /dev/null +++ b/.ci/01.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + + +### +### Load Library +### +# shellcheck disable=SC1090 +. ${CWD}/.lib.sh + + + +### +### Preparation +### +RAND_DIR="$( mktemp -d )" +RAND_NAME1="$( get_random_name )" +RAND_NAME2="$( get_random_name )" +echo " "${RAND_DIR}/index.php" + + +### +### Build container +### +run "docker build -t ${DOCKER_NAME} ${CWD}/.." + + +### +### Startup container +### +run "docker run -d --rm \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + -e DEBUG_ENTRYPOINT=1 \ + -e NEW_UID=$( id -u ) \ + -e NEW_GID=$( id -g ) \ + --name ${RAND_NAME1} cytopia/php-fpm-5.6" + +run "docker run -d --rm \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + -p 127.0.0.1:80:80 \ + -e DEBUG_ENTRYPOINT=2 \ + -e DEBUG_RUNTIME=1 \ + -e NEW_UID=$( id -u ) \ + -e NEW_GID=$( id -g ) \ + -e PHP_FPM_ENABLE=1 \ + -e PHP_FPM_SERVER_ADDR=${RAND_NAME1} \ + -e PHP_FPM_SERVER_PORT=9000 \ + --link ${RAND_NAME1} \ + --name ${RAND_NAME2} ${DOCKER_NAME}" + + +### +### Tests +### +sleep 5 +run "docker ps" +run "docker logs ${RAND_NAME1}" +run "docker logs ${RAND_NAME2}" +run "curl localhost" +run "curl localhost | grep 'hello world php'" + + +### +### Cleanup +### +run "docker stop ${RAND_NAME1}" +run "docker stop ${RAND_NAME2}" diff --git a/.ci/start-ci.sh b/.ci/start-ci.sh new file mode 100755 index 0000000..5ce0b04 --- /dev/null +++ b/.ci/start-ci.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +### +### Variables +### + +IFS=$'\n' + +# Current directory +CWD="$( dirname "${0}" )" + +declare -a TESTS=() + + +### +### Sanity checks +### + +# Check Dockerfile +if [ ! -f "${CWD}/../Dockerfile" ]; then + echo "Dockerfile not found in: ${CWD}/../Dockerfile." + exit 1 +fi + +# Check docker Name +if ! grep -q 'image=".*"' "${CWD}/../Dockerfile" > /dev/null 2>&1; then + echo "No 'image' LABEL found" + exit +fi + + +### +### Run tests +### + +# Get all [0-9]+.sh test files +FILES="$( find ${CWD} -regex "${CWD}/[0-9].+\.sh" | sort -u )" +for f in ${FILES}; do + TESTS+=("${f}") +done + +# Start a single test +if [ "${#}" -eq "1" ]; then + sh -c "${TESTS[${1}]}" + +# Run all tests +else + for i in "${TESTS[@]}"; do + echo "sh -c ${CWD}/${i}" + sh -c "${i}" + done +fi diff --git a/.travis.yml b/.travis.yml index d430f69..f3a49eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ -language: python -python: - - 2.7 +### +### Enable sudo (required for docker service) +### +sudo: required + ### ### Add services @@ -13,35 +15,8 @@ services: ### Global variables ### env: - global: - - MY_DOCKER_NAME="my-httpd-docker" - - -### -### Install -### -install: - - docker version - - # Build my docker - - docker build -t cytopia/${MY_DOCKER_NAME} . - - # Pull docker dependencies - - docker pull cytopia/php-fpm-5.6 - - docker pull cytopia/mysql-5.5 - - # Create directories - - mkdir -p ~/www - - mkdir -p ~/tmp/host-mysql-sock - - chmod 777 ~/www - - chmod 777 ~/tmp/host-mysql-sock - - # Add html and php files - - echo "Static Html" > ~/www/index.html - - echo "" > ~/www/index.php - - echo " ~/www/mysql_127.php - - echo " ~/www/mysql_rem.php - - echo " ~/www/mysql_ip.php + - S1=0 + - S1=1 ### @@ -61,288 +36,4 @@ before_script: ### Test ### script: - - ## - ## 01.) [a](DEBUG) Test plain docker - ## - - docker run - -p 127.0.0.1:80:80 - -e DEBUG_COMPOSE_ENTRYPOINT=1 - --name ${MY_DOCKER_NAME} cytopia/${MY_DOCKER_NAME} & - - sleep 5 - - - docker ps - - - curl localhost - - curl localhost | grep 'It works' - - - docker stop "$( docker ps | grep "${MY_DOCKER_NAME}" | awk '{print $1}' )" - - docker rm "${MY_DOCKER_NAME}" - ## - ## 01.) [b](SILENT) Test plain docker - ## - - docker run - -p 127.0.0.1:80:80 - --name ${MY_DOCKER_NAME} cytopia/${MY_DOCKER_NAME} & - - sleep 5 - - - docker ps - - - curl localhost - - curl localhost | grep 'It works' - - - docker stop "$( docker ps | grep "${MY_DOCKER_NAME}" | awk '{print $1}' )" - - docker rm "${MY_DOCKER_NAME}" - - - ## - ## 02.) [a](DEBUG) Test docker with external mounted directory - ## - - docker run - -p 127.0.0.1:80:80 - -v ~/www:/var/www/html - -e DEBUG_COMPOSE_ENTRYPOINT=1 - --name ${MY_DOCKER_NAME} cytopia/${MY_DOCKER_NAME} & - - sleep 5 - - - docker ps - - - curl localhost - - curl localhost | grep 'Static Html' - - - curl http://localhost/index.php - - curl http://localhost/index.php | grep ' @@ -13,38 +10,114 @@ LABEL \ image="apache-2.2" \ vendor="cytopia" \ license="MIT" \ - build-date="2017-08-30" + build-date="2017-09-27" -# Copy scripts -COPY ./scripts/docker-install.sh / -COPY ./scripts/docker-entrypoint.sh / +### +### Installation +### +# required packages +RUN set -x \ + && apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests -y \ + autoconf \ + gcc \ + make \ + python-yaml \ + supervisor \ + wget \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get purge -y --auto-remove -# Install -RUN /docker-install.sh +# mod-proxy-fcgi +RUN set -x \ + && wget --no-check-certificate -O mod-proxy-fcgi.tar.gz https://github.com/devilbox/mod-proxy-fcgi/archive/master.tar.gz \ + && tar xvfz mod-proxy-fcgi.tar.gz \ + && cd mod-proxy-fcgi-master \ + && autoconf \ + && ./configure \ + && make \ + && make install \ + && cd .. \ + && rm -rf mod-proxy-fcgi* +# vhost-gen +RUN set -x \ + && wget --no-check-certificate -O vhost_gen.tar.gz https://github.com/devilbox/vhost-gen/archive/master.tar.gz \ + && tar xfvz vhost_gen.tar.gz \ + && cd vhost-gen-master \ + && make install \ + && cd .. \ + && rm -rf vhost*gen* -## -## Ports -## +# watcherd +RUN set -x \ + && wget --no-check-certificate -O /usr/bin/watcherd https://raw.githubusercontent.com/devilbox/watcherd/master/watcherd \ + && chmod +x /usr/bin/watcherd + +# cleanup +RUN set -x \ + && apt-get update \ + && apt-get remove -y \ + autoconf \ + gcc \ + make \ + wget \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get purge -y --auto-remove + +# Add custom config directive to httpd server +RUN set -x \ + && ( \ + echo "ServerName localhost"; \ + echo "LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"; \ + echo "NameVirtualHost *:80"; \ + echo "Include /etc/httpd/conf.d/*.conf"; \ + echo "Include /etc/httpd/custom.d/*.conf"; \ + echo "Include /etc/apache-2.2.d/*.conf"; \ + echo "Include conf/extra/httpd-default.conf"; \ + ) >> /usr/local/apache2/conf/httpd.conf + +# create directories +RUN set -x \ + && mkdir -p /etc/apache-2.2.d \ + && mkdir -p /etc/httpd/conf.d \ + && mkdir -p /etc/httpd/custom.d \ + && mkdir -p /var/www/default/htdocs \ + && mkdir -p /shared/httpd \ + && chmod 0775 /shared/httpd \ + && chown daemon:daemon /shared/httpd + + +### +### Copy files +### +COPY ./data/vhost-gen/conf.yml /etc/vhost-gen/conf.yml +COPY ./data/vhost-gen/main.yml /etc/vhost-gen/main.yml +COPY ./data/supervisord.conf /etc/supervisord.conf +COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh + + +### +### Ports +### EXPOSE 80 -## -## Volumes -## -VOLUME /var/log/httpd +### +### Volumes +### +VOLUME /shared/httpd -## -## Become apache in order to have mounted files -## with apache user rights -## -User apache +### +### Signals +### +STOPSIGNAL SIGTERM -## -## Entrypoint -## +### +### Entrypoint +### ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/README.md b/README.md index c66bc26..4ba7e13 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,181 @@ -# Apache 2.2 Docker +# Apache 2.4 Docker -**Latest build:** 2017-08-30 +[![Devilbox](https://raw.githubusercontent.com/cytopia/devilbox/master/.devilbox/www/htdocs/assets/img/devilbox_80.png)](https://github.com/cytopia/devilbox) + +This Docker image is part of the **[devilbox](https://github.com/cytopia/devilbox)**. -[![Build Status](https://travis-ci.org/cytopia/docker-apache-2.2.svg?branch=master)](https://travis-ci.org/cytopia/docker-apache-2.2) [![](https://images.microbadger.com/badges/version/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/image/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/license/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") +**[Apache 2.2](https://github.com/cytopia/docker-apache-2.2) | Apache 2.4 | [Nginx stable](https://github.com/cytopia/docker-nginx-stable) | [Nginx mainline](https://github.com/cytopia/docker-nginx-mainline)** -[![cytopia/apache-2.2](http://dockeri.co/image/cytopia/apache-2.2)](https://hub.docker.com/r/cytopia/apache-2.2/) +[![Build Status](https://travis-ci.org/cytopia/docker-apache-2.4.svg?branch=master)](https://travis-ci.org/cytopia/docker-apache-2.4) [![](https://images.microbadger.com/badges/version/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") [![](https://images.microbadger.com/badges/image/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") [![](https://images.microbadger.com/badges/license/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") -**Apache 2.2 | [Apache 2.4](https://github.com/cytopia/docker-apache-2.4) | [Nginx stable](https://github.com/cytopia/docker-nginx-stable) | [Nginx mainline](https://github.com/cytopia/docker-nginx-mainline)** +This image is based on the official **[Apache 2.4](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically** when adding new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd]()** and **[vhost-gen]()**. + +From a users perspective, you mount your local project directory into the Docker under `/shared/httpd`. Any directory then created in your local project directory wil spawn a new virtual host by the same name. Additional settings such as custom server names, PHP-FPM or even different Apache templates per project are supported as well. ---- -**Apache 2.2 Docker on CentOS 6** +Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.4)**: -[![Devilbox](https://raw.githubusercontent.com/cytopia/devilbox/master/.devilbox/www/htdocs/assets/img/devilbox_80.png)](https://github.com/cytopia/devilbox) +[![cytopia/apache-2.4](http://dockeri.co/image/cytopia/apache-2.4)](https://hub.docker.com/r/cytopia/apache-2.4/) -This docker image is part of the **[devilbox](https://github.com/cytopia/devilbox)** +**Latest build:** 2017-09-27 ---- + +## Usage + +#### Automated virtual hosts + +1. Automated virtual hosts can be enabled by providing `-e MASS_VHOST_ENABLE=1`. +2. You should mount a local project directory into the Docker under `/shared/httpd` (`-v /local/path:/shared/httpd`). +3. You can optionally specify a global server name suffix via e.g.: `-e MASS_VHOST_TLD=.local` +4. You can optionally specify a global subdirectory from which the virtual host will servve the documents via e.g.: `-e MASS_VHOST_DOCROOT=www` +4. Allow the Docker to expose its port via `-p 80:80`. +5. Have DNS names point to the IP address the docker runs on (e.g. via `/etc/hosts`) + +With the above described settings, whenever you create a local directory under your projects dir, such as `/local/path/mydir`, there will be a new virtual host created by the same name `http://mydir`. You can also specify a global suffix for the vhost names via `-e MASS_VHOST_TLD=.local`, afterwards your above created vhost would be reachable via `http://mydir.local`. + +Just to give you a few examples: + +**Assumption:** `/local/path` is mounted to `/shared/httpd` + +| Directory | `MASS_VHOST_DOCROOT` | `MASS_VHOST_TLD` | Serving from (*) | Via | +|-----------|----------------------|------------------|--------------------------|----------------------| +| work1/ | htdocs/ | | /local/path/work1/htdocs | http://work1 | +| work1/ | www/ | | /local/path/work1/www | http://work1 | +| work1/ | htdocs/ | .loc | /local/path/work1/htdocs | http://work1.loc | +| work1/ | www/ | .loc | /local/path/work1/www | http://work1.loc | + +(*) This refers to the directory on your host computer + +**Assumption:** `/tmp` is mounted to `/shared/httpd` + +| Directory | `MASS_VHOST_DOCROOT` | `MASS_VHOST_TLD` | Serving from (*) | Via | +|-----------|----------------------|------------------|--------------------------|----------------------| +| api/ | htdocs/ | | /tmp/api/htdocs | http://api | +| api/ | www/ | | /tmp/api/www | http://api | +| api/ | htdocs/ | .test.com | /tmp/api/htdocs | http://api.test.com | +| api/ | www/ | .test.com | /tmp/api/www | http://api.test.com | + +(*) This refers to the directory on your host computer + +You would start it as follows: + +```shell +docker run -it \ + -p 80:80 \ + -e MASS_VHOST_ENABLE=1 \ + -e MASS_VHOST_DOCROOT=www \ + -e MASS_VHOST_TLD=.local \ + -v /local/path:/shared/httpd \ + devilbox/apache-2.4 +``` + +#### Customization per virtual host + +Each virtual host is generated from templates by **[vhost-gen](https://github.com/devilbox/vhost-gen/tree/master/etc/templates)**. As `vhost-gen` is really flexible and allows combining multiple templates, you can copy and alter an existing template and then place it in a subdirectory of your project folder. The subdirectory is specified by `MASS_VHOST_TPL`. + +**Assumption:** `/local/path` is mounted to `/shared/httpd` + +| Directory | `MASS_VHOST_TPL` | Templates are then read from (*) | +|-----------|------------------|------------------------------| +| work1/ | cfg/ | /local/path/work1/cfg/ | +| api/ | cfg/ | /local/path/api/cfg/ | +| work1/ | conf/ | /local/path/work1/conf/ | +| api/ | conf/ | /local/path/api/conf/ | + +(*) This refers to the directory on your host computer + +#### Customizing the default virtual host + +The default virtual host can also be overwritten with a custom template. Use `MAIN_VHOST_TPL` variable in order to set the subdirectory to look for template files. + +#### Enabling PHP-FPM + +PHP-FPM is not included inside this Docker container, but can be enabled to contact a remote PHP-FPM server. To do so, you must enable it and at least specify the remote PHP-FPM server address (hostname or IP address). Additionally you must mount the data dir under the same path into the PHP-FPM docker container as it is mounted into the web server. + +**Note:** When PHP-FPM is enabled, it is enabled for the default virtual host as well as for all other automatically created mass virtual hosts. + +#### Disabling the default virtual host + +If you only want to server you custom projects and don't need the default virtual host, you can disable it by `-e MAIN_VHOST_DISABLE=1`. + + ## Options -### Environmental variables +#### Environmental variables + +This Docker container adds a lot of injectables in order to customize it to your needs. See the table below for a detailed description. -#### Required environmental variables +##### Required environmental variables -- None +`PHP_FPM_SERVER_ADDR` is required when enabling PHP FPM. -#### Optional environmental variables +##### Optional environmental variables (general) | Variable | Type | Default | Description | |----------|------|---------|-------------| -| DEBUG_COMPOSE_ENTRYPOINT | bool | `0` | Show shell commands executed during start.
Value: `0` or `1` | -| TIMEZONE | string | `UTC` | Set docker OS timezone.
(Example: `Europe/Berlin`) | -| PHP_FPM_ENABLE | bool | `0` | Enable PHP-FPM support.
Value: `0` or `1` | -| PHP_FPM_SERVER_ADDR | string | `` | IP address or hostname of remote PHP-FPM server | -| PHP_FPM_SERVER_PORT | int | `9000` | Port of remote PHP-FPM server | -| CUSTOM_HTTPD_CONF_DIR | string | `` | Specify a directory inside the docker where Apache should look for additional config files (`*.conf`).

This will overwrite the default virtual host including the PHP FPM settings.

Make sure to mount this directory from your host into the docker. | +| DEBUG_ENTRYPOINT | int | `0` | Show settings and shell commands executed during startup.
Values:
`0`: Off
`1`: Show settings
`2`: Show settings and commands | +| DEBUG_RUNTIME | bool | `0` | Be verbose during runtime.
Value: `0` or `1` | +| DOCKER_LOGS | bool | `0` | When set to `1` will redirect error and access logs to Docker logs (`stderr` and `stdout`) instead of file inside container.
Value: `0` or `1` | +| TIMEZONE | string | `UTC` | Set docker OS timezone.
(Example: `Europe/Berlin`) | +| NEW_UID | int | `101` | Assign the default Apache user a new UID. This is useful if you you mount your document root and want to match the file permissions to the one of your local user. Set it to your host users uid (see `id` for your uid). | +| NEW_GID | int | `101` | This is useful if you you mount your document root and want to match the file permissions to the one of your local user group. Set it to your host user groups gid (see `id` for your gid). | +| PHP_FPM_ENABLE | bool | `0` | Enable PHP-FPM for the default vhost and the mass virtual hosts. | +| PHP_FPM_SERVER_ADDR | string | `` | IP address or hostname of remote PHP-FPM server.
Required when enabling PHP. | +| PHP_FPM_SERVER_PORT | int | `9000` | Port of remote PHP-FPM server | + +##### Optional environmental variables (default vhost) -### Default mount points +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| MAIN_VHOST_DISABLE | bool | `0` | By default there is a standard (catch-all) vhost configured to accept requests served from `/var/www/default/htdocs`. If you want to disable it, set the value to `1`.
Note:The `htdocs` dir name can be changed with `MAIN_VHOST_DOCROOT`. See below. | +| MAIN_VHOST_DOCROOT | string | `htdocs`| This is the directory name appended to `/var/www/default/` from which the default virtual host will serve its files.
Default:
`/var/www/default/htdocs`
Example:
`MAIN_VHOST_DOCROOT=www`
Doc root: `/var/www/default/www` | +| MAIN_VHOST_TPL | string | `cfg` | Directory within th default vhost base path (`/var/www/default`) to look for templates to overwrite virtual host settings. See [vhost-gen](https://github.com/devilbox/vhost-gen/tree/master/etc/templates) for available template files.
Resulting default path:
`/var/www/default/cfg` | +| MAIN_VHOST_STATUS_ENABLE | bool | `0` | Enable httpd status page. | +| MAIN_VHOST_STATUS_ALIAS | string | `/httpd-status` | Set the alias under which the httpd server should serve its status page. | -| Docker | Description | -|--------|-------------| -| /var/log/httpd | Apache log dir | +##### Optional environmental variables (mass vhosts) + +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| MASS_VHOST_ENABLE | bool | `0` | You can enable mass virtual hosts by setting this value to `1`. Mass virtual hosts will be created for each directory present in `/shared/httpd` by the same name including a top-level domain suffix (which could also be a domain+tld). See `MASS_VHOST_TLD` for how to set it. | +| MASS_VHOST_TLD | string | `.local`| This string will be appended to the server name (which is built by its directory name) for mass virtual hosts and together build the final domain.
Default:`.local`
Example:
Path: `/shared/httpd/temp`
`MASS_VHOST_TLD=.lan`
Server name: `temp.lan`
Example:
Path:`/shared/httpd/api`
`MASS_VHOST_TLD=.example.com`
Server name: `api.example.com` | +| MASS_VHOST_DOCROOT | string | `htdocs`| This is a subdirectory within your project dir under each project from which the web server will serve its files.
`/shared/httpd//$MASS_VHOST_DOCROOT/`
Default:
`/shared/httpd//htdocs/` | +| MASS_VHOST_TPL | string | `cfg` | Directory within your new virtual host to look for templates to overwrite virtual host settings. See [vhost-gen](https://github.com/devilbox/vhost-gen/tree/master/etc/templates) for available template files.
`/shared/httpd//$MASS_VHOST_TPL/`
Resulting default path:
`/shared/httpd//cfg/` | + + +#### Available mount points +| Docker | Description | +|---------------------|-------------| +| /etc/apache-2.4.d | Mount this directory to add outside configuration files (`*.conf`) to Apache | +| /var/www/default | Apache default virtual host base path (contains by default `htdocs/` and `cfg/` | +| /shared/httpd | Apache mass virtual host root directory | -### Default ports + +#### Default ports | Docker | Description | |--------|-------------| | 80 | Apache listening Port | -## Usage +## Examples -**1. Serve static files** +#### 1. Serve static files Mount your local directort `~/my-host-www` into the docker and server those files. + +**Note:** Files will be server from `~/my-host-www/htdocs`. ```bash -$ docker run -i -p 80:80 -v ~/my-host-www:/var/www/html -t cytopia/apache-2.2 +$ docker run -d -p 80:80 -v ~/my-host-www:/var/www/default -t cytopia/apache-2.4 ``` -**2. Serve PHP files with PHP-FPM** +#### 2. Serve PHP files with PHP-FPM -Note, for this to work, the `~/my-host-www` dir must be mounted into the Apache docker as well as into the php-fpm docker. +Note, for this to work, the `~/my-host-www` dir must be mounted into the Apache Docker as well as into the php-fpm docker. You can also attach other PHP-FPM version: [PHP-FPM 5.4](https://github.com/cytopia/docker-php-fpm-5.4), [PHP-FPM 5.5](https://github.com/cytopia/docker-php-fpm-5.5), [PHP-FPM 5.6](https://github.com/cytopia/docker-php-fpm-5.6), [PHP-FPM 7.0](https://github.com/cytopia/docker-php-fpm-7.0) or [PHP-FPM 7.1](https://github.com/cytopia/docker-php-fpm-7.1) @@ -70,21 +183,20 @@ Each PHP-FPM docker also has the option to enable Xdebug and more, see their res ```bash # Start the PHP-FPM docker, mounting the same diectory -$ docker run -d -p 9000 -v ~/my-host-www:/var/www/html --name php cytopia/php-fpm-5.6 +$ docker run -d -p 9000 -v ~/my-host-www:/var/www/default --name php cytopia/php-fpm-5.6 -# Start the Apache docker, linking it to the PHP-FPM docker -$ docker run -i \ +# Start the Apache Docker, linking it to the PHP-FPM docker +$ docker run -d \ -p 80:80 \ - -v ~/my-host-www:/var/www/html \ + -v ~/my-host-www:/var/www/default \ -e PHP_FPM_ENABLE=1 \ -e PHP_FPM_SERVER_ADDR=php \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ - -t cytopia/apache-2.2 + -t cytopia/apache-2.4 ``` - -**3. Fully functional LEMP stack** +#### 3. Fully functional LEMP stack Same as above, but also add a MySQL docker and link it into Apache. ```bash @@ -102,24 +214,24 @@ $ docker run -d \ # connections from within the php docker. $ docker run -d \ -p 9000:9000 \ - -v ~/my-host-www:/var/www/html \ + -v ~/my-host-www:/var/www/default \ -e FORWARD_PORTS_TO_LOCALHOST=3306:mysql:3306 \ --name php \ cytopia/php-fpm-5.6 -# Start the Apache docker, linking it to the PHP-FPM docker -$ docker run -i \ +# Start the Apache Docker, linking it to the PHP-FPM docker +$ docker run -d \ -p 80:80 \ - -v ~/my-host-www:/var/www/html \ + -v ~/my-host-www:/var/www/default \ -e PHP_FPM_ENABLE=1 \ -e PHP_FPM_SERVER_ADDR=php \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ --link mysql \ - -t cytopia/apache-2.2 + -t cytopia/apache-2.4 ``` -**4. Ultimate pre-configured docker-compose setup** +#### 4. Ultimate pre-configured docker-compose setup Have a look at the **[devilbox](https://github.com/cytopia/devilbox)** for a fully-customizable docker-compose variant. @@ -135,9 +247,9 @@ It allows any of the following combinations: ## Version ``` -Server version: Apache/2.2.15 (Unix) -Server built: Aug 15 2017 19:44:58 -Server's Module Magic Number: 20051115:25 -Server loaded: APR 1.3.9, APR-Util 1.3.9 +Server version: Apache/2.2.34 (Unix) +Server built: Sep 19 2017 01:07:59 +Server's Module Magic Number: 20051115:43 +Server loaded: APR 1.5.1, APR-Util 1.5.4 Server MPM: Prefork ``` diff --git a/build/docker-build.sh b/build/docker-build.sh index 4709378..d168e6b 100755 --- a/build/docker-build.sh +++ b/build/docker-build.sh @@ -41,6 +41,13 @@ NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk DATE="$( date '+%Y-%m-%d' )" +### +### Update Base +### +MY_BASE="$( grep 'FROM[[:space:]].*:.*' "${CWD}/Dockerfile" | sed 's/FROM\s*//g' )" +run "docker pull ${MY_BASE}" + + ### ### Build ### @@ -61,6 +68,7 @@ INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built| docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" docker rm "my_tmp_${NAME}" +INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space echo "${INFO}" sed -i'' '/##[[:space:]]Version/q' "${CWD}/README.md" diff --git a/build/docker-rebuild.sh b/build/docker-rebuild.sh index ac25d9c..73a812f 100755 --- a/build/docker-rebuild.sh +++ b/build/docker-rebuild.sh @@ -41,6 +41,13 @@ NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk DATE="$( date '+%Y-%m-%d' )" +### +### Update Base +### +MY_BASE="$( grep 'FROM[[:space:]].*:.*' "${CWD}/Dockerfile" | sed 's/FROM\s*//g' )" +run "docker pull ${MY_BASE}" + + ### ### Build ### @@ -61,6 +68,7 @@ INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built| docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" docker rm "my_tmp_${NAME}" +INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space echo "${INFO}" sed -i'' '/##[[:space:]]Version/q' "${CWD}/README.md" diff --git a/build/docker-start.sh b/build/docker-start.sh index 8d9147a..608f0e8 100755 --- a/build/docker-start.sh +++ b/build/docker-start.sh @@ -42,4 +42,8 @@ NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk ### ### Run ### -run "docker run -i -t cytopia/${NAME}" +_args="" +if [ "${#}" != "0" ]; then + _args="${*}" +fi +run "docker run -it ${_args} cytopia/${NAME}" diff --git a/data/docker-entrypoint.sh b/data/docker-entrypoint.sh new file mode 100755 index 0000000..6cb8cee --- /dev/null +++ b/data/docker-entrypoint.sh @@ -0,0 +1,495 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + + +################################################################################ +# VARIABLES +################################################################################ + +MY_USER="daemon" +MY_GROUP="daemon" +DEBUG_COMMANDS=0 + +### +### Defaults +### + + +################################################################################ +# FUNCTIONS +################################################################################ + +run() { + _cmd="${1}" + _debug="0" + + _red="\033[0;31m" + _green="\033[0;32m" + _reset="\033[0m" + _user="$(whoami)" + + + # If 2nd argument is set and enabled, allow debug command + if [ "${#}" = "2" ]; then + _debug="${2}" + fi + + if [ "${DEBUG_COMMANDS}" -gt "1" ] || [ "${_debug}" -gt "1" ]; then + printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}" + fi + sh -c "LANG=C LC_ALL=C ${_cmd}" +} + +log() { + _lvl="${1}" + _msg="${2}" + + _clr_ok="\033[0;32m" + _clr_info="\033[0;34m" + _clr_warn="\033[0;33m" + _clr_err="\033[0;31m" + _clr_rst="\033[0m" + + if [ "${_lvl}" = "ok" ]; then + printf "${_clr_ok}[OK] %s${_clr_rst}\n" "${_msg}" + elif [ "${_lvl}" = "info" ]; then + printf "${_clr_info}[INFO] %s${_clr_rst}\n" "${_msg}" + elif [ "${_lvl}" = "warn" ]; then + printf "${_clr_warn}[WARN] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr + elif [ "${_lvl}" = "err" ]; then + printf "${_clr_err}[ERR] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr + else + printf "${_clr_err}[???] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr + fi +} + +# Test if argument is an integer. +# +# @param mixed +# @return integer 0: is int | 1: not an int +isint() { + echo "${1}" | grep -Eq '^([0-9]|[1-9][0-9]*)$' +} + + + +################################################################################ +# SETTING INJECTABLES +################################################################################ + +### +### Debug Mode Entrypoint? +### +if set | grep '^DEBUG_ENTRYPOINT=' >/dev/null 2>&1; then + if [ "${DEBUG_ENTRYPOINT}" = "1" ]; then + DEBUG_COMMANDS=1 + elif [ "${DEBUG_ENTRYPOINT}" = "2" ]; then + DEBUG_COMMANDS=2 + else + log "err" "Wrong value for \$DEBUG_ENTRYPOINT: '${DEBUG_ENTRYPOINT}'" + log "err" "Allowed values: 0, 1 and 2" + exit 1 + fi +fi + + +### +### Debug Mode Runtime? +### +_RUNTIME_DEBUG_RUNTIME="0" +if set | grep '^DEBUG_RUNTIME=' >/dev/null 2>&1; then + if [ "${DEBUG_RUNTIME}" = "1" ]; then + _RUNTIME_DEBUG_RUNTIME="1" + fi +fi + + +### +### Use docker logs? +### +_RUNTIME_DOCKER_LOGS="0" +if ! set | grep '^DOCKER_LOGS=' >/dev/null 2>&1; then + log "info" "\$DOCKER_LOGS not set. Logging errors and access to log files inside container." +else + if [ "${DOCKER_LOGS}" = "1" ]; then + log "info" "\$DOCKER_LOGS enabled. Redirecting errors and access to Docker log (stderr and stdout)." + _RUNTIME_DOCKER_LOGS="1" + elif [ "${DOCKER_LOGS}" = "0" ]; then + log "info" "\$DOCKER_LOGS explicitly disabled. Logging errors and access to log files inside container." + else + log "err" "Invalid value for \$DOCKER_LOGS: ${DOCKER_LOGS}" + log "err" "Must be '1' (for On) or '0' (for Off)" + exit 1 + fi +fi + + +### +### Timezone +### +if ! set | grep '^TIMEZONE=' >/dev/null 2>&1; then + log "info" "\$TIMEZONE not set." +else + if [ -f "/usr/share/zoneinfo/${TIMEZONE}" ]; then + # Unix Time + log "info" "Setting docker timezone to: ${TIMEZONE}" + run "ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime" + else + log "err" "Invalid timezone for \$TIMEZONE." + log "err" "\$TIMEZONE: '${TIMEZONE}' does not exist." + exit 1 + fi +fi +log "info" "Docker date set to: $(date)" + + +### +### Change UID +### +if ! set | grep '^NEW_UID=' >/dev/null 2>&1; then + log "info" "\$NEW_UID not set. Keeping default uid of '${MY_USER}'." +else + if ! isint "${NEW_UID}"; then + log "err" "\$NEW_UID is not an integer: '${NEW_UID}'" + exit 1 + else + if _user_line="$( getent passwd "${NEW_UID}" )"; then + _user_name="${_user_line%%:*}" + if [ "${_user_name}" != "${MY_USER}" ]; then + log "warn" "User with ${NEW_UID} already exists: ${_user_name}" + log "info" "Changing UID of ${_user_name} to 9999" + run "usermod -u 9999 ${_user_name}" + fi + fi + log "info" "Changing user '${MY_USER}' uid to: ${NEW_UID}" + run "usermod -u ${NEW_UID} ${MY_USER}" + fi +fi + + +### +### Change GID +### +if ! set | grep '^NEW_GID=' >/dev/null 2>&1; then + log "info" "\$NEW_GID not set. Keeping default gid of '${MY_GROUP}'." +else + if ! isint "${NEW_GID}"; then + log "err" "\$NEW_GID is not an integer: '${NEW_GID}'" + exit 1 + else + if _group_line="$( getent group "${NEW_GID}" )"; then + _group_name="${_group_line%%:*}" + if [ "${_group_name}" != "${MY_GROUP}" ]; then + log "warn" "Group with ${NEW_GID} already exists: ${_group_name}" + log "info" "Changing GID of ${_group_name} to 9999" + run "groupmod -g 9999 ${_group_name}" + fi + fi + log "info" "Changing group '${MY_GROUP}' gid to: ${NEW_GID}" + run "groupmod -g ${NEW_GID} ${MY_GROUP}" + fi +fi + + + +################################################################################ +# MAIN VHOST INJECTABLES +################################################################################ + +### +### Disable default vhost? +### +_RUNTIME_MAIN_VHOST_ENABLE=1 +if ! set | grep '^MAIN_VHOST_DISABLE=' >/dev/null 2>&1; then + log "info" "\$MAIN_VHOST_DISABLE not set. Not disabling the default vhost." +else + if [ "${MAIN_VHOST_DISABLE}" = "0" ]; then + log "info" "\$MAIN_VHOST_DISABLE set to 0. Not disabling the default vhost." + elif [ "${MAIN_VHOST_DISABLE}" = "1" ]; then + log "info" "\$MAIN_VHOST_DISABLE set to 1. Disabling the default vhost." + _RUNTIME_MAIN_VHOST_ENABLE=0 + else + log "err" "\$MAIN_VHOST_DISABLE is set to ${MAIN_VHOST_DISABLE}, but must be 0 or 1." + exit 1 + fi +fi + + +### +### Set main vhost document root sufix +### +_RUNTIME_MAIN_VHOST_DOCROOT="htdocs" +if ! set | grep '^MAIN_VHOST_DOCROOT=' >/dev/null 2>&1; then + log "info" "\$MAIN_VHOST_DOCROOT not specified. Keeping default: ${_RUNTIME_MAIN_VHOST_DOCROOT}" +else + log "info" "\$MAIN_VHOST_DOCROOT is set to: ${MAIN_VHOST_DOCROOT}" + _RUNTIME_MAIN_VHOST_DOCROOT="${MAIN_VHOST_DOCROOT}" +fi + + +### +### Set main vhost template directory +### +_RUNTIME_MAIN_VHOST_TPL="cfg" +if ! set | grep '^MAIN_VHOST_TPL=' >/dev/null 2>&1; then + log "info" "\$MAIN_VHOST_TPL not specified. Keeping default: ${_RUNTIME_MAIN_VHOST_TPL}" +else + log "info" "\$MAIN_VHOST_TPL is set to: ${_RUNTIME_MAIN_VHOST_TPL}" + _RUNTIME_MAIN_VHOST_TPL="${MAIN_VHOST_TPL}" +fi + + +### +### Set main vhost status page +### +_RUNTIME_MAIN_VHOST_STATUS_ENABLE=0 +if ! set | grep '^MAIN_VHOST_STATUS_ENABLE=' >/dev/null 2>&1; then + log "info" "\$MAIN_VHOST_STATUS_ENABLE not specified. Disabling httpd status." +else + if [ "${MAIN_VHOST_STATUS_ENABLE}" = "0" ]; then + log "info" "\$MAIN_VHOST_STATUS_ENABLE set to 0. Disabling httpd status." + elif [ "${MAIN_VHOST_STATUS_ENABLE}" = "1" ]; then + log "info" "\$MAIN_VHOST_STATUS_ENABLE set to 1. Enabling httpd status." + _RUNTIME_MAIN_VHOST_STATUS_ENABLE="${MAIN_VHOST_STATUS_ENABLE}" + else + log "err" "\$MAIN_VHOST_STATUS_ENABLE is set to ${MAIN_VHOST_STATUS_ENABLE}, but must be 0 or 1." + exit 1 + fi +fi + +if [ "${_RUNTIME_MAIN_VHOST_STATUS_ENABLE}" -eq "1" ]; then + _RUNTIME_MAIN_VHOST_STATUS_ALIAS="/httpd-status" + if ! set | grep '^MAIN_VHOST_STATUS_ALIAS=' >/dev/null 2>&1; then + log "info" "\$MAIN_VHOST_STATUS_ALIAS not specified. Keeping default: ${_RUNTIME_MAIN_VHOST_STATUS_ALIAS}." + else + log "info" "Setting httpd status page to: '\$MAIN_VHOST_STATUS_ALIAS'" + _RUNTIME_MAIN_VHOST_STATUS_ALIAS="${MAIN_VHOST_STATUS_ALIAS}" + fi +fi + + + +################################################################################ +# MASS VHOST INJECTABLES +################################################################################ + +### +### Enable mass vhosts? +### +_RUNTIME_MASS_VHOST_ENABLE=0 +if ! set | grep '^MASS_VHOST_ENABLE=' >/dev/null 2>&1; then + log "info" "\$MASS_VHOST_ENABLE not set. Disabbling mass vhosts." +else + if [ "${MASS_VHOST_ENABLE}" = "0" ]; then + log "info" "\$MASS_VHOST_ENABLE set to 0. Disabling mass vhosts." + elif [ "${MASS_VHOST_ENABLE}" = "1" ]; then + log "info" "\$MASS_VHOST_ENABLE set to 1. Enabling mass vhosts." + _RUNTIME_MASS_VHOST_ENABLE=1 + else + log "err" "\$MASS_VHOST_ENABLE is set to ${MASS_VHOST_ENABLE}, but must be 0 or 1." + exit 1 + fi +fi + + +### +### Set mass vhost TLD +### +_RUNTIME_MASS_VHOST_TLD=".local" +if ! set | grep '^MASS_VHOST_TLD=' >/dev/null 2>&1; then + log "info" "\$MASS_VHOST_TLD not set. Keeping default: ${_RUNTIME_MASS_VHOST_TLD}" +else + log "info" "\$MASS_VHOST_TLD set to: ${MASS_VHOST_TLD}" + _RUNTIME_MASS_VHOST_TLD="${MASS_VHOST_TLD}" +fi + + +### +### Set mass vhost document root sufix +### +_RUNTIME_MASS_VHOST_DOCROOT="htdocs" +if ! set | grep '^MASS_VHOST_DOCROOT=' >/dev/null 2>&1; then + log "info" "\$MASS_VHOST_DOCROOT not specified. Keeping default: ${_RUNTIME_MASS_VHOST_DOCROOT}" +else + log "info" "\$MASS_VHOST_DOCROOT is set to: ${MASS_VHOST_DOCROOT}" + _RUNTIME_MASS_VHOST_DOCROOT="${MASS_VHOST_DOCROOT}" +fi + + +### +### Set mass vhost template directory +### +_RUNTIME_MASS_VHOST_TPL="cfg" +if ! set | grep '^MASS_VHOST_TPL=' >/dev/null 2>&1; then + log "info" "\$MASS_VHOST_TPL not specified. Keeping default: ${_RUNTIME_MASS_VHOST_TPL}" +else + log "info" "\$MASS_VHOST_TPL is set to: ${_RUNTIME_MASS_VHOST_TPL}" + _RUNTIME_MASS_VHOST_TPL="${MASS_VHOST_TPL}" +fi + + + +################################################################################ +# SHARED VHOST INJECTABLES (MAIN & MASS) +################################################################################ + +### +### Enable PHP-FPM +### +_RUNTIME_PHP_FPM_ENABLE=0 +if ! set | grep '^PHP_FPM_ENABLE=' >/dev/null 2>&1; then + log "info" "\$PHP_FPM_ENABLE not set. Not enabling PHP-FPM." +else + if [ "${PHP_FPM_ENABLE}" = "0" ]; then + log "info" "\$PHP_FPM_ENABLE set to 0. Not enabling PHP-FPM." + elif [ "${PHP_FPM_ENABLE}" = "1" ]; then + log "info" "\$PHP_FPM_ENABLE set to 1. Enabling PHP-FPM." + _RUNTIME_PHP_FPM_ENABLE=1 + + ### + ### PHP-FPM Addres + ### + # Check if PHP-FPM address is set + if ! set | grep '^PHP_FPM_SERVER_ADDR=' >/dev/null 2>&1; then + log "err" "PHP-FPM is enabled, but \$PHP_FPM_SERVER_ADDR not specified." + exit 1 + fi + # Check if PHP-FPM address is not empty + if [ -z "${PHP_FPM_SERVER_ADDR}" ]; then + log "err" "PHP-FPM enabled, but \$PHP_FPM_SERVER_ADDR is empty." + exit 1 + fi + log "info" "\$PHP_FPM_SERVER_ADDR is set to: ${PHP_FPM_SERVER_ADDR}" + + else + log "err" "\$PHP_FPM_ENABLE is set to ${PHP_FPM_ENABLE}, but must be 0 or 1." + exit 1 + fi +fi + + +### +### PHP-FPM Port +### +_RUNTIME_PHP_FPM_SERVER_PORT="9000" +if ! set | grep '^PHP_FPM_SERVER_PORT=' >/dev/null 2>&1; then + log "info" "\$PHP_FPM_SERVER_PORT not specified. Keeping default: ${_RUNTIME_PHP_FPM_SERVER_PORT}" +else + # Check if PHP-FPM port is not empty + if [ -z "${PHP_FPM_SERVER_PORT}" ]; then + log "err" "\$PHP_FPM_SERVER_PORT specified, but is empty." + exit 1 + fi + # Check if PHP-FPM port is an integer + if ! isint "${PHP_FPM_SERVER_PORT}"; then + log "err" "\$PHP_FPM_SERVER_PORT is not a valid integer: ${PHP_FPM_SERVER_PORT}" + exit 1 + fi + # Check if PHP-FPM port is in port range + if [ "${PHP_FPM_SERVER_PORT}" -lt 1 ] || [ "${PHP_FPM_SERVER_PORT}" -gt 65535 ] ; then + log "err" "\$PHP_FPM_SERVER_PORT is not in a valid port range: ${PHP_FPM_SERVER_PORT}" + exit 1 + fi + log "info" "\$PHP_FPM_SERVER_PORT is set to: ${PHP_FPM_SERVER_PORT}" + _RUNTIME_PHP_FPM_SERVER_PORT="${_RUNTIME_PHP_FPM_SERVER_PORT}" +fi + + + +################################################################################ +# SETUP CONFIGURATION +################################################################################ + +### +### Default and/or mass vhost must be enabled (at least one of them) +### +if [ "${_RUNTIME_MAIN_VHOST_ENABLE}" -eq "0" ] && [ "${_RUNTIME_MASS_VHOST_ENABLE}" -eq "0" ]; then + log "err" "Default vhost and mass vhosts are disabled." + exit 1 +fi + + +### +### vhost-gen +### +if [ "${_RUNTIME_PHP_FPM_ENABLE}" -eq "1" ]; then + run "sed -i'' 's/__PHP_ENABLE__/yes/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__PHP_ENABLE__/yes/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's/__PHP_ADDR__/${PHP_FPM_SERVER_ADDR}/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__PHP_ADDR__/${PHP_FPM_SERVER_ADDR}/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's/__PHP_PORT__/${_RUNTIME_PHP_FPM_SERVER_PORT}/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__PHP_PORT__/${_RUNTIME_PHP_FPM_SERVER_PORT}/g' /etc/vhost-gen/main.yml" +else + run "sed -i'' 's/__PHP_ENABLE__/no/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__PHP_ENABLE__/no/g' /etc/vhost-gen/main.yml" +fi + +if [ "${_RUNTIME_DOCKER_LOGS}" -eq "1" ]; then + run "sed -i'' 's/__DOCKER_LOGS_ERROR__/yes/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__DOCKER_LOGS_ERROR__/yes/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's/__DOCKER_LOGS_ACCESS__/yes/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__DOCKER_LOGS_ACCESS__/yes/g' /etc/vhost-gen/main.yml" +else + run "sed -i'' 's/__DOCKER_LOGS_ERROR__/no/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__DOCKER_LOGS_ERROR__/no/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's/__DOCKER_LOGS_ACCESS__/no/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__DOCKER_LOGS_ACCESS__/no/g' /etc/vhost-gen/main.yml" +fi + + +### +### Main vhost +### +if [ "${_RUNTIME_MAIN_VHOST_ENABLE}" -eq "1" ]; then + + # Enable status page? + if [ "${_RUNTIME_MAIN_VHOST_STATUS_ENABLE}" -eq "1" ]; then + run "sed -i'' 's/__ENABLE_STATUS__/yes/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's|__STATUS_ALIAS__|${_RUNTIME_MAIN_VHOST_STATUS_ALIAS}|g' /etc/vhost-gen/main.yml" + else + run "sed -i'' 's/__ENABLE_STATUS__/yes/g' /etc/vhost-gen/main.yml" + fi + + # Debug creation? + if [ "${DEBUG_COMMANDS}" -gt "0" ]; then + _verb="-v" + else + _verb="" + fi + run "vhost_gen.py -n localhost -p /var/www/default/${_RUNTIME_MAIN_VHOST_DOCROOT} -c /etc/vhost-gen/main.yml -o /var/www/default/${_RUNTIME_MAIN_VHOST_TPL} ${_verb} -d -s" +fi + + +### +### Mass vhost (watcher config setup) +### +if [ "${_RUNTIME_MASS_VHOST_ENABLE}" -eq "1" ]; then + run "sed -i'' 's/__DOCROOT_SUFFIX__/${_RUNTIME_MASS_VHOST_DOCROOT}/g' /etc/vhost-gen/conf.yml" + run "sed -i'' 's/__TLD__/${_RUNTIME_MASS_VHOST_TLD}/g' /etc/vhost-gen/conf.yml" +fi + + + +################################################################################ +# RUN +################################################################################ + +### +### Supervisor or plain +### +if [ "${_RUNTIME_MASS_VHOST_ENABLE}" -eq "1" ]; then + if [ "${_RUNTIME_DEBUG_RUNTIME}" -gt "0" ]; then + _verb="-v" + else + _verb="" + fi + run "sed -i'' 's/__MASS_VHOST_TPL__/${_RUNTIME_MASS_VHOST_TPL}/g' /etc/supervisord.conf" + run "sed -i'' 's/__VERBOSE__/${_verb}/g' /etc/supervisord.conf" + exec /usr/bin/supervisord -c /etc/supervisord.conf +else + exec httpd-foreground +fi diff --git a/data/supervisord.conf b/data/supervisord.conf new file mode 100644 index 0000000..0ea9ca3 --- /dev/null +++ b/data/supervisord.conf @@ -0,0 +1,26 @@ +[supervisord] +user=root +nodaemon=true + +[program:apache] +command=httpd-foreground +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +stdout_events_enabled=true +stderr_events_enabled=true + +[program:watcherd] +command=watcherd -v -p /shared/httpd -a "vhost_gen.py -p %%p -n %%n -o %%p/__MASS_VHOST_TPL__/ -s __VERBOSE__" -d "rm /etc/httpd/custom.d/%%n.conf" -t "/usr/local/apache2/bin/httpd -k restart" +#startsecs = 0 +#autorestart = false +#startretries = 1 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +stdout_events_enabled=true +stderr_events_enabled=true diff --git a/data/vhost-gen/conf.yml b/data/vhost-gen/conf.yml new file mode 100644 index 0000000..2e34947 --- /dev/null +++ b/data/vhost-gen/conf.yml @@ -0,0 +1,126 @@ +--- +# Generic vhost generator configuration file. +# Location: /etc/vhost-gen/conf.yml +# +# See: https://github.com/devilbox/vhost-gen +# +# If not specified or file is missing the following +# default values will be merged to your current (if any) +# configuration: +# +# server: nginx +# conf_dir: /etc/nginx/conf.d +# vhost: +# port: +# name: +# prefix: +# suffix: +# docroot: +# suffix: +# log: +# access: +# prefix: +# stdout: no +# error: +# prefix: +# stderr: no +# dir: +# create: no +# path: /var/log/nginx +# listen: +# enable: no +# php_fpm: +# enable: no +# address: php +# port: 9000 +# alias: [] +# deny: [] +# server_status: +# enable: no +# alias: /server-status + + +# The server type determines which template +# from etc/templates/ will be chosen. +# Allowed server types: +# server: apache22 +# server: apache24 +# server: nginx +server: apache22 + +# Where to store the generated configuration files. +# This must be a directory the web server will read +# configuration files from. +conf_dir: /etc/httpd/custom.d + +# Vhost definition +vhost: + # What port should this virtual host listen on + port: 80 + + # The virtual host name is specified as an command line argument + # to vhost_gen.py via '-n', however it is possible + # to prepend and/or append additional name strings. + name: + prefix: + suffix: __TLD__ + # The document root directory is specified as an command line argument + # to vhost_gen.py via '-p', however it is possible + # to prepend another subdirectory here. + docroot: + suffix: __DOCROOT_SUFFIX__ + # Log definition + log: + # Log file settings (error/access log) + access: + # By default the vhost name is used for log file names. + # You can also prepand an additional string to the access log + # as shown here: + # -access.log + prefix: '' + # For use inside a docker container, enable this in order + # to redirect the access log to stdout instead of to file. + # NOTE: When enabling this, the prefix will have no effect and the access + # log will be stored under /tmp/www-access.log which will be a symlink of + # /dev/stdout + stdout: __DOCKER_LOGS_ACCESS__ + error: + # By default the vhost name is used for log file names. + # You can also prepand an additional string to the error log + # as shown here: + # -error.log + prefix: '' + # For use inside a docker container, enable this in order + # to redirect the error log to stderr instead of to file. + # NOTE: When enabling this, the prefix will have no effect and the error + # log will be stored under /tmp/www-error.log which will be a symlink of + # /dev/stderr + stderr: __DOCKER_LOGS_ERROR__ + # Directory to store log files in. + # Also define if the directory should be created or not. + dir: + create: yes + path: /var/log/apache-2.2 + # Enable PHP-FPM + php_fpm: + enable: __PHP_ENABLE__ + # Hostname or IP address + address: __PHP_ADDR__ + port: __PHP_PORT__ + # Create additional aliases + alias: + - alias: /devilbox-api/ + path: /var/www/default/api + # Allow cross-domain-request to this alias from the hosts/origin + # specified by the below defined regex + xdomain_request: + enable: yes + origin: 'http(s)?://(.*)$' + # Denies locations + deny: + - alias: '/\.git' + - alias: '/\.ht.*' + # Enable server status on the following alias + server_status: + enable: no + alias: /httpd-status diff --git a/data/vhost-gen/main.yml b/data/vhost-gen/main.yml new file mode 100644 index 0000000..4bbd611 --- /dev/null +++ b/data/vhost-gen/main.yml @@ -0,0 +1,126 @@ +--- +# Generic vhost generator configuration file. +# Location: /etc/vhost-gen/conf.yml +# +# See: https://github.com/devilbox/vhost-gen +# +# If not specified or file is missing the following +# default values will be merged to your current (if any) +# configuration: +# +# server: nginx +# conf_dir: /etc/nginx/conf.d +# vhost: +# port: +# name: +# prefix: +# suffix: +# docroot: +# suffix: +# log: +# access: +# prefix: +# stdout: no +# error: +# prefix: +# stderr: no +# dir: +# create: no +# path: /var/log/nginx +# listen: +# enable: no +# php_fpm: +# enable: no +# address: php +# port: 9000 +# alias: [] +# deny: [] +# server_status: +# enable: no +# alias: /server-status + + +# The server type determines which template +# from etc/templates/ will be chosen. +# Allowed server types: +# server: apache22 +# server: apache24 +# server: nginx +server: apache22 + +# Where to store the generated configuration files. +# This must be a directory the web server will read +# configuration files from. +conf_dir: /etc/httpd/conf.d + +# Vhost definition +vhost: + # What port should this virtual host listen on + port: 80 + + # The virtual host name is specified as an command line argument + # to vhost_gen.py via '-n', however it is possible + # to prepend and/or append additional name strings. + name: + prefix: + suffix: + # The document root directory is specified as an command line argument + # to vhost_gen.py via '-p', however it is possible + # to prepend another subdirectory here. + docroot: + suffix: + # Log definition + log: + # Log file settings (error/access log) + access: + # By default the vhost name is used for log file names. + # You can also prepand an additional string to the access log + # as shown here: + # -access.log + prefix: 'default' + # For use inside a docker container, enable this in order + # to redirect the access log to stdout instead of to file. + # NOTE: When enabling this, the prefix will have no effect and the access + # log will be stored under /tmp/www-access.log which will be a symlink of + # /dev/stdout + stdout: __DOCKER_LOGS_ACCESS__ + error: + # By default the vhost name is used for log file names. + # You can also prepand an additional string to the error log + # as shown here: + # -error.log + prefix: 'default' + # For use inside a docker container, enable this in order + # to redirect the error log to stderr instead of to file. + # NOTE: When enabling this, the prefix will have no effect and the error + # log will be stored under /tmp/www-error.log which will be a symlink of + # /dev/stderr + stderr: __DOCKER_LOGS_ERROR__ + # Directory to store log files in. + # Also define if the directory should be created or not. + dir: + create: yes + path: /var/log/apache-2.2 + # Enable PHP-FPM + php_fpm: + enable: __PHP_ENABLE__ + # Hostname or IP address + address: __PHP_ADDR__ + port: __PHP_PORT__ + # Create additional aliases + alias: + - alias: /devilbox-api/ + path: /var/www/default/api + # Allow cross-domain-request to this alias from the hosts/origin + # specified by the below defined regex + xdomain_request: + enable: no + origin: 'http(s)?://(.*)$' + # Denies locations + deny: + - alias: '/\.git' + - alias: '/\.ht.*' + # Enable server status on the following alias + server_status: + enable: __ENABLE_STATUS__ + alias: __STATUS_ALIAS__ diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh deleted file mode 100755 index 43efabc..0000000 --- a/scripts/docker-entrypoint.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/bin/sh -eu - -### -### Variables -### -DEBUG_COMMANDS=0 - -HTTPD_CONF="/etc/httpd/conf/httpd.conf" - - - -### -### Functions -### -runsu() { - _cmd="${1}" - _debug="0" - - _red="\033[0;31m" - _green="\033[0;32m" - _reset="\033[0m" - _user="$(whoami)" - - # If 2nd argument is set and enabled, allow debug command - if [ "${#}" = "2" ]; then - if [ "${2}" = "1" ]; then - _debug="1" - fi - fi - - - if [ "${DEBUG_COMMANDS}" = "1" ] || [ "${_debug}" = "1" ]; then - printf "${_red}%s \$ ${_green}sudo ${_cmd}${_reset}\n" "${_user}" - fi - - /usr/local/bin/gosu root sh -c "LANG=C LC_ALL=C ${_cmd}" -} - - -log() { - _lvl="${1}" - _msg="${2}" - - _clr_ok="\033[0;32m" - _clr_info="\033[0;34m" - _clr_warn="\033[0;33m" - _clr_err="\033[0;31m" - _clr_rst="\033[0m" - - if [ "${_lvl}" = "ok" ]; then - printf "${_clr_ok}[OK] %s${_clr_rst}\n" "${_msg}" - elif [ "${_lvl}" = "info" ]; then - printf "${_clr_info}[INFO] %s${_clr_rst}\n" "${_msg}" - elif [ "${_lvl}" = "warn" ]; then - printf "${_clr_warn}[WARN] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr - elif [ "${_lvl}" = "err" ]; then - printf "${_clr_err}[ERR] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr - else - printf "${_clr_err}[???] %s${_clr_rst}\n" "${_msg}" 1>&2 # stdout -> stderr - fi -} - - - -################################################################################ -# BOOTSTRAP -################################################################################ - -if set | grep '^DEBUG_COMPOSE_ENTRYPOINT=' >/dev/null 2>&1; then - if [ "${DEBUG_COMPOSE_ENTRYPOINT}" = "1" ]; then - DEBUG_COMMANDS=1 - fi -fi - - -################################################################################ -# MAIN ENTRY POINT -################################################################################ - -### -### Adjust timezone -### - -if ! set | grep '^TIMEZONE=' >/dev/null 2>&1; then - log "warn" "\$TIMEZONE not set." -else - if [ -f "/usr/share/zoneinfo/${TIMEZONE}" ]; then - # Unix Time - log "info" "Setting docker timezone to: ${TIMEZONE}" - runsu "rm /etc/localtime" - runsu "ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime" - else - log "err" "Invalid timezone for \$TIMEZONE." - log "err" "\$TIMEZONE: '${TIMEZONE}' does not exist." - exit 1 - fi -fi -log "info" "Docker date set to: $(date)" - - - -### -### Prepare PHP-FPM -### -if ! set | grep '^PHP_FPM_ENABLE=' >/dev/null 2>&1; then - log "info" "\$PHP_FPM_ENABLE not set. PHP-FPM support disabled." -else - if [ "${PHP_FPM_ENABLE}" = "1" ]; then - - # PHP-FPM address - if ! set | grep '^PHP_FPM_SERVER_ADDR=' >/dev/null 2>&1; then - log "err" "PHP-FPM enabled, but \$PHP_FPM_SERVER_ADDR not set." - exit 1 - fi - if [ "${PHP_FPM_SERVER_ADDR}" = "" ]; then - log "err" "PHP-FPM enabled, but \$PHP_FPM_SERVER_ADDR is empty." - exit 1 - fi - - # PHP-FPM port - if ! set | grep '^PHP_FPM_SERVER_PORT=' >/dev/null 2>&1; then - log "info" "PHP-FPM enabled, but \$PHP_FPM_SERVER_PORT not set." - lgo "info" "Defaulting PHP-FPM port to 9000" - PHP_FPM_SERVER_PORT="9000" - elif [ "${PHP_FPM_SERVER_PORT}" = "" ]; then - log "info" "PHP-FPM enabled, but \$PHP_FPM_SERVER_PORT is empty." - lgo "info" "Defaulting PHP-FPM port to 9000" - PHP_FPM_SERVER_PORT="9000" - fi - - PHP_FPM_CONFIG="/etc/httpd/conf.d/php-fpm.conf" - PHP_FPM_HANDLER="/usr/local/bin/php-fcgi" - - # Enable - log "info" "Enabling PHP-FPM at: ${PHP_FPM_SERVER_ADDR}:${PHP_FPM_SERVER_PORT}" - runsu "echo '#### PHP-FPM config ####' > ${PHP_FPM_CONFIG}" - runsu "echo '' >> ${PHP_FPM_CONFIG}" - runsu "echo 'AddType application/x-httpd-fastphp5 .php' >> ${PHP_FPM_CONFIG}" - runsu "echo 'Action application/x-httpd-fastphp5 /php5-fcgi' >> ${PHP_FPM_CONFIG}" - runsu "echo 'Alias /php5-fcgi ${PHP_FPM_HANDLER}' >> ${PHP_FPM_CONFIG}" - runsu "echo 'FastCgiExternalServer ${PHP_FPM_HANDLER} -host ${PHP_FPM_SERVER_ADDR}:${PHP_FPM_SERVER_PORT} -pass-header Authorization' >> ${PHP_FPM_CONFIG}" - - - PHP_FPM_HANDLER_DIR="$( dirname "${PHP_FPM_HANDLER}" )" - if [ ! -d "${PHP_FPM_HANDLER_DIR}" ]; then - runsu "mkdir -p ${PHP_FPM_HANDLER_DIR} )" - fi - runsu "echo '#!/bin/sh' > ${PHP_FPM_HANDLER}" - runsu "echo '' >> ${PHP_FPM_HANDLER}" - runsu "echo 'PHPRC=/etc/' >> ${PHP_FPM_HANDLER}" - runsu "echo '#PHPRC=\"/etc/php.ini\"' >> ${PHP_FPM_HANDLER}" - runsu "echo 'export PHPRC' >> ${PHP_FPM_HANDLER}" - runsu "echo 'export PHP_FCGI_MAX_REQUESTS=5000' >> ${PHP_FPM_HANDLER}" - runsu "echo 'export PHP_FCGI_CHILDREN=8' >> ${PHP_FPM_HANDLER}" - runsu "echo 'exec /usr/bin/php-cgi' >> ${PHP_FPM_HANDLER}" - fi -fi - - - -### -### Add new Apache configuration dir -### -if ! set | grep '^CUSTOM_HTTPD_CONF_DIR=' >/dev/null 2>&1; then - log "info" "\$CUSTOM_HTTPD_CONF_DIR not set. No custom include directory added." -else - # Tell apache to also look into this custom dir for configuratoin - log "info" "Adding custom include directory: ${CUSTOM_HTTPD_CONF_DIR}" - runsu "sed -i'' 's|^Include[[:space:]]*conf\.d/.*$|Include ${CUSTOM_HTTPD_CONF_DIR}/*.conf|g' ${HTTPD_CONF}" -fi - - - -### -### Start -### -log "info" "Starting $(/usr/sbin/httpd -v 2>&1 | head -1)" -runsu "/usr/sbin/httpd -DFOREGROUND" "1" diff --git a/scripts/docker-install.sh b/scripts/docker-install.sh deleted file mode 100755 index 67279a0..0000000 --- a/scripts/docker-install.sh +++ /dev/null @@ -1,315 +0,0 @@ -#!/bin/sh -eu - - -## -## VARIABLES -## -VERSION_GOSU="1.2" -HTTPD_CONF="/etc/httpd/conf/httpd.conf" - - - - -MY_USER="apache" -MY_GROUP="apache" -MY_UID="48" -MY_GID="48" - - -## -## FUNCTIONS -## -print_headline() { - _txt="${1}" - _blue="\033[0;34m" - _reset="\033[0m" - - printf "${_blue}\n%s\n${_reset}" "--------------------------------------------------------------------------------" - printf "${_blue}- %s\n${_reset}" "${_txt}" - printf "${_blue}%s\n\n${_reset}" "--------------------------------------------------------------------------------" -} - -run() { - _cmd="${1}" - - _red="\033[0;31m" - _green="\033[0;32m" - _reset="\033[0m" - _user="$(whoami)" - - printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}" - sh -c "LANG=C LC_ALL=C ${_cmd}" -} - - -################################################################################ -# MAIN ENTRY POINT -################################################################################ - -## -## Adding Users -## -print_headline "1. Adding Users" -run "groupadd -g ${MY_GID} -r ${MY_GROUP}" -run "adduser ${MY_USER} -u ${MY_UID} -M -s /sbin/nologin -g ${MY_GROUP}" - - - -### -### Adding Repositories -### -### (required for mod_xsendfile) -print_headline "2. Adding Repository" -run "yum -y install epel-release" - - - -### -### Updating Packages -### -print_headline "3. Updating Packages Manager" -run "yum clean all" -run "yum -y check" -run "yum -y update" - - - -### -### Installing Packages -### -print_headline "4. Installing Packages" -run "yum -y install \ - httpd \ - mod_xsendfile \ - mod_proxy_fcgi \ - php \ - " -# PHP is required (pulls mod_php) so that `php_admin_value` -# is allowed inside apache directives - - - -### -### Configure Apache -### -### (Remove all custom config) -### -print_headline "5. Configure Apache" - -# Clean all configs -if [ ! -d "/etc/httpd/conf.d/" ]; then - run "mkdir -p /etc/httpd/conf.d/" -else - run "rm -rf /etc/httpd/conf.d/*" -fi - -# Apache 2.2 specific (make it like apache 2.4) -if [ ! -d "/etc/httpd/conf.modules.d/" ]; then - run "mkdir -p /etc/httpd/conf.modules.d/" -else - run "rm -rf /etc/httpd/conf.modules.d/*" -fi - -# Add Include directory (replace conf.d with conf.modules.d and add conf.d to the bottom) -run "sed -i'' 's|conf.d|conf.modules.d|g' ${HTTPD_CONF}" -run "echo 'Include conf.d/*.conf' >> ${HTTPD_CONF}" - - -# User and Group -run "sed -i'' 's/^User[[:space:]]*=.*$/User = ${MY_USER}/g' ${HTTPD_CONF}" -run "sed -i'' 's/^Group[[:space:]]*=.*$/Group = ${MY_GROUP}/g' ${HTTPD_CONF}" - -# Listen and ServerName -run "sed -i'' 's/^Listen[[:space:]].*$/Listen 0.0.0.0:80/g' ${HTTPD_CONF}" -run "sed -i'' 's/^#ServerName[[:space:]].*$/ServerName localhost:80/g' ${HTTPD_CONF}" - - -# Basics Modules (to be close to Apache 2.4) -run "echo 'LoadModule authn_dbd_module modules/mod_authn_dbd.so' > /etc/httpd/conf.modules.d/cytopia-basics.conf" -run "echo 'LoadModule dbd_module modules/mod_dbd.so' >> /etc/httpd/conf.modules.d/cytopia-basics.conf" -run "echo 'LoadModule dumpio_module modules/mod_dumpio.so' >> /etc/httpd/conf.modules.d/cytopia-basics.conf" -run "echo 'LoadModule filter_module modules/mod_filter.so' >> /etc/httpd/conf.modules.d/cytopia-basics.conf" -run "echo 'LoadModule reqtimeout_module modules/mod_reqtimeout.so' >> /etc/httpd/conf.modules.d/cytopia-basics.conf" -run "echo 'LoadModule unique_id_module modules/mod_unique_id.so' >> /etc/httpd/conf.modules.d/cytopia-basics.conf" -# PHP -run "echo 'LoadModule php5_module modules/libphp5.so' > /etc/httpd/conf.modules.d/cytopia-php.conf" -# Proxy FCGI (for PHP-FPM) -run "echo 'LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so' > /etc/httpd/conf.modules.d/cytopia-proxy.conf" -run "echo 'LoadModule proxy_scgi_module modules/mod_proxy_scgi.so' >> /etc/httpd/conf.modules.d/cytopia-proxy.conf" -# XSendfile -run "echo 'LoadModule xsendfile_module modules/mod_xsendfile.so' > /etc/httpd/conf.modules.d/cytopia-xsendfile.conf" - - - -# Add Custom http Configuration -{ - echo "CustomLog \"/var/log/httpd/access_log\" combined"; - echo "ErrorLog \"/var/log/httpd/error_log\""; - echo "LogLevel warn"; - echo; - - echo "AddDefaultCharset UTF-8"; - echo; - - echo "HostnameLookups Off"; - echo; - - echo "Timeout 60"; - echo "KeepAlive On"; - echo "KeepAliveTimeout 10"; - echo "MaxKeepAliveRequests 100"; - echo; - - echo "EnableMMAP Off"; - echo "EnableSendfile Off"; - echo; - - echo "XSendFile On"; - echo "XSendFilePath /var/www/html"; - echo; - -} > "/etc/httpd/conf.d/http-defaults.conf" - - -# Add Default vhost Configuration -{ - echo "NameVirtualHost *:80"; - echo; - - echo ""; - echo " ServerName localhost"; - echo " ServerAdmin root@localhost"; - echo; - - echo " ErrorLog /var/log/httpd/localhost-error.log"; - echo " CustomLog /var/log/httpd/localhost-access.log combined"; - echo; - - echo " DirectoryIndex index.html index.htm index.php"; - echo; - - echo " DocumentRoot \"/var/www/html\""; - echo; - - echo " "; - echo " DirectoryIndex index.html index.htm index.php"; - echo; - - echo " AllowOverride All"; - echo " Options All"; - echo; - - echo " RewriteEngine on"; - echo " RewriteBase /"; - echo; - - echo " Order allow,deny"; - echo " Allow from all"; - echo " "; - echo ""; - echo; - -} > "/etc/httpd/conf.d/localhost.conf" - -# Add test Page -if [ ! -d "/var/www/html" ]; then - run "mkdir -p /var/www/html" -else - run "rm -rf /var/www/html/*" -fi -run "echo '' > /var/www/html/index.php" -run "echo 'It works' > /var/www/html/index.html" -run "chown -R ${MY_USER}:${MY_GROUP} /var/www/html" - - - - - - - -### -### mod_fastcgi -### -print_headline "6. Installing mod_fastcgi" -run "yum -y install httpd-devel gcc" - -run "curl -SL -o /tmp/mod_fastcgi-2.4.7.tar.gz https://github.com/ceph/mod_fastcgi/archive/2.4.7-0910052141.tar.gz --retry 999 --retry-max-time 0 -C -" -run "mkdir /tmp/mod_fastcgi-2.4.7" -run "tar xvzf /tmp/mod_fastcgi-2.4.7.tar.gz --strip-components=1 --directory /tmp/mod_fastcgi-2.4.7" -run "cd /tmp/mod_fastcgi-2.4.7 && apxs -o mod_fastcgi.so -c *.c" -run "cp /tmp/mod_fastcgi-2.4.7/.libs/mod_fastcgi.so /etc/httpd/modules/" - -# Cleanup -run "yum -y remove \ - httpd-devel \ - gcc \ - apr-devel \ - apr-util-devel \ - cyrus-sasl \ - cyrus-sasl-devel \ - db4-cxx \ - db4-devel \ - expat-devel \ - openldap-devel \ - perl \ - perl-Module-Pluggable \ - perl-Pod-Escapes \ - perl-Pod-Simple \ - perl-libs \ - perl-version \ - \ - cloog-ppl \ - cpp \ - glibc-devel \ - glibc-headers \ - kernel-headers \ - libgomp \ - mpfr \ - ppl \ - " -run "yum -y remove httpd-devel" -run "rm -rf /tmp/mod_fastcgi-2.4.7*" - -run "echo 'LoadModule fastcgi_module modules/mod_fastcgi.so' > /etc/httpd/conf.modules.d/cytopia-fastcgi.conf" - - - - -### -### Installing Gosu -### -print_headline "7. Installing Gosu" -run "gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4" -run "curl -SL -o /usr/local/bin/gosu https://github.com/tianon/gosu/releases/download/${VERSION_GOSU}/gosu-amd64 --retry 999 --retry-max-time 0 -C -" -run "curl -SL -o /usr/local/bin/gosu.asc https://github.com/tianon/gosu/releases/download/${VERSION_GOSU}/gosu-amd64.asc --retry 999 --retry-max-time 0 -C -" -run "gpg --verify /usr/local/bin/gosu.asc" -run "rm /usr/local/bin/gosu.asc" -run "rm -rf /root/.gnupg/" -run "chown root /usr/local/bin/gosu" -run "chmod +x /usr/local/bin/gosu" -run "chmod +s /usr/local/bin/gosu" - - - -### -### Creating Mass VirtualHost dirs -### -print_headline "8. Creating Mass VirtualHost dirs" -run "mkdir -p /shared/httpd" -run "chmod 775 /shared/httpd" -run "chown ${MY_USER}:${MY_GROUP} /shared/httpd" - - - -### -### Cleanup unecessary packages -### -print_headline "9. Cleanup unecessary packages" -run "yum -y remove \ - dash \ - vim-minimal \ - tar \ - bzip2 \ - libtool \ - libss \ - " From add66f8ff571a9cc0d3340d165ca8d75d82bcf38 Mon Sep 17 00:00:00 2001 From: cytopia Date: Wed, 27 Sep 2017 19:08:24 +0200 Subject: [PATCH 2/8] REL-0.10 Fix Apache version in README --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4ba7e13..fa0f124 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,22 @@ -# Apache 2.4 Docker +# Apache 2.2 Docker [![Devilbox](https://raw.githubusercontent.com/cytopia/devilbox/master/.devilbox/www/htdocs/assets/img/devilbox_80.png)](https://github.com/cytopia/devilbox) This Docker image is part of the **[devilbox](https://github.com/cytopia/devilbox)**. -**[Apache 2.2](https://github.com/cytopia/docker-apache-2.2) | Apache 2.4 | [Nginx stable](https://github.com/cytopia/docker-nginx-stable) | [Nginx mainline](https://github.com/cytopia/docker-nginx-mainline)** +**Apache 2.2 | [Apache 2.4](https://github.com/cytopia/docker-apache-2.2) | [Nginx stable](https://github.com/cytopia/docker-nginx-stable) | [Nginx mainline](https://github.com/cytopia/docker-nginx-mainline)** -[![Build Status](https://travis-ci.org/cytopia/docker-apache-2.4.svg?branch=master)](https://travis-ci.org/cytopia/docker-apache-2.4) [![](https://images.microbadger.com/badges/version/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") [![](https://images.microbadger.com/badges/image/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") [![](https://images.microbadger.com/badges/license/cytopia/apache-2.4.svg)](https://microbadger.com/images/cytopia/apache-2.4 "apache-2.4") +[![Build Status](https://travis-ci.org/cytopia/docker-apache-2.2.svg?branch=master)](https://travis-ci.org/cytopia/docker-apache-2.2) [![](https://images.microbadger.com/badges/version/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/image/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/license/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") -This image is based on the official **[Apache 2.4](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically** when adding new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd]()** and **[vhost-gen]()**. +This image is based on the official **[Apache 2.2](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically** when adding new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd]()** and **[vhost-gen]()**. From a users perspective, you mount your local project directory into the Docker under `/shared/httpd`. Any directory then created in your local project directory wil spawn a new virtual host by the same name. Additional settings such as custom server names, PHP-FPM or even different Apache templates per project are supported as well. ---- -Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.4)**: +Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.2)**: -[![cytopia/apache-2.4](http://dockeri.co/image/cytopia/apache-2.4)](https://hub.docker.com/r/cytopia/apache-2.4/) +[![cytopia/apache-2.2](http://dockeri.co/image/cytopia/apache-2.2)](https://hub.docker.com/r/cytopia/apache-2.2/) **Latest build:** 2017-09-27 @@ -69,7 +69,7 @@ docker run -it \ -e MASS_VHOST_DOCROOT=www \ -e MASS_VHOST_TLD=.local \ -v /local/path:/shared/httpd \ - devilbox/apache-2.4 + devilbox/apache-2.2 ``` #### Customization per virtual host @@ -150,7 +150,7 @@ This Docker container adds a lot of injectables in order to customize it to your | Docker | Description | |---------------------|-------------| -| /etc/apache-2.4.d | Mount this directory to add outside configuration files (`*.conf`) to Apache | +| /etc/apache-2.2.d | Mount this directory to add outside configuration files (`*.conf`) to Apache | | /var/www/default | Apache default virtual host base path (contains by default `htdocs/` and `cfg/` | | /shared/httpd | Apache mass virtual host root directory | @@ -170,7 +170,7 @@ Mount your local directort `~/my-host-www` into the docker and server those file **Note:** Files will be server from `~/my-host-www/htdocs`. ```bash -$ docker run -d -p 80:80 -v ~/my-host-www:/var/www/default -t cytopia/apache-2.4 +$ docker run -d -p 80:80 -v ~/my-host-www:/var/www/default -t cytopia/apache-2.2 ``` #### 2. Serve PHP files with PHP-FPM @@ -193,7 +193,7 @@ $ docker run -d \ -e PHP_FPM_SERVER_ADDR=php \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ - -t cytopia/apache-2.4 + -t cytopia/apache-2.2 ``` #### 3. Fully functional LEMP stack @@ -228,7 +228,7 @@ $ docker run -d \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ --link mysql \ - -t cytopia/apache-2.4 + -t cytopia/apache-2.2 ``` #### 4. Ultimate pre-configured docker-compose setup From cc9224b2c061ca65c204cf97483d2b2f6b45c0a7 Mon Sep 17 00:00:00 2001 From: cytopia Date: Thu, 28 Sep 2017 18:19:50 +0200 Subject: [PATCH 3/8] REL-0.10 Consolidate conf dirs with other httpd Docker --- Dockerfile | 20 +++++++++++--------- README.md | 4 ++-- build/docker-build.sh | 5 ++--- build/docker-rebuild.sh | 5 ++--- data/docker-entrypoint.sh | 2 +- data/supervisord.conf | 2 +- data/vhost-gen/conf.yml | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index e8839e7..cbc6fa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,15 @@ FROM httpd:2.2 MAINTAINER "cytopia" -## -## Labels -## +### +### Labels +### LABEL \ name="cytopia's Apache 2.2 Image" \ image="apache-2.2" \ vendor="cytopia" \ license="MIT" \ - build-date="2017-09-27" + build-date="2017-09-28" ### @@ -20,6 +20,7 @@ LABEL \ # required packages RUN set -x \ && apt-get update \ + && apt-get upgrade -y \ && apt-get install --no-install-recommends --no-install-suggests -y \ autoconf \ gcc \ @@ -64,6 +65,7 @@ RUN set -x \ gcc \ make \ wget \ + && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* \ && apt-get purge -y --auto-remove @@ -73,17 +75,17 @@ RUN set -x \ echo "ServerName localhost"; \ echo "LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"; \ echo "NameVirtualHost *:80"; \ - echo "Include /etc/httpd/conf.d/*.conf"; \ - echo "Include /etc/httpd/custom.d/*.conf"; \ - echo "Include /etc/apache-2.2.d/*.conf"; \ echo "Include conf/extra/httpd-default.conf"; \ + echo "Include /etc/httpd-custom.d/*.conf"; \ + echo "Include /etc/httpd/conf.d/*.conf"; \ + echo "Include /etc/httpd/vhost.d/*.conf"; \ ) >> /usr/local/apache2/conf/httpd.conf # create directories RUN set -x \ - && mkdir -p /etc/apache-2.2.d \ + && mkdir -p /etc/httpd-custom.d \ && mkdir -p /etc/httpd/conf.d \ - && mkdir -p /etc/httpd/custom.d \ + && mkdir -p /etc/httpd/vhost.d \ && mkdir -p /var/www/default/htdocs \ && mkdir -p /shared/httpd \ && chmod 0775 /shared/httpd \ diff --git a/README.md b/README.md index fa0f124..4ad60e3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.2)**: [![cytopia/apache-2.2](http://dockeri.co/image/cytopia/apache-2.2)](https://hub.docker.com/r/cytopia/apache-2.2/) -**Latest build:** 2017-09-27 +**Latest build:** 2017-09-28 ---- @@ -150,7 +150,7 @@ This Docker container adds a lot of injectables in order to customize it to your | Docker | Description | |---------------------|-------------| -| /etc/apache-2.2.d | Mount this directory to add outside configuration files (`*.conf`) to Apache | +| /etc/httpd-custom.d | Mount this directory to add outside configuration files (`*.conf`) to Apache | | /var/www/default | Apache default virtual host base path (contains by default `htdocs/` and `cfg/` | | /shared/httpd | Apache mass virtual host root directory | diff --git a/build/docker-build.sh b/build/docker-build.sh index d168e6b..1e3762f 100755 --- a/build/docker-build.sh +++ b/build/docker-build.sh @@ -63,10 +63,9 @@ run "docker build -t cytopia/${NAME} ${CWD}" ### ### Retrieve information afterwards and Update README.md ### -docker run -d --name my_tmp_${NAME} -t cytopia/${NAME} +docker run -d --rm --name my_tmp_${NAME} -t cytopia/${NAME} INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built|Module|loaded|MPM)' )" -docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" -docker rm "my_tmp_${NAME}" +docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" > /dev/null INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space echo "${INFO}" diff --git a/build/docker-rebuild.sh b/build/docker-rebuild.sh index 73a812f..03e0e18 100755 --- a/build/docker-rebuild.sh +++ b/build/docker-rebuild.sh @@ -63,10 +63,9 @@ run "docker build --no-cache -t cytopia/${NAME} ${CWD}" ### ### Retrieve information afterwards and Update README.md ### -docker run -d --name my_tmp_${NAME} -t cytopia/${NAME} +docker run -d --rm --name my_tmp_${NAME} -t cytopia/${NAME} INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built|Module|loaded|MPM)' )" -docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" -docker rm "my_tmp_${NAME}" +docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" > /dev/null INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space echo "${INFO}" diff --git a/data/docker-entrypoint.sh b/data/docker-entrypoint.sh index 6cb8cee..fa5e7f7 100755 --- a/data/docker-entrypoint.sh +++ b/data/docker-entrypoint.sh @@ -266,7 +266,7 @@ if [ "${_RUNTIME_MAIN_VHOST_STATUS_ENABLE}" -eq "1" ]; then if ! set | grep '^MAIN_VHOST_STATUS_ALIAS=' >/dev/null 2>&1; then log "info" "\$MAIN_VHOST_STATUS_ALIAS not specified. Keeping default: ${_RUNTIME_MAIN_VHOST_STATUS_ALIAS}." else - log "info" "Setting httpd status page to: '\$MAIN_VHOST_STATUS_ALIAS'" + log "info" "Setting httpd status page to: '${MAIN_VHOST_STATUS_ALIAS}'" _RUNTIME_MAIN_VHOST_STATUS_ALIAS="${MAIN_VHOST_STATUS_ALIAS}" fi fi diff --git a/data/supervisord.conf b/data/supervisord.conf index 0ea9ca3..2266b1d 100644 --- a/data/supervisord.conf +++ b/data/supervisord.conf @@ -14,7 +14,7 @@ stdout_events_enabled=true stderr_events_enabled=true [program:watcherd] -command=watcherd -v -p /shared/httpd -a "vhost_gen.py -p %%p -n %%n -o %%p/__MASS_VHOST_TPL__/ -s __VERBOSE__" -d "rm /etc/httpd/custom.d/%%n.conf" -t "/usr/local/apache2/bin/httpd -k restart" +command=watcherd -v -p /shared/httpd -a "vhost_gen.py -p %%p -n %%n -o %%p/__MASS_VHOST_TPL__/ -s __VERBOSE__" -d "rm /etc/httpd/vhost.d/%%n.conf" -t "/usr/local/apache2/bin/httpd -k restart" #startsecs = 0 #autorestart = false #startretries = 1 diff --git a/data/vhost-gen/conf.yml b/data/vhost-gen/conf.yml index 2e34947..227412f 100644 --- a/data/vhost-gen/conf.yml +++ b/data/vhost-gen/conf.yml @@ -51,7 +51,7 @@ server: apache22 # Where to store the generated configuration files. # This must be a directory the web server will read # configuration files from. -conf_dir: /etc/httpd/custom.d +conf_dir: /etc/httpd/vhost.d # Vhost definition vhost: From 5ec546ef8dea39f5a34f011222e5b45c2da43fde Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 29 Sep 2017 21:38:23 +0200 Subject: [PATCH 4/8] REL-0.10 Autobuild via travis-ci --- .travis.yml | 89 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index f3a49eb..48290dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,12 @@ sudo: required +### +### Language +### +language: python + + ### ### Add services ### @@ -12,28 +18,83 @@ services: ### -### Global variables +### Build Matrix definition ### env: - - S1=0 - - S1=1 + global: + - IMAGE=devilbox/apache-2.2 + # travis encrypt DOCKER_USERNAME=user + # travis encrypt DOCKER_PASSWORD=pass + # Must be regenerated when repository name/owner changes + - secure: "NHoT/hlhTCkXvqkL9hfi7nmjv1HcQe/EexdklueBjhQcb14NxvRezAzNkqWPyanT+o9kGS6F+PmBIT2NswlSDhihDf/Ctbs1lCF7Ny9tixZnTNC00Ye6rOUPCZhNEC2fgd58uqcD54xdmjT2YywV4rYeYYBgyg8LTI63Uy6t+CeDVVZ5nsB8HQ+r/GC+aowFJKzREEfhq2zfE4C92xl2fqJXAYTyEbsM7BP4TBeCKdebQic+/jq5H2aqp8NJq+39LpdzvFTgRWAQhY8svxa8chclekGMziEjD8Al9ACm7EHbP1DNF1PVMyrqOps6xaFi/x6+yjfbzbRmQ28sWTeP+ayqgh4L7lkDDxZ862pk5irqq9vkyJGyzH4FAOZcswUxVfm/SW+lwDbvVcvzK7QPw9gEySMmlM9BiXiKn+V/dWXZYGA10u4mIGcmOxv8xyQl6hA5TsiTb07QAcBNNnYwyRoXExxNLhw7yPlJT03OMsU1NXWTx17VSkKZy5og+p0I4pUy49J2VtqyJfbfC+o2h3A9DhcW2/ld2BIetMNG4F6+p8iPMLpcFcbo7/a5XmI1AQGUNlhGns6P9ckvwpx4qEK+3xgRzEtWcFl27+0AX1pKCFAnG3x9S4uCkfV/I5sZ/5x9xZPSCxf3ZsADT+uB+Zh1vgA32FQwpTqh8L4w1Os=" + - secure: "kgi7IWjArL1/PGR4524iSfNdBAo9gisfbYk0YEwjfq43W0f4wWPZ8miLLDLZiWQ1C54cejJfD78/Hutsj5o6n/9Rq/C2WYHJthdjvgmj15Iv+GEWat3KSE6E/abm8z44d+i80Hd1uta7DrTNHZzQggR8jYEMotR4elfRvxpZqBth6Rh9q8LHndlh3oe4Mf6w5N7LPj+uete2AqJNdRr/EX/x90NQU9zG35BGQ9EakeF+LwxjD+YtD0v7zfuCbIKkRRm3TlcrMeh+QTdhS52Zh2RmCpAfisrBPgNjhr/juF44yd+n650QoytQsuEZDDgbWmrpcwWwXU28ZdNxvJLOwCYyzBnohvPBh+MuGSBzwKWaNKfI0jBQn/49GsGbJlRtLz6hLCKEL/PcxPUcNwibS+w2KVaVWKMuGbmkn7J9j2tUhE5vk012MTR/wG0Fa8dKOWHONig8o6pLQqsgnKXRR0ZnjojJquVrzk2GoL572qsKAIQOMVHqMSabk+7nPuDIjScJWa4vg851mMZ+StioY4bZK6L4WiTezkUz5bUy9n1N/QXXLIG8rG9EQhkmdxBo6WZdgu5F8/hZOI5AIxHCEPB86whynqQqvcwm4YJ24XUD2hpCHrg2io07xcqDkxJjpGbomi663a+WP3zZPN6Ujwv9T6FmIjCFdda7aHr2lCg=" + matrix: + - TEST=0 + - TEST=1 ### -### Disable auto-started daemons +### Stage definitions ### -before_script: - - # Disable services enabled by default - # http://docs.travis-ci.com/user/database-setup/#MySQL - - sudo /etc/init.d/mysql stop || true - - sudo /etc/init.d/postgresql stop || true - - sudo service mysql stop || true - - sudo service postgresql stop || true +stages: + - test + - deploy ### -### Test +### Global for all stages ### +install: + # Get newer docker version + - max=100; i=0; while [ $i -lt $max ]; do if sudo apt-get update; then break; else i=$((i+1)); fi done + - max=100; i=0; while [ $i -lt $max ]; do if sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; then break; else i=$((i+1)); fi done + - docker version script: - - .ci/start-ci.sh "${S1}" + - .ci/start-ci.sh "${TEST}" "${IMAGE}" + + +### +### Job definitions +### +jobs: + include: + # Final deploy stage + - stage: deploy + env: TEST= + before_script: + - if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then + if [ -n "${TRAVIS_TAG}" ]; then + docker build --no-cache=true -t "${IMAGE}:${TRAVIS_TAG}" . && + docker images; + elif [ "${TRAVIS_BRANCH}" == "master" ]; then + docker build --no-cache=true -t "${IMAGE}:latest" . && + docker images; + elif [[ ${TRAVIS_BRANCH} =~ ^(release[/-][.0-9]+)$ ]]; then + docker build --no-cache=true -t "${IMAGE}:${TRAVIS_BRANCH}" . && + docker images; + else + echo "Skipping branch ${TRAVIS_BRANCH}"; + fi + fi + script: + # Push to docker hub on success + - if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then + if [ -n "${TRAVIS_TAG}" ]; then + docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" && + echo "Pushing ${IMAGE}:${TRAVIS_TAG}" && + docker push "${IMAGE}:${TRAVIS_TAG}" && + docker tag "${IMAGE}:${TRAVIS_TAG}" "${IMAGE}:latest" && + echo "Pushing ${IMAGE}:latest" && + docker push "${IMAGE}:latest"; + elif [ "${TRAVIS_BRANCH}" == "master" ]; then + docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" && + echo "Pushing ${IMAGE}:latest" && + docker push "${IMAGE}:latest"; + elif [[ ${TRAVIS_BRANCH} =~ ^(release[/-][.0-9]+)$ ]]; then + docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" && + echo "Pushing ${IMAGE}:${TRAVIS_BRANCH}" && + docker push "${IMAGE}:${TRAVIS_BRANCH}"; + else + echo "Skipping branch ${TRAVIS_BRANCH}"; + fi + fi From 8edd6fea4d18a870e3a4f58ea006fab0440896d7 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 30 Sep 2017 16:29:43 +0200 Subject: [PATCH 5/8] REL-0.10 Upgrading vhost-gen config to latest structure --- Dockerfile | 2 +- README.md | 2 +- data/vhost-gen/conf.yml | 17 +++++++++++++++++ data/vhost-gen/main.yml | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cbc6fa6..a1c07c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ LABEL \ image="apache-2.2" \ vendor="cytopia" \ license="MIT" \ - build-date="2017-09-28" + build-date="2017-09-30" ### diff --git a/README.md b/README.md index 4ad60e3..ecc0d24 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.2)**: [![cytopia/apache-2.2](http://dockeri.co/image/cytopia/apache-2.2)](https://hub.docker.com/r/cytopia/apache-2.2/) -**Latest build:** 2017-09-28 +**Latest build:** 2017-09-30 ---- diff --git a/data/vhost-gen/conf.yml b/data/vhost-gen/conf.yml index 227412f..754b38d 100644 --- a/data/vhost-gen/conf.yml +++ b/data/vhost-gen/conf.yml @@ -10,6 +10,7 @@ # # server: nginx # conf_dir: /etc/nginx/conf.d +# custom: # vhost: # port: # name: @@ -48,11 +49,27 @@ # server: nginx server: apache22 + # Where to store the generated configuration files. # This must be a directory the web server will read # configuration files from. conf_dir: /etc/httpd/vhost.d + +# Custom directive +# Everything specified here will be directly replaced +# into the corresponding vhost directive: +# nginx: server { HERE } +# apache: HERE +# +# How to add multiline strings? +# +# custom: | +# custom statement 1 +# custom statement 2 +custom: + + # Vhost definition vhost: # What port should this virtual host listen on diff --git a/data/vhost-gen/main.yml b/data/vhost-gen/main.yml index 4bbd611..6dde619 100644 --- a/data/vhost-gen/main.yml +++ b/data/vhost-gen/main.yml @@ -10,6 +10,7 @@ # # server: nginx # conf_dir: /etc/nginx/conf.d +# custom: # vhost: # port: # name: @@ -48,11 +49,27 @@ # server: nginx server: apache22 + # Where to store the generated configuration files. # This must be a directory the web server will read # configuration files from. conf_dir: /etc/httpd/conf.d + +# Custom directive +# Everything specified here will be directly replaced +# into the corresponding vhost directive: +# nginx: server { HERE } +# apache: HERE +# +# How to add multiline strings? +# +# custom: | +# custom statement 1 +# custom statement 2 +custom: + + # Vhost definition vhost: # What port should this virtual host listen on From a23780c89f245adbc94f2d260e0766da559a286a Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 30 Sep 2017 16:42:38 +0200 Subject: [PATCH 6/8] REL-0.10 Be more verbose during travis run --- .ci/00.sh | 4 ++-- .ci/01.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.ci/00.sh b/.ci/00.sh index 6b25c23..c94cba8 100755 --- a/.ci/00.sh +++ b/.ci/00.sh @@ -20,7 +20,7 @@ CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" ### RAND_DIR="$( mktemp -d )" RAND_NAME="$( get_random_name )" -echo "hello world" > "${RAND_DIR}/index.html" +run "echo \"hello world\" > ${RAND_DIR}/index.html" ### @@ -45,7 +45,7 @@ run "docker run -d --rm \ ### ### Tests ### -sleep 5 +run "sleep 5" run "docker ps" run "docker logs ${RAND_NAME}" run "curl localhost" diff --git a/.ci/01.sh b/.ci/01.sh index 03158cb..dd25739 100755 --- a/.ci/01.sh +++ b/.ci/01.sh @@ -21,7 +21,7 @@ CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" RAND_DIR="$( mktemp -d )" RAND_NAME1="$( get_random_name )" RAND_NAME2="$( get_random_name )" -echo " "${RAND_DIR}/index.php" +run "echo \" ${RAND_DIR}/index.php" ### @@ -57,7 +57,7 @@ run "docker run -d --rm \ ### ### Tests ### -sleep 5 +run "sleep 5" run "docker ps" run "docker logs ${RAND_NAME1}" run "docker logs ${RAND_NAME2}" From 3259df3633ef4c7eaa5b37a0f1ff74a236f65e1e Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 30 Sep 2017 17:15:03 +0200 Subject: [PATCH 7/8] REL-0.10 Fix: Disable server status when set to disabled --- data/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/docker-entrypoint.sh b/data/docker-entrypoint.sh index fa5e7f7..8ca84f8 100755 --- a/data/docker-entrypoint.sh +++ b/data/docker-entrypoint.sh @@ -451,7 +451,7 @@ if [ "${_RUNTIME_MAIN_VHOST_ENABLE}" -eq "1" ]; then run "sed -i'' 's/__ENABLE_STATUS__/yes/g' /etc/vhost-gen/main.yml" run "sed -i'' 's|__STATUS_ALIAS__|${_RUNTIME_MAIN_VHOST_STATUS_ALIAS}|g' /etc/vhost-gen/main.yml" else - run "sed -i'' 's/__ENABLE_STATUS__/yes/g' /etc/vhost-gen/main.yml" + run "sed -i'' 's/__ENABLE_STATUS__/no/g' /etc/vhost-gen/main.yml" fi # Debug creation? From fbc51cb9065e04ab406198684f0151e686b17cd6 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 1 Oct 2017 11:21:35 +0200 Subject: [PATCH 8/8] REL-0.10 Move to devilbox namespace --- .travis.yml | 6 ++-- Dockerfile | 4 +-- README.md | 20 +++++------ build/docker-attach.sh | 19 +++++++---- build/docker-build.sh | 16 ++++++--- build/docker-enter.sh | 13 +++++-- build/docker-push.sh | 75 ----------------------------------------- build/docker-rebuild.sh | 16 ++++++--- build/docker-start.sh | 15 +++++++-- 9 files changed, 77 insertions(+), 107 deletions(-) delete mode 100755 build/docker-push.sh diff --git a/.travis.yml b/.travis.yml index 48290dc..e9df2ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,10 @@ env: # travis encrypt DOCKER_USERNAME=user # travis encrypt DOCKER_PASSWORD=pass # Must be regenerated when repository name/owner changes - - secure: "NHoT/hlhTCkXvqkL9hfi7nmjv1HcQe/EexdklueBjhQcb14NxvRezAzNkqWPyanT+o9kGS6F+PmBIT2NswlSDhihDf/Ctbs1lCF7Ny9tixZnTNC00Ye6rOUPCZhNEC2fgd58uqcD54xdmjT2YywV4rYeYYBgyg8LTI63Uy6t+CeDVVZ5nsB8HQ+r/GC+aowFJKzREEfhq2zfE4C92xl2fqJXAYTyEbsM7BP4TBeCKdebQic+/jq5H2aqp8NJq+39LpdzvFTgRWAQhY8svxa8chclekGMziEjD8Al9ACm7EHbP1DNF1PVMyrqOps6xaFi/x6+yjfbzbRmQ28sWTeP+ayqgh4L7lkDDxZ862pk5irqq9vkyJGyzH4FAOZcswUxVfm/SW+lwDbvVcvzK7QPw9gEySMmlM9BiXiKn+V/dWXZYGA10u4mIGcmOxv8xyQl6hA5TsiTb07QAcBNNnYwyRoXExxNLhw7yPlJT03OMsU1NXWTx17VSkKZy5og+p0I4pUy49J2VtqyJfbfC+o2h3A9DhcW2/ld2BIetMNG4F6+p8iPMLpcFcbo7/a5XmI1AQGUNlhGns6P9ckvwpx4qEK+3xgRzEtWcFl27+0AX1pKCFAnG3x9S4uCkfV/I5sZ/5x9xZPSCxf3ZsADT+uB+Zh1vgA32FQwpTqh8L4w1Os=" - - secure: "kgi7IWjArL1/PGR4524iSfNdBAo9gisfbYk0YEwjfq43W0f4wWPZ8miLLDLZiWQ1C54cejJfD78/Hutsj5o6n/9Rq/C2WYHJthdjvgmj15Iv+GEWat3KSE6E/abm8z44d+i80Hd1uta7DrTNHZzQggR8jYEMotR4elfRvxpZqBth6Rh9q8LHndlh3oe4Mf6w5N7LPj+uete2AqJNdRr/EX/x90NQU9zG35BGQ9EakeF+LwxjD+YtD0v7zfuCbIKkRRm3TlcrMeh+QTdhS52Zh2RmCpAfisrBPgNjhr/juF44yd+n650QoytQsuEZDDgbWmrpcwWwXU28ZdNxvJLOwCYyzBnohvPBh+MuGSBzwKWaNKfI0jBQn/49GsGbJlRtLz6hLCKEL/PcxPUcNwibS+w2KVaVWKMuGbmkn7J9j2tUhE5vk012MTR/wG0Fa8dKOWHONig8o6pLQqsgnKXRR0ZnjojJquVrzk2GoL572qsKAIQOMVHqMSabk+7nPuDIjScJWa4vg851mMZ+StioY4bZK6L4WiTezkUz5bUy9n1N/QXXLIG8rG9EQhkmdxBo6WZdgu5F8/hZOI5AIxHCEPB86whynqQqvcwm4YJ24XUD2hpCHrg2io07xcqDkxJjpGbomi663a+WP3zZPN6Ujwv9T6FmIjCFdda7aHr2lCg=" + # DOCKER_USERNAME + - secure: "DC6uq+guleW95fBkEGRRQgHqNrZJmZFFbg0uaeQARDQcy3AZMnHmpFTI6MIlJERCGQ4SACZSUV4oPMPRo78/a3L0fSdSaijLp7hlGxEu8gJYm0saJVliPZJblgvxVICqBgUr9OoV5kxn/L8xPxy8eqdLJs5TwJ2+IDX3gUPvBeN6U21xvwdEA44DwFJpYJ1pt/GoJ6CcsgQu3uJ4MHKAH/HFXxk6z/INJlIqOJnVeEJoJBHGOMb1rp8DnxDpmcuG1G0IkZqv9abVYePWdcl86TOzHHQyjvsI86neQYX6Tr1P0/y+R8gPMzn98fTcNXa33z8aJydRCs8GOQmQNViP1eLTi4a+n+lEA6J98VUBF+LuqWE5+WARczfwWyNE2qsQxjm4dDAfkSIK51Pk7tRs+pIesthmAQusp0TeM6k6O3MUT8ZNbk9dGoW8yguPoABzZgaTBvWvLwbBfU6kg/Vdjk6kuqAB4w2t7alXVYefBsNQmoHgaMNp84nbPbSbliPFMgsgdKgGfRMMUc7lLizpRuOxHVluoDKJNBauEdrJiBufWZWCQvw/TahegeC4owVT6E9lWgsH4mMhp/BPiZyeAmGcxyPhq9FbvTK9CxkLYYeofaJh47yvc6sN5nvH/IwHRPsnq1XJwW7ODPw4DdBPeLBxnMs9WETwkmGfe6ZncdE=" + # DOCKER_PASSWORD + - secure: "NetFHs4D7GOsuBAx72eEqoM8RiJ/+3mM2iycdMkDjHm1dIv+NHIXh2Y0tbQxiSqWS1LTcCC12zW0bnVWPVHY7C7lEIAtvEvtAHPS0PMv+a3SkGnByIMDFhGUuwnr/dgcfBUnOgw/Ai+PBOrAPfesAZd/rZ4Gbru+WZpNatlJhAoPHMdUBeqWBz7pouldMOAwO9bT7fWa7z3FaFPO2fbCq85bT15uVkKBFc/SkSgvbywDdT053zkrKhrWPQHWZxMOHdxsIimbvFEYzoM3s6IkMwVhFcOqgPqlokhu3MCAJrb1V6554gM7EMhuYqyfFeAB2i/4P5q7yRZeJQ5wm9Zf5D7ywUprFgT3YjsonR7H+2CCZAZpiXg01fl/LC3Mg6IKEL0/726lfu0kevHH60x2oq86r32ioa3AyRmtC/wu9nbm5ey1MLb/BBI/VH1Cv2xdwqgthrikXlt7/KlKN/e+UlS0Dn+GXomN09xlV2COD4YLEVgqK3bXDt1s6xQZ9F//Lt4HTSp6XJw8iuQyV4D5fvTGxvrBervptVlEpfT67dLDpEFm3mS0a5bp2yc0YY/AjKlFM8rc64k2Tu573bdDoPkbEDGgBv8ZGp4XSWVbmfScRZcsJSGdXvntk634kGgAgb8YwP8wR82dCUGjVyrjaljrS5+g5+EQJm2DmXgzRQ4=" matrix: - TEST=0 - TEST=1 diff --git a/Dockerfile b/Dockerfile index a1c07c1..9e52b80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,9 @@ MAINTAINER "cytopia" LABEL \ name="cytopia's Apache 2.2 Image" \ image="apache-2.2" \ - vendor="cytopia" \ + vendor="devilbox" \ license="MIT" \ - build-date="2017-09-30" + build-date="2017-10-01" ### diff --git a/README.md b/README.md index ecc0d24..83ba58e 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,21 @@ This Docker image is part of the **[devilbox](https://github.com/cytopia/devilbox)**. -**Apache 2.2 | [Apache 2.4](https://github.com/cytopia/docker-apache-2.2) | [Nginx stable](https://github.com/cytopia/docker-nginx-stable) | [Nginx mainline](https://github.com/cytopia/docker-nginx-mainline)** +**Apache 2.2 | [Apache 2.4](https://github.com/devilbox/docker-apache-2.2) | [Nginx stable](https://github.com/devilbox/docker-nginx-stable) | [Nginx mainline](https://github.com/devilbox/docker-nginx-mainline)** -[![Build Status](https://travis-ci.org/cytopia/docker-apache-2.2.svg?branch=master)](https://travis-ci.org/cytopia/docker-apache-2.2) [![](https://images.microbadger.com/badges/version/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/image/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/license/cytopia/apache-2.2.svg)](https://microbadger.com/images/cytopia/apache-2.2 "apache-2.2") +[![Build Status](https://travis-ci.org/devilbox/docker-apache-2.2.svg?branch=master)](https://travis-ci.org/devilbox/docker-apache-2.2) [![](https://images.microbadger.com/badges/version/devilbox/apache-2.2.svg)](https://microbadger.com/images/devilbox/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/image/devilbox/apache-2.2.svg)](https://microbadger.com/images/devilbox/apache-2.2 "apache-2.2") [![](https://images.microbadger.com/badges/license/devilbox/apache-2.2.svg)](https://microbadger.com/images/devilbox/apache-2.2 "apache-2.2") -This image is based on the official **[Apache 2.2](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically** when adding new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd]()** and **[vhost-gen]()**. +This image is based on the official **[Apache 2.2](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically** when adding new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd](https://github.com/devilbox/watcherd)** and **[vhost-gen](https://github.com/devilbox/vhost-gen)**. From a users perspective, you mount your local project directory into the Docker under `/shared/httpd`. Any directory then created in your local project directory wil spawn a new virtual host by the same name. Additional settings such as custom server names, PHP-FPM or even different Apache templates per project are supported as well. ---- -Find me on **[Docker Hub](https://hub.docker.com/r/cytopia/apache-2.2)**: +Find me on **[Docker Hub](https://hub.docker.com/r/devilbox/apache-2.2)**: -[![cytopia/apache-2.2](http://dockeri.co/image/cytopia/apache-2.2)](https://hub.docker.com/r/cytopia/apache-2.2/) +[![devilbox/apache-2.2](http://dockeri.co/image/devilbox/apache-2.2)](https://hub.docker.com/r/devilbox/apache-2.2/) -**Latest build:** 2017-09-30 +**Latest build:** This container is built every night by [travis-ci](https://travis-ci.org/devilbox/docker-apache-2.2). ---- @@ -170,14 +170,14 @@ Mount your local directort `~/my-host-www` into the docker and server those file **Note:** Files will be server from `~/my-host-www/htdocs`. ```bash -$ docker run -d -p 80:80 -v ~/my-host-www:/var/www/default -t cytopia/apache-2.2 +$ docker run -d -p 80:80 -v ~/my-host-www:/var/www/default -t devilbox/apache-2.2 ``` #### 2. Serve PHP files with PHP-FPM Note, for this to work, the `~/my-host-www` dir must be mounted into the Apache Docker as well as into the php-fpm docker. -You can also attach other PHP-FPM version: [PHP-FPM 5.4](https://github.com/cytopia/docker-php-fpm-5.4), [PHP-FPM 5.5](https://github.com/cytopia/docker-php-fpm-5.5), [PHP-FPM 5.6](https://github.com/cytopia/docker-php-fpm-5.6), [PHP-FPM 7.0](https://github.com/cytopia/docker-php-fpm-7.0) or [PHP-FPM 7.1](https://github.com/cytopia/docker-php-fpm-7.1) +You can also attach other PHP-FPM version: [PHP-FPM 5.4](https://github.com/cytopia/docker-php-fpm-5.4), [PHP-FPM 5.5](https://github.com/cytopia/docker-php-fpm-5.5), [PHP-FPM 5.6](https://github.com/cytopia/docker-php-fpm-5.6), [PHP-FPM 7.0](https://github.com/cytopia/docker-php-fpm-7.0), [PHP-FPM 7.1](https://github.com/cytopia/docker-php-fpm-7.1), [PHP-FPM 7.2](https://github.com/cytopia/docker-php-fpm-7.2) or [HHVM](https://github.com/cytopia/docker-hhvm-latest). Each PHP-FPM docker also has the option to enable Xdebug and more, see their respective Readme files for futher settings. @@ -193,7 +193,7 @@ $ docker run -d \ -e PHP_FPM_SERVER_ADDR=php \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ - -t cytopia/apache-2.2 + -t devilbox/apache-2.2 ``` #### 3. Fully functional LEMP stack @@ -228,7 +228,7 @@ $ docker run -d \ -e PHP_FPM_SERVER_PORT=9000 \ --link php \ --link mysql \ - -t cytopia/apache-2.2 + -t devilbox/apache-2.2 ``` #### 4. Ultimate pre-configured docker-compose setup diff --git a/build/docker-attach.sh b/build/docker-attach.sh index 6aaa6ac..b020098 100755 --- a/build/docker-attach.sh +++ b/build/docker-attach.sh @@ -32,17 +32,24 @@ if [ ! -f "${CWD}/Dockerfile" ]; then exit 1 fi -# Get docker Name +# Test Docker name if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then echo "No 'image' LABEL found" exit fi -# Make sure exactly 1 container is running +# Test Docker vendor +if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then + echo "No 'vendor' LABEL found" + exit +fi + +# Retrieve values NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" -COUNT="$( docker ps | grep -c "cytopia/${NAME}" || true)" +VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )" +COUNT="$( docker ps | grep -c "${VEND}/${NAME}" || true)" if [ "${COUNT}" != "1" ]; then - echo "${COUNT} 'cytopia/${NAME}' container running. Unable to attach." + echo "${COUNT} '${VEND}/${NAME}' container running. Unable to attach." exit 1 fi @@ -50,7 +57,7 @@ fi ### ### Attach ### -DID="$(docker ps | grep "cytopia/${NAME}" | awk '{print $1}')" +DID="$(docker ps | grep "${VEND}/${NAME}" | awk '{print $1}')" -echo "Attaching to: cytopia/${NAME}" +echo "Attaching to: ${VEND}/${NAME}" run "docker exec -it ${DID} env TERM=xterm /bin/bash -l" diff --git a/build/docker-build.sh b/build/docker-build.sh index 1e3762f..a5ed846 100755 --- a/build/docker-build.sh +++ b/build/docker-build.sh @@ -32,12 +32,21 @@ if [ ! -f "${CWD}/Dockerfile" ]; then exit 1 fi -# Get docker Name +# Test Docker name if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then echo "No 'image' LABEL found" exit fi + +# Test Docker vendor +if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then + echo "No 'vendor' LABEL found" + exit +fi + +# Retrieve values NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )" DATE="$( date '+%Y-%m-%d' )" @@ -53,17 +62,16 @@ run "docker pull ${MY_BASE}" ### # Update build date -run "sed -i'' 's/\*\*Latest\sbuild.*/**Latest build:** ${DATE}<\/small>/g' ${CWD}/README.md" run "sed -i'' 's/build-date=\".*\"/build-date=\"${DATE}\"/g' ${CWD}/Dockerfile" # Build Docker -run "docker build -t cytopia/${NAME} ${CWD}" +run "docker build -t ${VEND}/${NAME} ${CWD}" ### ### Retrieve information afterwards and Update README.md ### -docker run -d --rm --name my_tmp_${NAME} -t cytopia/${NAME} +docker run -d --rm --name my_tmp_${NAME} -t ${VEND}/${NAME} INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built|Module|loaded|MPM)' )" docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" > /dev/null diff --git a/build/docker-enter.sh b/build/docker-enter.sh index d51036e..841d638 100755 --- a/build/docker-enter.sh +++ b/build/docker-enter.sh @@ -32,15 +32,24 @@ if [ ! -f "${CWD}/Dockerfile" ]; then exit 1 fi -# Get docker Name +# Test Docker name if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then echo "No 'image' LABEL found" exit fi + +# Test Docker vendor +if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then + echo "No 'vendor' LABEL found" + exit +fi + +# Retrieve values NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )" ### ### Enter ### -run "docker run -i --entrypoint /bin/bash -t cytopia/${NAME}" +run "docker run -i --entrypoint /bin/bash -t ${VEND}/${NAME}" diff --git a/build/docker-push.sh b/build/docker-push.sh deleted file mode 100755 index 5937649..0000000 --- a/build/docker-push.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/sh -eu - - -### -### Globals -### -CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.." - - -### -### Checks -### - -# Check Dockerfile -if [ ! -f "${CWD}/Dockerfile" ]; then - echo "Dockerfile not found in: ${CWD}/Dockerfile." - exit 1 -fi - -# Get docker Name -if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then - echo "No 'image' LABEL found" - exit -fi -NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" - - -### -### Docker hub variables -### -USR="cytopia" -IMG="${USR}/${NAME}" -REG="https://index.docker.io/v1/" - - -## -## Functions -## -get_docker_id() { - _did="$( docker images | grep "${IMG}\s" | grep "latest" | awk '{print $3}' )" - echo "${_did}" -} -is_logged_in() { - _user="$( docker info | grep "${USR}" | awk '{print $2}' )" - _dhub="$( docker info | grep 'Registry' | awk '{print $2}' )" - - if [ "${_user}" = "${USR}" ]; then - if [ "${_dhub}" = "${REG}" ]; then - return 0 - fi - fi - return 1 -} -run() { - _cmd="${1}" - _red="\033[0;31m" - _green="\033[0;32m" - _reset="\033[0m" - _user="$(whoami)" - - printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}" - sh -c "LANG=C LC_ALL=C ${_cmd}" -} - - - -## -## Entrypoint -## -#run "docker build --no-cache -t ${IMG} ." -run "docker tag $( get_docker_id ) ${IMG}:latest" -if ! is_logged_in; then - run "docker login" -fi -run "docker push ${IMG}" diff --git a/build/docker-rebuild.sh b/build/docker-rebuild.sh index 03e0e18..2919859 100755 --- a/build/docker-rebuild.sh +++ b/build/docker-rebuild.sh @@ -32,12 +32,21 @@ if [ ! -f "${CWD}/Dockerfile" ]; then exit 1 fi -# Get docker Name +# Test Docker name if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then echo "No 'image' LABEL found" exit fi + +# Test Docker vendor +if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then + echo "No 'vendor' LABEL found" + exit +fi + +# Retrieve values NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )" DATE="$( date '+%Y-%m-%d' )" @@ -53,17 +62,16 @@ run "docker pull ${MY_BASE}" ### # Update build date -run "sed -i'' 's/\*\*Latest\sbuild.*/**Latest build:** ${DATE}<\/small>/g' ${CWD}/README.md" run "sed -i'' 's/build-date=\".*\"/build-date=\"${DATE}\"/g' ${CWD}/Dockerfile" # Build Docker -run "docker build --no-cache -t cytopia/${NAME} ${CWD}" +run "docker build --no-cache -t ${VEND}/${NAME} ${CWD}" ### ### Retrieve information afterwards and Update README.md ### -docker run -d --rm --name my_tmp_${NAME} -t cytopia/${NAME} +docker run -d --rm --name my_tmp_${NAME} -t ${VEND}/${NAME} INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built|Module|loaded|MPM)' )" docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" > /dev/null diff --git a/build/docker-start.sh b/build/docker-start.sh index 608f0e8..b89c00d 100755 --- a/build/docker-start.sh +++ b/build/docker-start.sh @@ -32,12 +32,23 @@ if [ ! -f "${CWD}/Dockerfile" ]; then exit 1 fi -# Get docker Name + +# Test Docker name if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then echo "No 'image' LABEL found" exit fi + +# Test Docker vendor +if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then + echo "No 'vendor' LABEL found" + exit +fi + +# Retrieve values NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )" +VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )" + ### ### Run @@ -46,4 +57,4 @@ _args="" if [ "${#}" != "0" ]; then _args="${*}" fi -run "docker run -it ${_args} cytopia/${NAME}" +run "docker run -it ${_args} ${VEND}/${NAME}"