Skip to content

Commit dba33d4

Browse files
authored
Merge pull request #9 from devilbox/release-0.15
WIP: Add HTTPS support
2 parents e445382 + 0c7dd57 commit dba33d4

24 files changed

+1403
-717
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
7272
docker build --no-cache=true -t "${IMAGE}:latest" . &&
7373
docker images;
74-
elif [[ ${TRAVIS_BRANCH} =~ ^(release[/-][.0-9]+)$ ]]; then
74+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
7575
docker build --no-cache=true -t "${IMAGE}:${TRAVIS_BRANCH}" . &&
7676
docker images;
7777
else
@@ -91,7 +91,7 @@ jobs:
9191
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
9292
echo "Pushing ${IMAGE}:latest" &&
9393
docker push "${IMAGE}:latest";
94-
elif [[ ${TRAVIS_BRANCH} =~ ^(release[/-][.0-9]+)$ ]]; then
94+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
9595
echo "Pushing ${IMAGE}:${TRAVIS_BRANCH}" &&
9696
docker push "${IMAGE}:${TRAVIS_BRANCH}";
9797
else

Dockerfile

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@ MAINTAINER "cytopia" <[email protected]>
33

44

55
###
6-
### Labels
6+
### Build arguments
77
###
8-
LABEL \
9-
name="cytopia's Nginx Image" \
10-
image="nginx-stable" \
11-
vendor="devilbox" \
12-
license="MIT" \
13-
build-date="2017-10-01"
8+
ARG VHOST_GEN_GIT_REF=0.5
9+
ARG CERT_GEN_GIT_REF=0.2
10+
11+
ENV BUILD_DEPS \
12+
git \
13+
make \
14+
wget
15+
16+
ENV RUN_DEPS \
17+
ca-certificates \
18+
python-yaml \
19+
supervisor
20+
21+
22+
###
23+
### Runtime arguments
24+
###
25+
ENV MY_USER=nginx
26+
ENV MY_GROUP=nginx
27+
ENV HTTPD_START="/usr/sbin/nginx"
28+
ENV HTTPD_RELOAD="nginx -s reload"
1429

1530

