1+ # Build stage
2+ FROM debian:bookworm-slim as build
3+
4+ # Set up working directory for application builds
5+ WORKDIR /apps
6+
7+ # Install essential build dependencies
8+ RUN apt-get update && apt-get install -y --no-install-recommends \
9+ build-essential \
10+ git \
11+ curl \
12+ ca-certificates \
13+ libpcre3-dev \
14+ zlib1g-dev \
15+ libbz2-dev \
16+ liblzma-dev \
17+ autoconf \
18+ automake \
19+ libtool \
20+ pkg-config \
21+ libssl-dev \
22+ libopenblas-dev
23+
24+ # Install HTSlib
25+ RUN git clone https://github.com/samtools/htslib.git && \
26+ cd htslib && \
27+ git submodule update --init --recursive && \
28+ autoreconf -i && \
29+ ./configure && \
30+ make && \
31+ make install && \
32+ ldconfig
33+
34+ # Install Nim (version 1.6.10)
35+ # Nim is needed to compile somalier and its dependencies
36+ ENV NIM_VERSION="v1.6.10"
37+ RUN git clone -b ${NIM_VERSION} --depth 1 https://github.com/nim-lang/nim nim-${NIM_VERSION}/ && \
38+ cd nim-${NIM_VERSION} && \
39+ /bin/bash build_all.sh
40+ ENV PATH="/apps/nim-${NIM_VERSION}/bin:${PATH}"
41+
42+ # Install hts-nim - nim wrapper for HTSlib
43+ WORKDIR /apps
44+ RUN git clone --depth 1 https://github.com/brentp/hts-nim.git && \
45+ cd hts-nim && \
46+ nimble install -y
47+
48+ # Install slivar - somalier depends on this package for some functionality
49+ RUN git clone --depth 1 https://github.com/brentp/slivar.git
50+
51+ # Architecture-specific fix for arm64 (aarch64)
52+ # The -mpopcnt flag is x86_64-specific and causes compilation errors on arm64
53+ # arm64 has native population count instructions that are used automatically
54+ RUN if [ "$(uname -m)" = "aarch64" ]; then \
55+ find /apps/slivar -type f -name "*.nim" -exec sed -i '/-mpopcnt/d' {} \; && \
56+ find /apps/slivar -type f -name "nimble" -exec sed -i '/-mpopcnt/d' {} \; && \
57+ find /apps/slivar -type f -name "*.cfg" -exec sed -i '/-mpopcnt/d' {} \; || true; \
58+ fi
59+
60+ # Compile and install slivar
61+ RUN cd slivar && \
62+ nimble install -y
63+
64+ # Install somalier
65+ WORKDIR /apps
66+ RUN git clone --depth 1 https://github.com/brentp/somalier.git
67+
68+ # Architecture-specific fixes for arm64 (aarch64)
69+ # 1. Remove x86_64-specific -mpopcnt compiler flag
70+ # 2. Remove slivar dependency from nimble file (we've installed it separately)
71+ RUN if [ "$(uname -m)" = "aarch64" ]; then \
72+ find /apps/somalier -type f -name "*.nim" -exec sed -i '/-mpopcnt/d' {} \; && \
73+ find /apps/somalier -type f -name "nimble" -exec sed -i '/-mpopcnt/d' {} \; && \
74+ find /apps/somalier -type f -name "*.cfg" -exec sed -i '/-mpopcnt/d' {} \; && \
75+ # Remove slivar dependency from somalier.nimble because for arm64 we have already installed it.
76+ sed -i '/slivar/d' /apps/somalier/somalier.nimble || true; \
77+ fi
78+
79+ # Compile and install Somalier
80+ RUN cd somalier && \
81+ nimble install -d -y && \
82+ nim c -d:danger -d:nsb_static -d:release -d:nimDebugDlOpen -d:openmp -d:blas=openblas -d:lapack=openblas -o:/usr/bin/somalier src/somalier
83+
84+ # Final stage
85+ FROM debian:bookworm-slim
86+
87+ # Install minimal runtime dependencies
88+ RUN apt-get update && apt-get install -y --no-install-recommends \
89+ procps \
90+ libopenblas-dev \
91+ libgomp1
92+
93+ # Copy the HTSlib shared library from the build stage
94+ COPY --from=build /usr/local/lib/libhts.so* /lib/
95+ COPY --from=build /apps/htslib/libhts.so* /lib/
96+ RUN ldconfig
97+
98+ COPY --from=build /usr/bin/somalier /usr/bin/somalier
99+ COPY --from=build /apps/somalier/scripts/ancestry-labels-1kg.tsv /
100+
101+ ENV somalier_ancestry_labels=/ancestry_labels-1kg.tsv
0 commit comments