Skip to content

Commit c27bd53

Browse files
committed
feat(router): image without development libraries to reduce the size.
1 parent e8102fb commit c27bd53

8 files changed

Lines changed: 84 additions & 48 deletions

File tree

router/Dockerfile

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM ubuntu:14.04
1+
FROM ubuntu-debootstrap:14.04
22

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,12 @@ 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+
RUN mkdir /nginx && tar zxpvf /app/nginx.tgz -C /nginx && rm /app/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ done
5353

5454
# spawn the service in the background
5555
echo "Starting Nginx..."
56-
/usr/sbin/nginx &
56+
/nginx/sbin/nginx &
5757
SERVICE_PID=$!
5858

5959
# smart shutdown on SIGINT and SIGTERM

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 ! /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 = "/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 = "/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 /nginx -czf /nginx.tgz .

router/parent/build.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
cd /tmp
4+
5+
export VERSION_NGINX=nginx-1.6.2
6+
export VERSION_TCP_PROXY=v0.4.5
7+
8+
# URLs to the source directories
9+
export SOURCE_NGINX=http://nginx.org/download
10+
export SOURCE_TCP_PROXY=https://github.com/yaoweibin/nginx_tcp_proxy_module/archive
11+
12+
export BPATH=`pwd`/build
13+
export PREFIX=/deis
14+
export STATICLIBSSL="$PREFIX"
15+
16+
rm -rf $PREFIX
17+
mkdir $PREFIX
18+
19+
# install required packages to build
20+
apt-get update \
21+
&& apt-get install -y patch curl wget build-essential \
22+
libpcre3 libpcre3-dev libssl-dev libgeoip-dev zlib1g-dev
23+
24+
# where the installers are
25+
mkdir $BPATH
26+
27+
# grab the source files
28+
wget -P $BPATH ${SOURCE_NGINX}/${VERSION_NGINX}.tar.gz
29+
wget -P $BPATH ${SOURCE_TCP_PROXY}/${VERSION_TCP_PROXY}.tar.gz
30+
31+
32+
# expand the source files
33+
cd $BPATH
34+
tar xzf $VERSION_NGINX.tar.gz
35+
tar xzf $VERSION_TCP_PROXY.tar.gz
36+
37+
# build nginx
38+
cd $BPATH/$VERSION_NGINX
39+
40+
patch -p1 < /$BPATH/nginx_tcp_proxy_module-0.4.5/tcp.patch
41+
42+
./configure \
43+
--prefix=/nginx \
44+
--pid-path=/run/nginx.pid \
45+
--with-debug \
46+
--with-pcre-jit \
47+
--with-ipv6 \
48+
--with-http_ssl_module \
49+
--with-http_stub_status_module \
50+
--with-http_realip_module \
51+
--with-http_auth_request_module \
52+
--with-http_addition_module \
53+
--with-http_dav_module \
54+
--with-http_geoip_module \
55+
--with-http_gzip_static_module \
56+
--with-http_spdy_module \
57+
--with-http_sub_module \
58+
--with-mail \
59+
--with-mail_ssl_module \
60+
--add-module=$BPATH/nginx_tcp_proxy_module-0.4.5 \
61+
&& 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 /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)