Skip to content

Commit

Permalink
Refactor h2load Dockerfile
Browse files Browse the repository at this point in the history
- Replaced `as` with `AS` for Dockerfile convention.
- Used `WORKDIR` instead of `cd` for better readability.
- Quoted variables to prevent word splitting and globbing.
- Combined `apk` commands with `--no-cache` to optimize package installation.
- Update OpenSSL
  • Loading branch information
Hawazyn committed Dec 1, 2024
1 parent d7db9b5 commit 339dad7
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions h2load/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
# Multi-stage build: First the full builder image:

# define the alpine image version to use
# Define the alpine image version to use
ARG ALPINE_VERSION=3.20

FROM alpine:${ALPINE_VERSION} as intermediate

ENV DEBIAN_FRONTEND=noninteractive
# Set the installation directory
ARG INSTALLDIR=/opt/oqssa

# define the openssl tag to be used
ARG OPENSSL_TAG=openssl-3.3.2
FROM alpine:${ALPINE_VERSION} AS intermediate
ARG INSTALLDIR

# define the liboqs tag to be used
# Define version tags for dependencies
ARG OPENSSL_TAG=openssl-3.4.0
ARG LIBOQS_TAG=0.11.0

# define the oqsprovider tag to be used
ARG OQSPROVIDER_TAG=0.7.0

# define the nghttp2 tag to be used
ARG NGHTTP2_TAG=v1.64.0

ARG INSTALLDIR=/opt/oqssa

# Update image and apt software
RUN apk update && apk upgrade

# All build prerequisites for the various software packages:
RUN apk add bash git g++ make cmake ninja autoconf automake libtool \
RUN apk --no-cache add bash git g++ make cmake ninja autoconf automake libtool \
libev-dev libevent-dev openssl-dev openssl zlib c-ares-dev pkgconfig \
linux-headers zlib-dev jansson-dev

Expand All @@ -38,15 +29,16 @@ RUN git clone --depth 1 --branch ${LIBOQS_TAG} https://github.com/open-quantum-s
git clone --depth 1 --branch ${NGHTTP2_TAG} https://github.com/nghttp2/nghttp2.git

# build liboqs
WORKDIR /opt/liboqs
RUN mkdir build && cd build && cmake -GNinja -DCMAKE_INSTALL_PREFIX=${INSTALLDIR} .. && ninja && ninja install
WORKDIR /opt/liboqs/build
RUN cmake -GNinja -DCMAKE_INSTALL_PREFIX=${INSTALLDIR} .. \
&& ninja && ninja install

# build openssl 3
WORKDIR /opt/openssl
RUN LDFLAGS="-Wl,-rpath -Wl,${INSTALLDIR}/lib64" ./config shared --prefix=${INSTALLDIR} && \
make ${MAKE_DEFINES} && make install_sw install_ssldirs && \
if [ -d ${INSTALLDIR}/lib64 ]; then ln -s ${INSTALLDIR}/lib64 ${INSTALLDIR}/lib; fi && \
if [ -d ${INSTALLDIR}/lib ]; then ln -s ${INSTALLDIR}/lib ${INSTALLDIR}/lib64; fi
RUN LDFLAGS="-Wl,-rpath -Wl,${INSTALLDIR}/lib64" ./config shared --prefix="${INSTALLDIR}" && \
make -j"$(nproc)" && make install_sw install_ssldirs && \
if [ -d "${INSTALLDIR}/lib64" ]; then ln -s "${INSTALLDIR}/lib64" "${INSTALLDIR}/lib"; fi && \
if [ -d "${INSTALLDIR}/lib" ]; then ln -s "${INSTALLDIR}/lib" "${INSTALLDIR}/lib64"; fi

# build & install provider (and activate by default)
WORKDIR /opt/oqs-provider
Expand All @@ -59,24 +51,22 @@ RUN ln -s ../openssl . && \
sed -i "s/providers = provider_sect/providers = provider_sect\nssl_conf = ssl_sect\n\n\[ssl_sect\]\nsystem_default = system_default_sect\n\n\[system_default_sect\]\nGroups = \$ENV\:\:KEM_ALG\n/g" /opt/oqssa/ssl/openssl.cnf && \
sed -i "s/\# Use this in order to automatically load providers/\# Set default KEM alg if not set via environment variable\nKEM_ALG = kyber512\n\n# Use this in order to automatically load providers/g" /opt/oqssa/ssl/openssl.cnf


# build nghttp2
WORKDIR /opt/nghttp2
RUN LD_LIBRARY_PATH=${INSTALLDIR}/lib64 autoreconf -i && automake && autoconf && ./configure \
PKG_CONFIG_PATH="/opt/oqssa/lib64/pkgconfig" && make -j$(nproc) install
RUN LD_LIBRARY_PATH="${INSTALLDIR}/lib64" autoreconf -i && automake && autoconf && ./configure \
PKG_CONFIG_PATH="/opt/oqssa/lib64/pkgconfig" && make -j"$(nproc)" install

# Copy all required shared object dependencies to a single directory
RUN mkdir /opt/lib && cd /opt/lib && \
cp /usr/local/lib/libnghttp2.so.* . && \
cp /usr/lib/libev.so.* . && \
cp /opt/oqssa/lib64/libssl.so.* . && \
cp /opt/oqssa/lib64/libcrypto.so.* . && \
cp /usr/lib/libstdc++.so.* . && \
cp /usr/lib/libgcc_s.so.* .
WORKDIR /opt/lib
RUN cp /usr/local/lib/libnghttp2.so.* . && \
cp /usr/lib/libev.so.* . && \
cp /opt/oqssa/lib64/libssl.so.* . && \
cp /opt/oqssa/lib64/libcrypto.so.* . && \
cp /usr/lib/libstdc++.so.* . && \
cp /usr/lib/libgcc_s.so.* .

## second stage: Only create minimal image without build tooling and intermediate build results generated above:
FROM alpine:${ALPINE_VERSION} as dev
ENV DEBIAN_FRONTEND=noninteractive
FROM alpine:${ALPINE_VERSION} AS dev

# copy executable
COPY --from=intermediate /usr/local/bin/h2load /usr/local/bin
Expand Down

0 comments on commit 339dad7

Please sign in to comment.