Skip to content

Commit 7137222

Browse files
committed
Add SSL support
1 parent bfb0834 commit 7137222

24 files changed

+1390
-702
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" <cytopia@everythingcli.org>
33

44

55
###
6-
### Labels
6+
### Build arguments
77
###
8-
LABEL \
9-
name="cytopia's Nginx Image" \
10-
image="nginx-mainline" \
11-
vendor="devilbox" \
12-
license="MIT" \
13-
build-date="2017-10-01"
8+
ARG VHOST_GEN_GIT_REF=0.4
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: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ Find me on **[Docker Hub](https://hub.docker.com/r/devilbox/nginx-mainline)**:
2929

3030
1. Automated virtual hosts can be enabled by providing `-e MASS_VHOST_ENABLE=1`.
3131
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`
32+
3. You can optionally specify a global server name suffix via e.g.: `-e MASS_VHOST_TLD=.loc`
3333
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`)
34+
5. Allow the Docker to expose its port via `-p 80:80`.
35+
6. Have DNS names point to the IP address the container runs on (e.g. via `/etc/hosts`)
3636

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

3943
Just to give you a few examples:
4044

@@ -67,7 +71,7 @@ docker run -it \
6771
-p 80:80 \
6872
-e MASS_VHOST_ENABLE=1 \
6973
-e MASS_VHOST_DOCROOT=www \
70-
-e MASS_VHOST_TLD=.local \
74+
-e MASS_VHOST_TLD=.loc \
7175
-v /local/path:/shared/httpd \
7276
devilbox/nginx-mainline
7377
```
@@ -99,7 +103,7 @@ PHP-FPM is not included inside this Docker container, but can be enabled to cont
99103

100104
#### Disabling the default virtual host
101105

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`.
106+
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`.
103107

104108

105109
## Options
@@ -130,7 +134,10 @@ This Docker container adds a lot of injectables in order to customize it to your
130134

131135
| Variable | Type | Default | Description |
132136
|----------|------|---------|-------------|
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. |
137+
| 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. |
138+
| 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> |
139+
| MAIN_VHOST_SSL_GEN | bool | `0` | `0`: Do not generate an ssl certificate<br/> `1`: Generate self-signed certificate automatically |
140+
| 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) |
134141
| 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` |
135142
| 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` |
136143
| MAIN_VHOST_STATUS_ENABLE | bool | `0` | Enable httpd status page. |
@@ -141,7 +148,9 @@ This Docker container adds a lot of injectables in order to customize it to your
141148
| Variable | Type | Default | Description |
142149
|----------|------|---------|-------------|
143150
| 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` |
151+
| 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> |
152+
| MASS_VHOST_SSL_GEN | bool | `0` | `0`: Do not generate an ssl certificate<br/> `1`: Generate self-signed certificate automatically |
153+
| 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` |
145154
| 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/` |
146155
| 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/` |
147156

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

160169
| Docker | Description |
161170
|--------|-------------|
162-
| 80 | Nginx listening Port |
171+
| 80 | HTTP listening Port |
172+
| 443 | HTTPS listening Port |
163173

164174

165175
## Examples
@@ -247,8 +257,5 @@ It allows any of the following combinations:
247257
## Version
248258

249259
```
250-
nginx version: nginx/1.13.5
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
260+
nginx version: nginx/1.13.12
254261
```

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-mainline
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)