Skip to content

Commit

Permalink
Merge pull request #2 from signalsciences/bbucher-21325-alpine-image
Browse files Browse the repository at this point in the history
Use alpine based image
  • Loading branch information
bbucher-sigsci authored Mar 31, 2020
2 parents 843f34a + be96130 commit 10e3fdf
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG NGINX_INGRESS_VERSION=${NGINX_INGRESS_VERSION:-latest}
FROM quay.io/kubernetes-ingress-controller/nginx-ingress-controller:${NGINX_INGRESS_VERSION}
ARG PKGNAME=${PKGNAME:-nginx-module-sigsci-nxo}
ARG BUILD_NUMBER=146

# Change to the root user to update the container
USER root
Expand All @@ -9,23 +10,24 @@ USER root
# NOTE: The nginx native module to be installed needs to be for
# the correct version of nginx installed; this applies
# to both nginx.org and openresty nginx distributions.
RUN apt-get update && apt-get install -y apt-transport-https gnupg lsb-release \
# Figure out which debian release/codename this is
&& CODENAME=$(lsb_release -c | sed 's/^Codename:\s*//') \
# The sid (unstable) codname is not supported, but buster (previous stable) will work
&& if [ "${CODENAME}" = "sid" ]; then CODENAME="buster"; fi \
RUN apk update && apk add --no-cache gnupg wget --virtual ./build_deps \
# Figure out which alpine release this is
&& ALPINE_RELEASE=$(cat /etc/alpine-release | sed 's/\./\_/g') \
&& ALPINE_RELEASE=${ALPINE_RELEASE::-2} \
# Figure out which nginx is installed in the container
&& NGXVERSION=$(nginx -v 2>&1 | sed 's%^[^/]*/\([0-9]*\.[0-9]*\.[0-9]*\).*%\1%') \
# Add the signal sciences apt repo
&& (curl -s -S -L https://apt.signalsciences.net/release/gpgkey | apt-key add -) \
&& (echo "deb https://apt.signalsciences.net/release/debian/ ${CODENAME} main" > /etc/apt/sources.list.d/sigsci-release.list) \
&& apt-get update \
# Download and force install the package as nginx was installed from source not package
&& apt-get download nginx-module-sigsci-nxo=${NGXVERSION}\* \
&& (dpkg --force-all -i nginx-module-sigsci-nxo_${NGXVERSION}*.deb || true) \
&& rm -f nginx-module-sigsci-nxo_${NGXVERSION}*.deb \
&& sed -i "s@^#pid.*@&\nload_module /usr/lib/nginx/modules/ngx_http_sigsci_nxo_module-${NGXVERSION}.so;\n@" /usr/local/openresty/nginx/conf/nginx.conf \
&& rm -rf /var/lib/apt/lists/*

# Get the latest version of the sigsci nginx native module
&& MODULE_VERSION=$(wget -O- -q https://dl.signalsciences.net/sigsci-module-nginx-native/VERSION) \
# Get the correct sigsci nginx native module based on alpine version, nginx version, and module version
&& wget -O /tmp/nginx-module-sigsci-nxo_${NGXVERSION}-${BUILD_NUMBER}-alpine${ALPINE_RELEASE}.tar.gz https://dl.signalsciences.net/sigsci-module-nginx-native/${MODULE_VERSION}/alpine/alpine${ALPINE_RELEASE}/nginx-module-sigsci-nxo_${NGXVERSION}-${BUILD_NUMBER}-alpine${ALPINE_RELEASE}.tar.gz \
# Manually install the sigsci native nginx module and update nginx.conf
&& tar xvfz /tmp/nginx-module-sigsci-nxo_${NGXVERSION}-${BUILD_NUMBER}-alpine${ALPINE_RELEASE}.tar.gz -C /tmp || : \
&& mkdir -p /usr/lib/nginx/modules \
&& mv /tmp/ngx_http_sigsci_nxo_module-${NGXVERSION}.so /usr/lib/nginx/modules/ngx_http_sigsci_module.so \
&& ln -s /usr/lib/nginx/modules/ngx_http_sigsci_module.so /etc/nginx/modules/ngx_http_sigsci_module.so \
&& sed -i 's@^pid.*@&\nload_module /usr/lib/nginx/modules/ngx_http_sigsci_module.so;\n@' /etc/nginx/nginx.conf \
# cleanup
&& rm /tmp/nginx-module-sigsci-nxo_${NGXVERSION}-${BUILD_NUMBER}-alpine${ALPINE_RELEASE}.tar.gz /tmp/*.so \
&& apk del --no-cache ./build_deps
# Change back to the www-data user for executing nginx at runtime
USER www-data

0 comments on commit 10e3fdf

Please sign in to comment.