Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file: Dockerfile-jemalloc #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions Dockerfile-jemalloc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
ARG GOLANG_VERSION=1.14
FROM golang:${GOLANG_VERSION} as builder

ARG IMAGINARY_VERSION=dev
ARG LIBVIPS_VERSION=8.10.0
ARG GOLANGCILINT_VERSION=1.29.0

# Installs libvips + required libraries
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install --no-install-recommends -y \
ca-certificates \
automake build-essential curl \
gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg62-turbo-dev libpng-dev \
libwebp-dev libtiff5-dev libgif-dev libexif-dev libxml2-dev libpoppler-glib-dev \
swig libmagickwand-dev libpango1.0-dev libmatio-dev libopenslide-dev libcfitsio-dev \
libgsf-1-dev fftw3-dev liborc-0.4-dev librsvg2-dev libimagequant-dev libheif-dev && \
cd /tmp && \
curl -fsSLO https://github.com/libvips/libvips/releases/download/v${LIBVIPS_VERSION}/vips-${LIBVIPS_VERSION}.tar.gz && \
tar zvxf vips-${LIBVIPS_VERSION}.tar.gz && \
cd /tmp/vips-${LIBVIPS_VERSION} && \
CFLAGS="-g -O3" CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -g -O3" \
./configure \
--disable-debug \
--disable-dependency-tracking \
--disable-introspection \
--disable-static \
--enable-gtk-doc-html=no \
--enable-gtk-doc=no \
--enable-pyvips8=no && \
make && \
make install && \
ldconfig

# Installing golangci-lint
WORKDIR /tmp
RUN curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v${GOLANGCILINT_VERSION}

WORKDIR ${GOPATH}/src/github.com/h2non/imaginary

# Cache go modules
ENV GO111MODULE=on

COPY go.mod .
COPY go.sum .

RUN go mod download

# Copy imaginary sources
COPY . .

# Run quality control
RUN go test -test.v -test.race -test.covermode=atomic .
RUN golangci-lint run .

# Compile imaginary
RUN go build -a \
-o ${GOPATH}/bin/imaginary \
-ldflags="-s -w -h -X main.Version=${IMAGINARY_VERSION}" \
github.com/h2non/imaginary

FROM debian:buster-slim

ARG IMAGINARY_VERSION

LABEL maintainer="[email protected]" \
org.label-schema.description="Fast, simple, scalable HTTP microservice for high-level image processing with first-class Docker support" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://github.com/h2non/imaginary" \
org.label-schema.vcs-url="https://github.com/h2non/imaginary" \
org.label-schema.version="${IMAGINARY_VERSION}"

COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /go/bin/imaginary /usr/local/bin/imaginary
COPY --from=builder /etc/ssl/certs /etc/ssl/certs

# Install runtime dependencies
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install --no-install-recommends -y \
procps libglib2.0-0 libjpeg62-turbo libpng16-16 libopenexr23 \
libwebp6 libwebpmux3 libwebpdemux2 libtiff5 libgif7 libexif12 libxml2 libpoppler-glib8 \
libmagickwand-6.q16-6 libpango1.0-0 libmatio4 libopenslide0 \
libgsf-1-114 fftw3 liborc-0.4-0 librsvg2-2 libcfitsio7 libimagequant0 libheif1 && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Server port to listen
ENV PORT 9000

# use jemalloc instead of ptmalloc
ADD https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2 /tmp/jemalloc-5.2.1.tar.bz2
RUN apt-get update && apt install -y bzip2 gcc make autoconf
RUN cd /tmp \
&& tar -jxvf jemalloc-5.2.1.tar.bz2 \
&& cd jemalloc-5.2.1 \
&& ./configure --enable-prof && make && make install \
&& rm -rf /tmp/*
ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so


# Drop privileges for non-UID mapped environments
USER nobody

# Run the entrypoint command by default when the container starts.
ENTRYPOINT ["/usr/local/bin/imaginary"]

# Expose the server TCP port
EXPOSE ${PORT}