Skip to content

Commit 5211c44

Browse files
author
Matthew Fisher
committed
Merge pull request #1986 from aledbf/reduce_router_image_size
feat(router): image without development libraries to reduce the size.
2 parents 6ddac3d + 0b6635b commit 5211c44

8 files changed

Lines changed: 84 additions & 53 deletions

File tree

router/Dockerfile

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ubuntu:14.04
33
ENV DEBIAN_FRONTEND noninteractive
44

55
# install common packages
6-
RUN apt-get update && apt-get install -y curl
6+
RUN apt-get update && apt-get install -y libgeoip1 curl && apt-get clean
77

88
# install etcdctl
99
RUN curl -sSL -o /usr/local/bin/etcdctl https://s3-us-west-2.amazonaws.com/opdemand/etcdctl-v0.4.6 \
@@ -13,47 +13,14 @@ RUN curl -sSL -o /usr/local/bin/etcdctl https://s3-us-west-2.amazonaws.com/opdem
1313
RUN curl -sSL -o /usr/local/bin/confd https://s3-us-west-2.amazonaws.com/opdemand/confd-v0.5.0-json \
1414
&& chmod +x /usr/local/bin/confd
1515

16-
# install build and runtime packages
17-
RUN apt-get update && \
18-
apt-get install -yq patch libpcre3 libpcre3-dev libssl-dev libgeoip-dev gcc make
19-
20-
# build nginx+tcp_proxy from source
21-
RUN curl -sSL http://nginx.org/download/nginx-1.6.2.tar.gz | tar -C /tmp -xz
22-
RUN curl -sSL https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/v0.4.5.tar.gz | tar -C /tmp -xz
23-
RUN cd /tmp/nginx-1.6.2 \
24-
&& patch -p1 < /tmp/nginx_tcp_proxy_module-0.4.5/tcp.patch \
25-
&& ./configure \
26-
--prefix=/var/lib/nginx \
27-
--sbin-path=/usr/sbin/nginx \
28-
--conf-path=/etc/nginx/nginx.conf \
29-
--http-log-path=/var/log/nginx/access.log \
30-
--error-log-path=/var/log/nginx/error.log \
31-
--lock-path=/var/lock/nginx.lock \
32-
--pid-path=/run/nginx.pid \
33-
--http-client-body-temp-path=/var/lib/nginx/body \
34-
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
35-
--http-proxy-temp-path=/var/lib/nginx/proxy \
36-
--http-scgi-temp-path=/var/lib/nginx/scgi \
37-
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
38-
--with-debug \
39-
--with-pcre-jit \
40-
--with-ipv6 \
41-
--with-http_ssl_module \
42-
--with-http_stub_status_module \
43-
--with-http_realip_module \
44-
--with-http_auth_request_module \
45-
--with-http_addition_module \
46-
--with-http_dav_module \
47-
--with-http_geoip_module \
48-
--with-http_gzip_static_module \
49-
--with-http_spdy_module \
50-
--with-http_sub_module \
51-
--with-mail \
52-
--with-mail_ssl_module \
53-
--add-module=/tmp/nginx_tcp_proxy_module-0.4.5 \
54-
&& make && make install
55-
5616
WORKDIR /app
17+
5718
EXPOSE 80 2222
19+
5820
CMD ["/app/bin/boot"]
21+
5922
ADD . /app
23+
24+
ADD nginx.tgz /opt/nginx
25+
26+
RUN rm nginx.tgz

router/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
55
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
66

77
build: check-docker
8-
docker build -t $(IMAGE) .
8+
cd parent && docker build -t deis/binary-router .
9+
docker cp `docker run -d deis/binary-router`:/nginx.tgz .
10+
docker build -t $(IMAGE) .
11+
rm nginx.tgz
912

1013
clean: check-docker check-registry
1114
docker rmi $(IMAGE)

router/bin/boot

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ etcd_set_default gzipVary on
4545
etcd_set_default gzipDisable "\"msie6\""
4646
etcd_set_default gzipTypes "application/x-javascript application/xhtml+xml application/xml application/xml+rss application/json text/css text/javascript text/plain text/xml"
4747

48-
# wait for confd to run once and install initial templates
49-
until confd -onetime -node $ETCD -config-file /app/confd.toml >/dev/null 2>/dev/null; do
50-
echo "router: waiting for confd to write initial templates..."
51-
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
52-
done
53-
5448
# spawn the service in the background
5549
echo "Starting Nginx..."
56-
/usr/sbin/nginx &
50+
/opt/nginx/sbin/nginx &
5751
SERVICE_PID=$!
5852

