From eaba263290b8f7cf8f7b3f89516b96335e79a22a Mon Sep 17 00:00:00 2001 From: Radu Ghiorma Date: Fri, 12 Jan 2024 22:48:44 +0200 Subject: [PATCH] Dockerfile for 1brc --- .dockerignore | 13 +++++ .gitignore | 2 +- .mvn/wrapper/maven-wrapper.properties | 2 +- Dockerfile | 78 +++++++++++++++++++++++++++ README.md | 20 +++++++ pom.xml | 2 +- 6 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..f44f7b096b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.github +.git +.idea +*.log +*.zip +measurements.txt +measurements_1B.txt +out_expected.txt +out_expected_1B.txt +target/ + +Dockerfile +.env \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6a1ef02bcb..63e0c144be 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ out/ # 1BRC /measurements*.txt /*.out -out_expected.txt +out_expected*.txt diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index e347d2d249..2ff8f6d162 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/4.0.0-alpha-8/apache-maven-4.0.0-alpha-8-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..346b95f3c1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,78 @@ +# +# Copyright 2023 The original authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# syntax=docker/dockerfile:1 +# Use an official Fedora Linux as a base image +FROM fedora:latest as build-sdkman +ARG JAVA_VERSIONS +# Maintain a variable providing a list of required packages (for easier maintenance) +ENV _PACKAGES="curl zip unzip" +# Maintain a variable providing a list of java versions to always install (for easier maintenance) +ENV _JAVA_VERSIONS="21.0.1-open" +# Install necessary packages +RUN dnf -y update && dnf -y install ${_PACKAGES} +# Clear DNF caches to reduce image size +RUN dnf clean all +# Install SDKMAN! +RUN curl -s "https://get.sdkman.io" | bash +# this SHELL command is needed to allow using source +SHELL ["/bin/bash", "-c"] +# Look for SDKMAN and load it into the shell session +RUN echo "source /root/.sdkman/bin/sdkman-init.sh" >> /root/.bashrc +# Install default java versions +RUN for JAVA_VERSION in $_JAVA_VERSIONS; do source "/root/.sdkman/bin/sdkman-init.sh" && sdk install java $JAVA_VERSION; done +# Install jbang +RUN source "/root/.sdkman/bin/sdkman-init.sh" && sdk install jbang +# Install SDK versions +RUN for JAVA_VERSION in $JAVA_VERSIONS; do source "/root/.sdkman/bin/sdkman-init.sh" && sdk install java $JAVA_VERSION; done + +FROM fedora:latest as build-1brc +ARG PACKAGES +# Maintain a variable providing a list of required packages (for easier maintenance) +ENV _PACKAGES="diffutils perl-Digest-SHA hyperfine jq numactl bc gcc zlib-devel git" + +COPY --from=build-sdkman /root/.sdkman /root/.sdkman +# Source sdkman in all shells (alternative to adding to PATH) +# this SHELL command is needed to allow using source +SHELL ["/bin/bash", "-c"] +# Look for SDKMAN and load it into the shell session +RUN echo "source /root/.sdkman/bin/sdkman-init.sh" >> /root/.bashrc +# Manually add sdkman to PATH +ENV PATH="/root/.sdkman/bin:$PATH" +# Install necessary packages +RUN dnf -y update && dnf -y install ${_PACKAGES} +# Install requested extra build packages +RUN if [ -n "$PACKAGES" ] ; then dnf -y install $PACKAGES ; else echo "PACKAGES is empty, run docker build --build_arg PACKAGES= ." ; fi +# Clear DNF caches to reduce image size +RUN dnf clean all + +ARG REPOSITORY="https://github.com/gunnarmorling/1brc.git" +# Checkeout the repository +RUN git clone $REPOSITORY + +WORKDIR 1brc +# Initialize SDKMAN and download project dependencies to work offline +RUN source "/root/.sdkman/bin/sdkman-init.sh" \ +# Cache local repo + && ./mvnw dependency:go-offline \ +# Build the project + && ./mvnw package + +FROM build-1brc +# Set the working directory in the container to /app +WORKDIR /1brc +# Copy the files from the workspace +COPY / . \ No newline at end of file diff --git a/README.md b/README.md index 083400deee..6e52506225 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,26 @@ or directly on the .java file: When you run this, it will generate a flamegraph in profile.html. You can then open this in a browser and see where your program is spending its time. +## Building the Docker image + +Build the image by default it will install java 21.0.1-open. + +❗To keep the image size reasonable it will not generate the measurements_1B.txt and out_expected.txt files + +```shell + docker build . -t 1brc +``` +To configure the build image you can pass the following build_arg +* --build-arg JAVA_VERSION=\ +* --build-arg PACKAGES=\ +```shell + docker build -build-arg JAVA_VERSIONS="21.0.1-graal 21.0.1-graalce" . -t 1brc +``` +When running the container you need to specify the measurements_1B.txt and out_expected.txt files. +```shell + docker run -it -v ${pwd}/measurements_1B.txt:/1brc/measurements_1B.txt -v ${pwd}/out_expected_1B.txt:/1brc/out_expected.txt 1brc +``` + ## Rules and limits * Any of these Java distributions may be used: diff --git a/pom.xml b/pom.xml index 51226a3d65..72d7ad8ab9 100644 --- a/pom.xml +++ b/pom.xml @@ -207,7 +207,7 @@ **/.dontdelete **/measurements*.txt **/measurements*.out - out_expected.txt + out_expected*.txt github_users.txt src/main/java/dev/morling/onebrc/CalculateAverage_cliffclick.java