1631
###
@@ -22,40 +37,36 @@ RUN set -x \
2237
&& apt-get update \
2338
&& apt-get upgrade -y \
2439
&& apt-get install --no-install-recommends --no-install-suggests -y \
25-
make \
26-
python-yaml \
27-
supervisor \
28-
wget \
29-
&& rm -rf /var/lib/apt/lists/* \
30-
&& apt-get purge -y --auto-remove
31-
32-
# vhost-gen
33-
RUN set -x \
34-
&& wget --no-check-certificate -O vhost_gen.tar.gz https://github.com/devilbox/vhost-gen/archive/master.tar.gz \
35-
&& tar xfvz vhost_gen.tar.gz \
36-
&& cd vhost-gen-master \
40+
${BUILD_DEPS} \
41+
${RUN_DEPS} \
42+
\
43+
# Install vhost-gen
44+
&& git clone https://github.com/devilbox/vhost-gen \
45+
&& cd vhost-gen \
46+
&& git checkout "${VHOST_GEN_GIT_REF}" \
3747
&& make install \
3848
&& cd .. \
39-
&& rm -rf vhost*gen*
40-
41-
# watcherd
42-
RUN set -x \
49+
&& rm -rf vhost*gen* \
50+
\
51+
# Install cert-gen
52+
&& wget --no-check-certificate -O /usr/bin/ca-gen https://raw.githubusercontent.com/devilbox/cert-gen/${CERT_GEN_GIT_REF}/bin/ca-gen \
53+
&& wget --no-check-certificate -O /usr/bin/cert-gen https://raw.githubusercontent.com/devilbox/cert-gen/${CERT_GEN_GIT_REF}/bin/cert-gen \
54+
&& chmod +x /usr/bin/ca-gen \
55+
&& chmod +x /usr/bin/cert-gen \
56+
\
57+
# Install watcherd
4358
&& wget --no-check-certificate -O /usr/bin/watcherd https://raw.githubusercontent.com/devilbox/watcherd/master/watcherd \
44-
&& chmod +x /usr/bin/watcherd
45-
46-
# cleanup
47-
RUN set -x \
48-
&& apt-get update \
49-
&& apt-get remove -y \
50-
make \
51-
wget \
52-
&& apt-get autoremove -y \
53-
&& rm -rf /var/lib/apt/lists/* \
54-
&& apt-get purge -y --auto-remove
59+
&& chmod +x /usr/bin/watcherd \
60+
\
61+
# Clean-up
62+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps \
63+
${BUILD_DEPS} \
64+
&& rm -rf /var/lib/apt/lists/*
5565

5666
# Add custom config directive to httpd server
5767
RUN set -x \
58-
&& sed -i'' 's|^\s*include.*conf\.d/.*| include /etc/httpd-custom.d/*.conf;\n include /etc/httpd/conf.d/*.conf;\n include /etc/httpd/vhost.d/*.conf;\n|g' /etc/nginx/nginx.conf
68+
&& sed -i'' 's|^\s*include.*conf\.d/.*| include /etc/httpd-custom.d/*.conf;\n include /etc/httpd/conf.d/*.conf;\n include /etc/httpd/vhost.d/*.conf;\n|g' /etc/nginx/nginx.conf \
69+
&& echo "daemon off;" >> /etc/nginx/nginx.conf
5970

6071
# create directories
6172
RUN set -x \
@@ -65,28 +76,31 @@ RUN set -x \
6576
&& mkdir -p /var/www/default/htdocs \
6677
&& mkdir -p /shared/httpd \
6778
&& chmod 0775 /shared/httpd \
68-
&& chown nginx:nginx /shared/httpd
79+
&& chown ${MY_USER}:${MY_GROUP} /shared/httpd
6980

7081

7182
###
7283
### Copy files
7384
###
74-
COPY ./data/vhost-gen/conf.yml /etc/vhost-gen/conf.yml
7585
COPY ./data/vhost-gen/main.yml /etc/vhost-gen/main.yml
76-
COPY ./data/supervisord.conf /etc/supervisord.conf
86+
COPY ./data/vhost-gen/mass.yml /etc/vhost-gen/mass.yml
87+
COPY ./data/create-vhost.sh /usr/local/bin/create-vhost.sh
88+
COPY ./data/docker-entrypoint.d /docker-entrypoint.d
7789
COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh
7890

7991

8092
###
8193
### Ports
8294
###
8395
EXPOSE 80
96+
EXPOSE 443
8497

8598

8699
###
87100
### Volumes
88101
###
89102
VOLUME /shared/httpd
103+
VOLUME /ca
90104

91105

92106
###

README.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# Nginx stable Docker
1+
# Nginx stable Docker image
22

3-
[![Devilbox](https://raw.githubusercontent.com/cytopia/devilbox/master/.devilbox/www/htdocs/assets/img/devilbox_80.png)](https://github.com/cytopia/devilbox)
3+
[![Build Status](https://travis-ci.org/devilbox/docker-nginx-stable.svg?branch=master)](https://travis-ci.org/devilbox/docker-nginx-stable)
4+
[![release](https://img.shields.io/github/release/devilbox/docker-nginx-stable.svg)](https://github.com/devilbox/docker-nginx-stable/releases)
5+
[![Join the chat at https://gitter.im/devilbox/Lobby](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
[![Github](https://img.shields.io/badge/github-docker--nginx--stable-red.svg)](https://github.com/devilbox/docker-nginx-stable)
7+
[![](https://images.microbadger.com/badges/license/devilbox/nginx-stable.svg)](https://microbadger.com/images/devilbox/nginx-stable "nginx-stable")
48

5-
<sub>This Docker image is part of the **[devilbox](https://github.com/cytopia/devilbox)**.</sub>
9+
**[devilbox/docker-nginx-stable](https://github.com/devilbox/docker-nginx-stable)**
610

7-
**[Apache 2.2](https://github.com/devilbox/docker-apache-2.2) | [Apache 2.4](https://github.com/devilbox/docker-apache-2.4) | Nginx stable | [Nginx mainline](https://github.com/devilbox/docker-nginx-mainline)**
8-
9-
[![Build Status](https://travis-ci.org/devilbox/docker-nginx-stable.svg?branch=master)](https://travis-ci.org/devilbox/docker-nginx-stable) [![](https://images.microbadger.com/badges/version/devilbox/nginx-stable.svg)](https://microbadger.com/images/devilbox/nginx-stable "nginx-stable") [![](https://images.microbadger.com/badges/image/devilbox/nginx-stable.svg)](https://microbadger.com/images/devilbox/nginx-stable "nginx-stable") [![](https://images.microbadger.com/badges/license/devilbox/nginx-stable.svg)](https://microbadger.com/images/devilbox/nginx-stable "nginx-stable")
11+
This image is based on the official **[Nginx](https://hub.docker.com/_/nginx)** Docker image and extends it with the ability to have **virtual hosts created automatically**, as well as **adding SSL certificates** when creating 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)**.
1012

11-
This image is based on the official **[Nginx (stable)](https://hub.docker.com/_/nginx/)** 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)**.
13+
From a users perspective, you mount your local project directory into the container 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.
1214

13-
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 nginx templates per project are supported as well.
14-
15-
----
15+
| Docker Hub | Upstream Project |
16+
|------------|------------------|
17+
| <a href="https://hub.docker.com/r/devilbox/nginx-stable"><img height="82px" src="http://dockeri.co/image/devilbox/nginx-stable" /></a> | <a href="https://github.com/cytopia/devilbox" ><img height="82px" src="https://raw.githubusercontent.com/devilbox/artwork/master/submissions_banner/cytopia/01/png/banner_256_trans.png" /></a> |
1618

17-
Find me on **[Docker Hub](https://hub.docker.com/r/devilbox/nginx-stable)**:
18-
19-
[![devilbox/nginx-stable](http://dockeri.co/image/devilbox/nginx-stable)](https://hub.docker.com/r/devilbox/nginx-stable/)
20-
21-
<small>**Latest build:** This container is built every night by [travis-ci](https://travis-ci.org/devilbox/docker-nginx-stable).</small>
19+
**[Apache 2.2](https://github.com/devilbox/docker-apache-2.2) | [Apache 2.4](https://github.com/devilbox/docker-apache-2.4) | Nginx stable | [Nginx mainline](https://github.com/devilbox/docker-nginx-mainline)**
2220

2321
----
2422

@@ -29,12 +27,16 @@ Find me on **[Docker Hub](https://hub.docker.com/r/devilbox/nginx-stable)**:
2927

3028
1. Automated virtual hosts can be enabled by providing `-e MASS_VHOST_ENABLE=1`.
3129
2. You should mount a local project directory into the Docker under `/shared/httpd` (`-v /local/path:/shared/httpd`).
32-
3. You can optionally specify a global server name suffix via e.g.: `-e MASS_VHOST_TLD=.local`
30+
3. You can optionally specify a global server name suffix via e.g.: `-e MASS_VHOST_TLD=.loc`
3331
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`
34-
4. Allow the Docker to expose its port via `-p 80:80`.
35-
5. Have DNS names point to the IP address the docker runs on (e.g. via `/etc/hosts`)
32+
5. Allow the Docker to expose its port via `-p 80:80`.
33+
6. Have DNS names point to the IP address the container runs on (e.g. via `/etc/hosts`)
3634

37-
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`.
35+
With the above described settings, whenever you create a local directory under your projects dir
36+
such as `/local/path/mydir`, there will be a new virtual host created by the same name
37+
`http://mydir`. You can also specify a global suffix for the vhost names via
38+
`-e MASS_VHOST_TLD=.loc`, afterwards your above created vhost would be reachable via
39+
`http://mydir.loc`.
3840

3941
Just to give you a few examples:
4042

@@ -67,7 +69,7 @@ docker run -it \
6769
-p 80:80 \
6870
-e MASS_VHOST_ENABLE=1 \
6971
-e MASS_VHOST_DOCROOT=www \
70-
-e MASS_VHOST_TLD=.local \
72+
-e MASS_VHOST_TLD=.loc \
7173
-v /local/path:/shared/httpd \
7274
devilbox/nginx-stable
7375
```
@@ -99,7 +101,7 @@ PHP-FPM is not included inside this Docker container, but can be enabled to cont
99101

100102
#### Disabling the default virtual host
101103

102-
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`.
104+
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_ENABLE=0`.
103105

104106

105107
## Options
@@ -130,7 +132,10 @@ This Docker container adds a lot of injectables in order to customize it to your
130132

131133
| Variable | Type | Default | Description |
132134
|----------|------|---------|-------------|
133-
| 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`.<br/><strong>Note:</strong>The `htdocs` dir name can be changed with `MAIN_VHOST_DOCROOT`. See below. |
135+
| MAIN_VHOST_ENABLE | bool | `1` | 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 `0`.<br/><strong>Note:</strong>The `htdocs` dir name can be changed with `MAIN_VHOST_DOCROOT`. See below. |
136+
| MAIN_VHOST_SSL_TYPE | string | `plain` | <ul><li><code>plain</code> - only serve via http</li><li><code>ssl</code> - only serve via https</li><li><code>both</code> - serve via http and https</li><li><code>redir</code> - serve via https and redirect http to https</li></ul> |
137+
| MAIN_VHOST_SSL_GEN | bool | `0` | `0`: Do not generate an ssl certificate<br/> `1`: Generate self-signed certificate automatically |
138+
| MAIN_VHOST_SSL_CN | string | `localhost` | Comma separated list of CN names for SSL certificate generation (The domain names by which you want to reach the default server) |
134139
| 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.<br/><strong>Default:</strong><br/>`/var/www/default/htdocs`<br/><strong>Example:</strong><br/>`MAIN_VHOST_DOCROOT=www`<br/>Doc root: `/var/www/default/www` |
135140
| 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.<br/><strong>Resulting default path:</strong><br/>`/var/www/default/cfg` |
136141
| MAIN_VHOST_STATUS_ENABLE | bool | `0` | Enable httpd status page. |
@@ -141,7 +146,9 @@ This Docker container adds a lot of injectables in order to customize it to your
141146
| Variable | Type | Default | Description |
142147
|----------|------|---------|-------------|
143148
| 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. |
144-
| 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.<br/><strong>Default:</strong>`<project>.local`<br/><strong>Example:</strong><br/>Path: `/shared/httpd/temp`<br/>`MASS_VHOST_TLD=.lan`<br/>Server name: `temp.lan`<br/><strong>Example:</strong><br/>Path:`/shared/httpd/api`<br/>`MASS_VHOST_TLD=.example.com`<br/>Server name: `api.example.com` |
149+
| MASS_VHOST_SSL_TYPE | string | `plain` | <ul><li><code>plain</code> - only serve via http</li><li><code>ssl</code> - only serve via https</li><li><code>both</code> - serve via http and https</li><li><code>redir</code> - serve via https and redirect http to https</li></ul> |
150+
| MASS_VHOST_SSL_GEN | bool | `0` | `0`: Do not generate an ssl certificate<br/> `1`: Generate self-signed certificate automatically |
151+
| MASS_VHOST_TLD | string | `.loc`| 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.<br/><strong>Default:</strong>`<project>.loc`<br/><strong>Example:</strong><br/>Path: `/shared/httpd/temp`<br/>`MASS_VHOST_TLD=.lan`<br/>Server name: `temp.lan`<br/><strong>Example:</strong><br/>Path:`/shared/httpd/api`<br/>`MASS_VHOST_TLD=.example.com`<br/>Server name: `api.example.com` |
145152
| 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.<br/>`/shared/httpd/<project>/$MASS_VHOST_DOCROOT/`<br/><strong>Default:</strong><br/>`/shared/httpd/<project>/htdocs/` |
146153
| 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.<br/>`/shared/httpd/<project>/$MASS_VHOST_TPL/`<br/><strong>Resulting default path:</strong><br/>`/shared/httpd/<project>/cfg/` |
147154

@@ -159,7 +166,8 @@ This Docker container adds a lot of injectables in order to customize it to your
159166

160167
| Docker | Description |
161168
|--------|-------------|
162-
| 80 | Nginx listening Port |
169+
| 80 | HTTP listening Port |
170+
| 443 | HTTPS listening Port |
163171

164172

165173
## Examples
@@ -247,8 +255,5 @@ It allows any of the following combinations:
247255
## Version
248256

249257
```
250-
nginx version: nginx/1.12.1
251-
built by gcc 6.3.0 20170516 (Debian 6.3.0-18)
252-
built with OpenSSL 1.1.0f 25 May 2017
253-
TLS SNI support enabled
258+
nginx version: nginx/1.14.0
254259
```

build/docker-attach.sh

Lines changed: 0 additions & 63 deletions
This file was deleted.

build/docker-build.sh

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
### Globals
66
###
77
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.."
8-
8+
VEND=devilbox
9+
NAME=nginx-stable
910

1011
###
1112
### Funcs
@@ -32,23 +33,6 @@ if [ ! -f "${CWD}/Dockerfile" ]; then
3233
exit 1
3334
fi
3435

35-
# Test Docker name
36-
if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
37-
echo "No 'image' LABEL found"
38-
exit
39-
fi
40-
41-
# Test Docker vendor
42-
if ! grep -q 'vendor=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
43-
echo "No 'vendor' LABEL found"
44-
exit
45-
fi
46-
47-
# Retrieve values
48-
NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
49-
VEND="$( grep -Eo 'vendor="(.*)"' "${CWD}/Dockerfile" | awk -F'"' '{print $2}' )"
50-
DATE="$( date '+%Y-%m-%d' )"
51-
5236

5337
###
5438
### Update Base
@@ -61,21 +45,17 @@ run "docker pull ${MY_BASE}"
6145
### Build
6246
###
6347

64-
# Update build date
65-
run "sed -i'' 's/build-date=\".*\"/build-date=\"${DATE}\"/g' ${CWD}/Dockerfile"
66-
6748
# Build Docker
6849
run "docker build -t ${VEND}/${NAME} ${CWD}"
6950

7051

7152
###
7253
### Retrieve information afterwards and Update README.md
7354
###
74-
docker run -d --rm --name my_tmp_${NAME} -t ${VEND}/${NAME}
75-
INFO="$( docker exec my_tmp_${NAME} httpd -V | grep -E '^Server.*(version|built|Module|loaded|MPM)' )"
76-
docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')" > /dev/null
55+
DID="$( docker run -d --rm -t ${VEND}/${NAME} )"
56+
INFO="$( docker exec "${DID}" nginx -v 2>&1 )"
57+
docker stop "${DID}"
7758

78-
INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space
7959
echo "${INFO}"
8060

8161
sed -i'' '/##[[:space:]]Version/q' "${CWD}/README.md"

0 commit comments

Comments
 (0)