Commit 32ed7f7e authored by Silvio Rhatto's avatar Silvio Rhatto
Browse files

Merge branch 'fix/dockerfile-refactor' into 'main'

Fix: refactor Dockerfile

See merge request tpo/onion-services/onionmine!57
parents 8dcea245 3793bd84
Loading
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
@@ -34,29 +34,39 @@ WORKDIR ${BASE}
ARG MKP224O_BUILD_FLAGS="--enable-amd64-51-30k"
ARG MKP224O_BUILD_CFLAGS="-O3 -march=x86-64 -mtune=generic -fomit-frame-pointer"
ARG MKP224O_LDFLAGS="-static"
ARG VENDOR_STRATEGY="copy"

# Export as environment variables for bin/compile
ENV MKP224O_BUILD_FLAGS=${MKP224O_BUILD_FLAGS}
ENV MKP224O_BUILD_CFLAGS=${MKP224O_BUILD_CFLAGS}
ENV MKP224O_LDFLAGS=${MKP224O_LDFLAGS}

# Install build dependencies
RUN apk add --no-cache gcc libc-dev libsodium-dev libsodium-static make autoconf \
    git bash

# Copy the needed code
COPY bin       ${BASE}/bin
COPY lib       ${BASE}/lib
COPY onionmine ${BASE}/

RUN mkdir -p ${BASE}/vendor && \
# Initialize vendor folder
# Advantage: allows pinning vendors through Git submodules
COPY vendor ${BASE}/vendor

# Initialize vendors by cloning them
# Advantage: no need to initialize Git submodules before building the image
RUN if [ "${VENDOR_STRATEGY}" = "clone" ]; then \
    rm -rf ${BASE}/vendor && mkdir -p ${BASE}/vendor && \
    cd ${BASE}/vendor && \
    git clone --depth 1 --recurse-submodules https://github.com/cathugger/mkp224o.git && \
    git clone --recurse-submodules https://github.com/HARICA-official/onion-csr.git
    git clone --depth 1 --recurse-submodules https://github.com/HARICA-official/onion-csr.git; fi

# Use bin/compile for mkp224o compilation
RUN bin/compile

# Install onion-csr
RUN rm -f vendor/onion-csr/libed25519.so
RUN cd vendor/onion-csr && git submodule update --init --recursive
RUN cd vendor/onion-csr && gcc -shared -o libed25519.so -fPIC ed25519/src/*.c

FROM alpine:3.23 AS onionmine
@@ -67,21 +77,26 @@ ENV PATH=${BASE}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

WORKDIR ${BASE}

# Install the runtime dependencies
RUN apk add --no-cache ruby bash rsync wipe curl tor netcat-openbsd openssl
RUN gem install ffi

# Copy the needed code
COPY --from=builder ${BASE}/onionmine ${BASE}/
COPY --from=builder ${BASE}/bin       ${BASE}/bin
COPY --from=builder ${BASE}/lib       ${BASE}/lib
COPY                pools/example.org ${BASE}/pools/example.org

# Copy mkp224o
COPY --from=builder ${BASE}/vendor/mkp224o/mkp224o ${BASE}/vendor/mkp224o/mkp224o
RUN cd ${BASE}/bin && ln -sf ../vendor/mkp224o/mkp224o mkp224o

# Handle onion-csr requirements
RUN gem install ffi
COPY --from=builder ${BASE}/vendor/onion-csr/libed25519.so ${BASE}/vendor/onion-csr/
COPY --from=builder ${BASE}/vendor/onion-csr/onion-csr.rb  ${BASE}/vendor/onion-csr/
COPY --from=builder ${BASE}/vendor/onion-csr/ed25519.rb    ${BASE}/vendor/onion-csr/

COPY pools/example.org ${BASE}/pools/example.org
COPY onionmine         ${BASE}/

# Create a basic configuration
RUN echo 'MKP224O_RUNTIME_COMPILATION="n"' > ${BASE}/onionmine.conf

RUN cd ${BASE}/bin && ln -sf ../vendor/mkp224o/mkp224o mkp224o

ENTRYPOINT ["onionmine"]