Skip to content

Commit

Permalink
Migrate to alpine linux
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Dec 27, 2019
1 parent 9e3e538 commit 4cad130
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 74 deletions.
4 changes: 0 additions & 4 deletions images/nginx/Makefile
Expand Up @@ -32,9 +32,6 @@ IMGNAME = nginx
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)

# Set default base image dynamically for each arch
BASEIMAGE?=quay.io/kubernetes-ingress-controller/debian-base-$(ARCH):0.1

ifeq ($(ARCH),arm)
QEMUARCH=arm
endif
Expand Down Expand Up @@ -62,7 +59,6 @@ all-push: $(addprefix sub-push-,$(ALL_ARCH))
container: .container-$(ARCH)
.container-$(ARCH):
cp -r ./rootfs/* $(TEMP_DIR)
cd $(TEMP_DIR) && $(SED_I) 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile
cd $(TEMP_DIR) && $(SED_I) "s|ARCH|$(QEMUARCH)|g" Dockerfile

ifeq ($(ARCH),amd64)
Expand Down
6 changes: 2 additions & 4 deletions images/nginx/README.md
@@ -1,6 +1,4 @@
OpenResty base image using [debian-base](https://quay.io/kubernetes-ingress-controller/debian-base-amd64)

OpenResty® is a dynamic web platform based on NGINX and LuaJIT.
NGINX base image using [alpine](https://www.alpinelinux.org/)

This custom image contains:

Expand All @@ -20,7 +18,7 @@ This image provides a default configuration file with no backend servers.
_Using docker_

```console
docker run -v /some/nginx.con:/etc/nginx/nginx.conf:ro quay.io/kubernetes-ingress-controller/nginx:0.90
docker run -v /some/nginx.con:/etc/nginx/nginx.conf:ro quay.io/kubernetes-ingress-controller/nginx:0.95
```

_Creating a replication controller_
Expand Down
4 changes: 2 additions & 2 deletions images/nginx/rc.yaml
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Service
metadata:
name: nginxsvc
name: nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
Expand Down Expand Up @@ -38,7 +38,7 @@ spec:
spec:
containers:
- name: nginx
image: quay.io/kubernetes-ingress-controller/nginx:0.90
image: quay.io/kubernetes-ingress-controller/nginx:0.95
ports:
- containerPort: 80
- containerPort: 443
43 changes: 19 additions & 24 deletions images/nginx/rootfs/Dockerfile
Expand Up @@ -13,18 +13,17 @@
# limitations under the License.


FROM BASEIMAGE as builder
FROM alpine:3.11 as builder

CROSS_BUILD_COPY qemu-ARCH-static /usr/bin/

RUN clean-install bash

COPY . /

RUN /build.sh
RUN apk add -U bash \
&& /build.sh

# Use a multi-stage build
FROM BASEIMAGE
FROM alpine:3.11

ENV PATH=$PATH:/usr/local/luajit/bin:/usr/local/nginx/sbin:/usr/local/nginx/bin

Expand All @@ -33,33 +32,29 @@ ENV LUA_CPATH="/usr/local/lib/lua/?/?.so;/usr/local/lib/lua/?.so;;"

COPY --from=builder /usr/local /usr/local
COPY --from=builder /opt /opt
COPY --chown=www-data:www-data --from=builder /etc/nginx /etc/nginx
COPY --from=builder /etc/nginx /etc/nginx

RUN apt-get update && apt-get dist-upgrade -y \
&& clean-install \
RUN apk add -U --no-cache \
bash \
openssl \
pcre \
zlib \
geoip \
curl ca-certificates \
libgeoip1 \
patch \
libpcre3 \
zlib1g \
libaio1 \
openssl \
util-linux \
lmdb-utils \
libcurl4 \
libprotobuf17 \
libz3-4 \
procps \
libxml2 libpcre++0v5 \
liblmdb0 \
libmaxminddb0 \
yajl \
lmdb \
libxml2 \
libmaxminddb \
yaml-cpp \
dumb-init \
nano \
libyaml-cpp0.6 \
libyajl2 \
tzdata \
&& ln -s /usr/local/nginx/sbin/nginx /sbin/nginx \
&& ln -s /usr/local/lib/mimalloc-1.2/libmimalloc.so /usr/local/lib/libmimalloc.so \
&& addgroup -Sg 101 www-data \
&& adduser -S -D -H -u 101 -h /usr/local/nginx \
-s /sbin/nologin -G www-data -g www-data www-data \
&& bash -eu -c ' \
writeDirs=( \
/var/log/nginx \
Expand Down
70 changes: 30 additions & 40 deletions images/nginx/rootfs/build.sh
Expand Up @@ -67,47 +67,47 @@ get_src()
rm -rf "$f"
}

apt-get update && apt-get dist-upgrade -y
apk update
apk upgrade

# install required packages to build
clean-install \
apk add \
bash \
build-essential \
gcc \
clang \
libc-dev \
make \
automake \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
alpine-sdk \
findutils \
curl ca-certificates \
libgeoip1 \
libgeoip-dev \
geoip-dev \
patch \
libpcre3 \
libpcre3-dev \
libssl-dev \
zlib1g \
zlib1g-dev \
libaio1 \
libaio-dev \
openssl \
libperl-dev \
cmake \
util-linux \
lmdb-utils \
lmdb-tools \
wget \
libcurl4-openssl-dev \
libprotobuf-dev protobuf-compiler \
libz-dev \
git g++ pkgconf flex bison doxygen libyajl-dev liblmdb-dev libtool dh-autoreconf libxml2 libpcre++-dev libxml2-dev \
curl-dev \
libprotobuf \
git g++ pkgconf flex bison doxygen yajl-dev lmdb-dev libtool autoconf libxml2 pcre-dev libxml2-dev \
python \
libmaxminddb-dev \
bc \
unzip \
dos2unix mercurial \
libyaml-cpp0.6 \
|| exit 1

# https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1667178.html
if [[ ${ARCH} == "armv7l" ]]; then
echo "Fixing ca-certificates"
touch /etc/ssl/certs/ca-certificates.crt
c_rehash
fi
yaml-cpp

mkdir -p /etc/nginx

Expand Down Expand Up @@ -229,18 +229,6 @@ cd "$BUILD_PATH/luajit2-$LUAJIT_VERSION"
make CCDEBUG=-g
make install

if [[ ${ARCH} == "armv7l" ]]; then
export PCRE_DIR=/usr/lib/arm-linux-gnueabihf
fi

if [[ ${ARCH} == "x86_64" ]]; then
export PCRE_DIR=/usr/lib/x86_64-linux-gnu
fi

if [[ ${ARCH} == "aarch64" ]]; then
export PCRE_DIR=/usr/lib/aarch64-linux-gnu
fi

cd "$BUILD_PATH"

# install openresty-gdb-utils
Expand Down Expand Up @@ -554,7 +542,7 @@ export LUA_INCLUDE_DIR=/usr/local/include/luajit-2.1
ln -s $LUA_INCLUDE_DIR /usr/include/lua5.1

if [[ ${ARCH} != "armv7l" ]]; then
luarocks install lrexlib-pcre 2.7.2-1 PCRE_LIBDIR=${PCRE_DIR}
luarocks install lrexlib-pcre 2.7.2-1
fi

cd "$BUILD_PATH/lua-resty-core-$LUA_RESTY_CORE"
Expand All @@ -580,7 +568,6 @@ make install
cd "$BUILD_PATH/lua-resty-string-0.11"
make install


# build Lua bridge tracer
cd "$BUILD_PATH/lua-bridge-tracer-$LUA_BRIDGE_TRACER_VERSION"
mkdir .build
Expand Down Expand Up @@ -610,6 +597,9 @@ writeDirs=( \
/var/log/nginx \
);

addgroup -Sg 101 www-data
adduser -S -D -H -u 101 -h /usr/local/nginx -s /sbin/nologin -G www-data -g www-data www-data

for dir in "${writeDirs[@]}"; do
mkdir -p ${dir};
chown -R www-data.www-data ${dir};
Expand Down

0 comments on commit 4cad130

Please sign in to comment.