5953
# smart shutdown on SIGINT and SIGTERM
@@ -64,6 +58,12 @@ function on_exit() {
6458
}
6559
trap on_exit INT TERM
6660

61+
# wait for confd to run once and install initial templates
62+
until confd -onetime -node $ETCD -config-file /app/confd.toml >/dev/null 2>/dev/null; do
63+
echo "router: waiting for confd to write initial templates..."
64+
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
65+
done
66+
6767
# spawn confd in the background to update services based on etcd changes
6868
confd -node $ETCD -config-file /app/confd.toml &
6969
CONFD_PID=$!

router/bin/check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ if grep -q "<no value>" $1 ; then
77
exit 1
88
fi
99

10-
if ! /usr/sbin/nginx -t -c $1 ; then
10+
if ! /opt/nginx/sbin/nginx -t -c $1 ; then
1111
exit 1
1212
fi

router/conf.d/nginx.conf.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[template]
22
src = "nginx.conf"
3-
dest = "/etc/nginx/nginx.conf"
3+
dest = "/opt/nginx/conf/nginx.conf"
44
uid = 0
55
gid = 0
66
mode = "0644"
@@ -12,4 +12,4 @@ keys = [
1212
"/deis/builder",
1313
]
1414
check_cmd = "/app/bin/check {{ .src }}"
15-
reload_cmd = "/usr/sbin/nginx -s reload"
15+
reload_cmd = "/opt/nginx/sbin/nginx -s reload"

router/parent/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ubuntu:14.04
2+
3+
ADD . /tmp
4+
5+
RUN /tmp/build.sh
6+
7+
RUN tar -C /opt/nginx -czf /nginx.tgz .

router/parent/build.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
export VERSION_NGINX=nginx-1.6.2
4+
export VERSION_TCP_PROXY=0.4.5
5+
6+
export BUILD_PATH=/tmp/build
7+
8+
# nginx installation directory
9+
export PREFIX=/opt/nginx
10+
11+
rm -rf $PREFIX
12+
mkdir $PREFIX
13+
14+
mkdir $BUILD_PATH
15+
cd $BUILD_PATH
16+
17+
# install required packages to build
18+
apt-get update \
19+
&& apt-get install -y patch curl build-essential \
20+
libpcre3 libpcre3-dev libssl-dev libgeoip-dev zlib1g-dev
21+
22+
# grab the source files
23+
curl -sSL http://nginx.org/download/$VERSION_NGINX.tar.gz -o $BUILD_PATH/$VERSION_NGINX.tar.gz
24+
curl -sSL https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/v$VERSION_TCP_PROXY.tar.gz -o $BUILD_PATH/$VERSION_TCP_PROXY.tar.gz
25+
26+
# expand the source files
27+
tar xzf $VERSION_NGINX.tar.gz
28+
tar xzf $VERSION_TCP_PROXY.tar.gz
29+
30+
# build nginx
31+
cd $BUILD_PATH/$VERSION_NGINX
32+
33+
patch -p1 < $BUILD_PATH/nginx_tcp_proxy_module-$VERSION_TCP_PROXY/tcp.patch
34+
35+
./configure \
36+
--prefix=$PREFIX \
37+
--pid-path=/run/nginx.pid \
38+
--with-debug \
39+
--with-pcre-jit \
40+
--with-ipv6 \
41+
--with-http_ssl_module \
42+
--with-http_stub_status_module \
43+
--with-http_realip_module \
44+
--with-http_auth_request_module \
45+
--with-http_addition_module \
46+
--with-http_dav_module \
47+
--with-http_geoip_module \
48+
--with-http_gzip_static_module \
49+
--with-http_spdy_module \
50+
--with-http_sub_module \
51+
--with-mail \
52+
--with-mail_ssl_module \
53+
--add-module=$BUILD_PATH/nginx_tcp_proxy_module-$VERSION_TCP_PROXY \
54+
&& make && make install

router/templates/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ http {
1919
types_hash_max_size 2048;
2020
server_names_hash_bucket_size 64;
2121

22-
include /etc/nginx/mime.types;
22+
include /opt/nginx/conf/mime.types;
2323
default_type application/octet-stream;
2424
{{ if .deis_router_gzip }}
2525
gzip {{ .deis_router_gzip }};

0 commit comments

Comments
 (0)