Skip to content

Commit

Permalink
Add docker image for Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Sep 28, 2021
1 parent d70e272 commit 4869b5b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 30 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ jobs:
build-docker:
name: Build Docker Image
runs-on: ubuntu-20.04
strategy:
matrix:
os: [debian, alpine]
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: /tmp/.buildx-${{ matrix.os }}-cache
key: ${{ runner.os }}-buildx-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
${{ runner.os }}-buildx-${{ matrix.os }}-
- name: Output Variables
id: var
Expand Down Expand Up @@ -55,6 +58,7 @@ jobs:
uses: docker/metadata-action@v3
with:
images: opentracing/nginx-opentracing
flavor: suffix=${{ matrix.os != 'debian' && '-' || '' }}${{ matrix.os != 'debian' && matrix.os || '' }},onlatest=true
tags: |
type=edge
type=ref,event=pr
Expand All @@ -70,6 +74,7 @@ jobs:
platforms: ${{ github.event_name != 'pull_request' && env.PLATFORMS || '' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
cache-from: type=local,src=/tmp/.buildx-${{ matrix.os }}-cache
cache-to: type=local,dest=/tmp/.buildx-${{ matrix.os }}-cache,mode=max
target: final
build-args: BUILDS_OS={{ matrix.os }}
104 changes: 82 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# syntax=docker/dockerfile:1.3
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.0.0-rc.1 AS xx
ARG BUILD_OS=debian
FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:67890c41290f1639e1a2acca464192109ac4c7f599c884072cd046861ea44233 AS xx

FROM --platform=$BUILDPLATFORM debian:buster as build-base
### Build base image for debian
FROM --platform=$BUILDPLATFORM debian:buster as build-base-debian

RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
Expand All @@ -10,25 +12,57 @@ RUN apt-get update \
clang \
git \
golang \
libprotobuf-dev \
libcurl4 \
libprotobuf-dev \
libtool \
libyaml-cpp-dev \
libz-dev \
lld \
pkg-config \
protobuf-compiler \
libyaml-cpp-dev \
lld \
wget

ENV CMAKE_VERSION 3.21.2
COPY --from=xx / /
ARG TARGETPLATFORM

RUN xx-apt install -y xx-cxx-essentials zlib1g-dev libcurl4-openssl-dev libc-ares-dev libre2-dev libssl-dev libc-dev libmsgpack-dev


### Build base image for alpine
FROM --platform=$BUILDPLATFORM alpine:3.14 as build-base-alpine

RUN apk add --no-cache \
alpine-sdk \
bash \
build-base \
clang \
gcompat \
git \
libcurl \
lld \
protobuf-dev \
yaml-cpp-dev \
zlib-dev

COPY --from=xx / /
ARG TARGETPLATFORM

RUN xx-apk add --no-cache xx-cxx-essentials openssl-dev zlib-dev libgcc curl-dev msgpack-c-dev


### Build image
FROM build-base-${BUILD_OS} as build-base

ENV CMAKE_VERSION 3.21.3
RUN wget -q -O cmake-linux.sh "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-$(arch).sh" \
&& sh cmake-linux.sh -- --skip-license --prefix=/usr \
&& rm cmake-linux.sh

COPY --from=xx / /
ARG TARGETPLATFORM
RUN set -e; \
[ "$(xx-info arch)" = "ppc64le" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple; \
[ "$(xx-info arch)" = "386" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple; \
true

RUN xx-apt install -y zlib1g-dev xx-cxx-essentials libcurl4-openssl-dev libc-ares-dev libre2-dev libssl-dev libc-dev

## Build gRPC
FROM build-base as grpc
Expand Down Expand Up @@ -66,13 +100,15 @@ RUN xx-info env && git clone --depth 1 -b $OPENTRACING_CPP_VERSION https://githu
&& cd opentracing-cpp \
&& mkdir .build && cd .build \
&& cmake $(xx-clang --print-cmake-defines) \
-DCMAKE_INSTALL_PREFIX=$(xx-info sysroot)/usr/local\
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_MOCKTRACER=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF .. \
&& make -j$(nproc) install \
&& if [[ "$(xx-info sysroot)" != "/" ]]; then cp -a $(xx-info sysroot)/usr/local/lib/libopentracing.so* /usr/local/lib/; fi \
&& xx-verify /usr/local/lib/libopentracing.so


Expand All @@ -81,10 +117,12 @@ FROM opentracing-cpp as zipkin-cpp-opentracing
ARG ZIPKIN_CPP_VERSION=master
ARG TARGETPLATFORM

RUN xx-info env && git clone --depth 1 -b $ZIPKIN_CPP_VERSION https://github.com/rnburn/zipkin-cpp-opentracing.git \
RUN [ "$(xx-info vendor)" = "alpine" ] && export QEMU_LD_PREFIX=/$(xx-info); \
xx-info env && git clone --depth 1 -b $ZIPKIN_CPP_VERSION https://github.com/rnburn/zipkin-cpp-opentracing.git \
&& cd zipkin-cpp-opentracing \
&& mkdir .build && cd .build \
&& cmake $(xx-clang --print-cmake-defines) \
-DCMAKE_PREFIX_PATH=$(xx-info sysroot)/usr/local \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_STATIC_LIBS=OFF \
-DCMAKE_BUILD_TYPE=Release \
Expand Down Expand Up @@ -121,10 +159,12 @@ RUN git clone --depth 1 -b $JAEGER_CPP_VERSION https://github.com/jaegertracing/
&& printf "%s\n" "" "set(CMAKE_C_COMPILER clang)" "set(CMAKE_CXX_COMPILER clang++)" \
"set(CMAKE_ASM_COMPILER clang)" "set(PKG_CONFIG_EXECUTABLE $(xx-clang --print-prog-name=pkg-config))" \
"set(CMAKE_C_COMPILER_TARGET $(xx-clang --print-target-triple))" "set(CMAKE_CXX_COMPILER_TARGET $(xx-clang++ --print-target-triple))" \
"set(CMAKE_ASM_COMPILER_TARGET $(xx-clang --print-target-triple))" >> cmake/toolchain.cmake \
"set(CMAKE_ASM_COMPILER_TARGET $(xx-clang --print-target-triple))" \
"set(CMAKE_INSTALL_PREFIX $(xx-info sysroot)/usr/local)" >> cmake/toolchain.cmake \
&& mkdir .build \
&& cd .build \
&& cmake $(xx-clang --print-cmake-defines) \
-DCMAKE_PREFIX_PATH=$(xx-info sysroot)/usr/local \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
Expand All @@ -151,10 +191,9 @@ ARG TARGETPLATFORM

RUN xx-info env && git clone --depth 1 -b $DATADOG_VERSION https://github.com/DataDog/dd-opentracing-cpp.git \
&& cd dd-opentracing-cpp \
&& sed -i 's/cmake/cmake \$(xx-clang --print-cmake-defines)/I' scripts/install_dependencies.sh \
&& scripts/install_dependencies.sh not-opentracing not-curl not-zlib \
&& mkdir .build && cd .build \
&& cmake $(xx-clang --print-cmake-defines) \
&& cmake $(xx-clang --print-cmake-defines) \
-DCMAKE_PREFIX_PATH=$(xx-info sysroot)/usr/local \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF .. \
Expand All @@ -163,16 +202,28 @@ RUN xx-info env && git clone --depth 1 -b $DATADOG_VERSION https://github.com/Da
&& xx-verify /usr/local/lib/libdd_opentracing_plugin.so


### Build nginx-opentracing modules
FROM nginx:1.21.3 as build-nginx

COPY --from=jaeger-cpp-client /hunter /hunter
COPY . /src
### Base build image for debian
FROM nginx:1.21.3 as build-nginx-debian

RUN echo "deb-src http://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get build-dep -y nginx


### Base build image for alpine
FROM nginx:1.21.3-alpine as build-nginx-alpine
RUN apk add --no-cache \
build-base \
pcre-dev \
zlib-dev


### Build nginx-opentracing modules
FROM build-nginx-${BUILD_OS} as build-nginx

COPY --from=jaeger-cpp-client /hunter /hunter
COPY . /src

RUN curl -sSL -O https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}.tar.gz \
&& tar zxf release-${NGINX_VERSION}.tar.gz \
&& cd nginx-release-${NGINX_VERSION} \
Expand All @@ -182,12 +233,21 @@ RUN curl -sSL -O https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}
--with-cc-opt="-I/hunter/include" \
--with-ld-opt="-fPIE -fPIC -Wl,-z,relro -Wl,-z,now -L/hunter/lib" \
--with-debug \
&& make modules \
&& make -j$(nproc) modules \
&& cp objs/ngx_http_opentracing_module.so /usr/lib/nginx/modules/


### Base image for alpine
FROM nginx:1.21.3-alpine as nginx-alpine
RUN apk add --no-cache libstdc++


### Base image for debian
FROM nginx:1.21.3 as nginx-debian


### Build final image
FROM nginx:1.21.3 as final
FROM nginx-${BUILD_OS} as final

COPY --from=build-nginx /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
COPY --from=dd-opentracing-cpp /usr/local/lib/ /usr/local/lib/
Expand All @@ -197,6 +257,6 @@ COPY --from=opentracing-cpp /usr/local/lib/ /usr/local/lib/
# gRPC doesn't seem to be used
# COPY --from=grpc /usr/local/lib/ /usr/local/lib/

RUN ldconfig
RUN ldconfig /usr/local/lib/

STOPSIGNAL SIGTERM
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.PHONY: docker.build
docker.build: test
docker build -f Dockerfile -t opentracing-contrib/nginx-opentracing .
.PHONY: docker-image
docker-image:
DOCKER_BUILDKIT=1 docker build -f Dockerfile -t opentracing-contrib/nginx-opentracing --target final .

.PHONY: docker-image-alpine
docker-image-alpine:
DOCKER_BUILDKIT=1 docker build -f Dockerfile -t opentracing-contrib/nginx-opentracing --target final --build-arg BUILD_OS=alpine .

.PHONY: test
test:
Expand Down

0 comments on commit 4869b5b

Please sign in to comment.