From e0982f81d0863288ec3d09ed6de637de86ff7839 Mon Sep 17 00:00:00 2001 From: GitGab19 Date: Tue, 22 Oct 2024 11:33:04 +0200 Subject: [PATCH] docker images optimization + docker-compose adjustment --- docker-compose-config-a.yaml | 36 ++++++++--------- docker-compose-config-c.yaml | 30 +++++++------- log-server/Dockerfile | 29 ++++++++------ pools-latency-calculator.dockerfile | 9 ----- pools-latency-calculator/Dockerfile | 33 +++++++++++++--- .../monitor_and_apply_latency.sh | 2 +- sv1-custom-proxy/Dockerfile | 30 ++++++++++---- sv1-public-pool.dockerfile | 4 +- sv2-custom-proxy/Dockerfile | 30 ++++++++++---- sv2-roles.dockerfile | 39 ++++++++++++++----- template-provider.dockerfile | 5 ++- 11 files changed, 160 insertions(+), 87 deletions(-) delete mode 100644 pools-latency-calculator.dockerfile diff --git a/docker-compose-config-a.yaml b/docker-compose-config-a.yaml index afec3a0..c5f0504 100644 --- a/docker-compose-config-a.yaml +++ b/docker-compose-config-a.yaml @@ -148,7 +148,7 @@ services: image: sv2-roles-builder-image labels: logging: "config-a" - command: ["/bin/bash", "-c", "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.6 2 & exec ./target/release/pool_sv2 -c pool/config-examples/pool-config-a-docker-example.toml"] + command: ["/bin/sh", "-c", "./monitor_and_apply_latency.sh 10.5.0.6 2 & exec ./pool_sv2 -c pool/config-examples/pool-config-a-docker-example.toml"] ports: - "34254:34254" container_name: sv2-pool @@ -159,7 +159,7 @@ services: sv2-roles-builder: condition: service_started volumes: - - ./custom-configs/sri-roles/config-a:/usr/src/stratum/roles/pool/config-examples/ + - ./custom-configs/sri-roles/config-a:/usr/local/bin/pool/config-examples/ restart: unless-stopped networks: sv2-net: @@ -173,9 +173,9 @@ services: logging: "config-a" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.6 2 & exec ./target/release/jd_server -c jd-server/config-examples/jds-config-a-docker-example.toml", + "./monitor_and_apply_latency.sh 10.5.0.6 2 & exec ./jd_server -c jd-server/config-examples/jds-config-a-docker-example.toml", ] ports: - "34264:34264" @@ -187,7 +187,7 @@ services: sv2-roles-builder: condition: service_started volumes: - - ./custom-configs/sri-roles/config-a:/usr/src/stratum/roles/jd-server/config-examples/ + - ./custom-configs/sri-roles/config-a:/usr/local/bin/jd-server/config-examples/ restart: unless-stopped networks: sv2-net: @@ -201,15 +201,15 @@ services: logging: "config-a" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.4 2 10.5.0.5 & exec ./target/release/jd_client -c jd-client/config-examples/jdc-config-a-docker-example.toml", + "./monitor_and_apply_latency.sh 10.5.0.4 2 10.5.0.5 & exec ./jd_client -c jd-client/config-examples/jdc-config-a-docker-example.toml", ] ports: - "34265:34265" container_name: sv2-jdc volumes: - - ./custom-configs/sri-roles/config-a:/usr/src/stratum/roles/jd-client/config-examples/ + - ./custom-configs/sri-roles/config-a:/usr/local/bin/jd-client/config-examples/ restart: unless-stopped depends_on: - jd-server @@ -227,7 +227,7 @@ services: logging: "config-a" command: [ - "./target/release/translator_sv2", + "./translator_sv2", "-c", "translator/config-examples/tproxy-config-a-docker-example.toml", ] @@ -237,7 +237,7 @@ services: depends_on: - sv2-jdc-translator-proxy volumes: - - ./custom-configs/sri-roles/config-a:/usr/src/stratum/roles/translator/config-examples/ + - ./custom-configs/sri-roles/config-a:/usr/local/bin/translator/config-examples/ restart: unless-stopped networks: sv2-net: @@ -247,7 +247,7 @@ services: image: sv2-custom-proxy-builder-image labels: logging: "config-a" - command: ["./target/release/sv2-custom-proxy"] + command: ["./sv2-custom-proxy"] ports: - "34253:34254" - "34251:34251" @@ -270,7 +270,7 @@ services: image: sv2-custom-proxy-builder-image labels: logging: "config-a" - command: ["./target/release/sv2-custom-proxy"] + command: ["./sv2-custom-proxy"] ports: - "8440:8440" - "5678:5678" @@ -298,7 +298,7 @@ services: image: sv1-custom-proxy-builder-image labels: logging: "config-a" - command: ["./target/release/sv1-custom-proxy"] + command: ["./sv1-custom-proxy"] ports: - "34255:34255" - "5676:5676" @@ -347,9 +347,9 @@ services: logging: "config-a" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.8 2 & exec ./target/release/sv1-custom-proxy", + "./monitor_and_apply_latency.sh 10.5.0.8 2 & exec ./sv1-custom-proxy", ] ports: - "3333:3333" @@ -374,7 +374,7 @@ services: image: sv1-custom-proxy-builder-image labels: logging: "config-a" - command: ["./target/release/sv1-custom-proxy"] + command: ["./sv1-custom-proxy"] ports: - "48330:48330" - "4567:4567" @@ -533,7 +533,7 @@ services: pools-latency-calculator: image: pools-latency-calculator-builder-image - command: ["./target/release/pools-latency-calculator"] + command: ["./pools-latency-calculator"] ports: - "1234:1234" container_name: pools-latency-calculator @@ -577,7 +577,7 @@ services: log-server: image: log-server-builder-image - command: ["./target/release/log-server"] + command: ["./log-server"] volumes: - /var/run/docker.sock:/var/run/docker.sock ports: diff --git a/docker-compose-config-c.yaml b/docker-compose-config-c.yaml index 95c5393..8b05782 100644 --- a/docker-compose-config-c.yaml +++ b/docker-compose-config-c.yaml @@ -52,7 +52,7 @@ services: pools-latency-calculator-builder: build: - dockerfile: pools-latency-calculator.dockerfile + dockerfile: ./pools-latency-calculator/Dockerfile container_name: pools-latency-calculator-builder image: pools-latency-calculator-builder-image command: echo "pools-latency-calculator build completed" @@ -122,7 +122,7 @@ services: logging: "config-c" command: [ - "./target/release/pool_sv2", + "./pool_sv2", "-c", "pool/config-examples/pool-config-c-docker-example.toml", ] @@ -133,7 +133,7 @@ services: - sv2-roles-builder - sv2-tp-pool-proxy volumes: - - ./custom-configs/sri-roles/config-c:/usr/src/stratum/roles/pool/config-examples/ + - ./custom-configs/sri-roles/config-c:/usr/local/bin/pool/config-examples/ restart: unless-stopped networks: sv2-net: @@ -147,9 +147,9 @@ services: logging: "config-c" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.23 2 & exec ./target/release/translator_sv2 -c translator/config-examples/tproxy-config-c-docker-example.toml", + "./monitor_and_apply_latency.sh 10.5.0.23 2 & exec ./translator_sv2 -c translator/config-examples/tproxy-config-c-docker-example.toml", ] ports: - "34256:34256" @@ -157,7 +157,7 @@ services: depends_on: - sv2-pool-translator-proxy volumes: - - ./custom-configs/sri-roles/config-c:/usr/src/stratum/roles/translator/config-examples/ + - ./custom-configs/sri-roles/config-c:/usr/local/bin/translator/config-examples/ restart: unless-stopped networks: sv2-net: @@ -171,9 +171,9 @@ services: logging: "config-c" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.4 2 -proxy-type=pool-translator & exec ./target/release/sv2-custom-proxy", + "./monitor_and_apply_latency.sh 10.5.0.4 2 -proxy-type=pool-translator & exec ./sv2-custom-proxy", ] ports: - "34253:34254" @@ -199,7 +199,7 @@ services: image: sv2-custom-proxy-builder-image labels: logging: "config-c" - command: ["./target/release/sv2-custom-proxy"] + command: ["./sv2-custom-proxy"] ports: - "8441:8441" - "5678:5678" @@ -227,7 +227,7 @@ services: image: sv1-custom-proxy-builder-image labels: logging: "config-c" - command: ["./target/release/sv1-custom-proxy"] + command: ["./sv1-custom-proxy"] ports: - "34255:34255" - "5676:5676" @@ -276,9 +276,9 @@ services: logging: "config-c" command: [ - "/bin/bash", + "/bin/sh", "-c", - "/usr/local/bin/monitor_and_apply_latency.sh 10.5.0.8 2 & exec ./target/release/sv1-custom-proxy", + "./monitor_and_apply_latency.sh 10.5.0.8 2 & exec ./sv1-custom-proxy", ] ports: - "3333:3333" @@ -303,7 +303,7 @@ services: image: sv1-custom-proxy-builder-image labels: logging: "config-c" - command: ["./target/release/sv1-custom-proxy"] + command: ["./sv1-custom-proxy"] ports: - "48330:48330" - "4567:4567" @@ -463,7 +463,7 @@ services: pools-latency-calculator: image: pools-latency-calculator-builder-image - command: ["./target/release/pools-latency-calculator"] + command: ["./pools-latency-calculator"] ports: - "1234:1234" container_name: pools-latency-calculator @@ -506,7 +506,7 @@ services: log-server: image: log-server-builder-image - command: ["./target/release/log-server"] + command: ["./log-server"] volumes: - /var/run/docker.sock:/var/run/docker.sock ports: diff --git a/log-server/Dockerfile b/log-server/Dockerfile index 58ef5c4..0add540 100644 --- a/log-server/Dockerfile +++ b/log-server/Dockerfile @@ -1,13 +1,20 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/log-server -COPY ./log-server . +# Build stage +FROM rust:1.75-alpine AS builder + +WORKDIR /usr/src/log-server +COPY . . + +# Install necessary dependencies +RUN apk add musl-dev pkgconfig libressl-dev + +# Build the project in release mode RUN cargo build --release -FROM rust:1.75 -COPY --from=builder usr/src/log-server/ usr/src/log-server/ -RUN apt-get update && apt-get install -y --no-install-recommends \ - iproute2 \ - iputils-ping \ - iptables \ - curl -WORKDIR /usr/src/log-server/ \ No newline at end of file +# Final stage +FROM alpine:latest + +# Copy only the binary from the builder image +COPY --from=builder /usr/src/log-server/target/release/log-server /usr/local/bin/log-server + +# Set the working directory +WORKDIR /usr/local/bin/ \ No newline at end of file diff --git a/pools-latency-calculator.dockerfile b/pools-latency-calculator.dockerfile deleted file mode 100644 index d24faeb..0000000 --- a/pools-latency-calculator.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/pools-latency-calculator -COPY pools-latency-calculator/ . -WORKDIR pools-latency-calculator/ -RUN cargo build --release - -FROM rust:1.75 -COPY --from=builder /usr/src/pools-latency-calculator/ /usr/src/pools-latency-calculator/ -WORKDIR /usr/src/pools-latency-calculator/ diff --git a/pools-latency-calculator/Dockerfile b/pools-latency-calculator/Dockerfile index 4416f4c..9c454f8 100644 --- a/pools-latency-calculator/Dockerfile +++ b/pools-latency-calculator/Dockerfile @@ -1,8 +1,29 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/pools-latency-calculator -COPY ./pools-latency-calculator/ . +# Build stage +FROM rust:1.75-alpine AS builder + +WORKDIR /usr/src/pools-latency-calculator + +# Install necessary dependencies for building +RUN apk add --no-cache musl-dev pkgconfig libressl-dev + +# Copy the source code into the container +COPY pools-latency-calculator/ . + +# Build the project in release mode RUN cargo build --release -FROM rust:1.75 -COPY --from=builder /usr/src/pools-latency-calculator/ /usr/src/pools-latency-calculator/ -WORKDIR /usr/src/pools-latency-calculator/ \ No newline at end of file +# Final stage +FROM alpine:latest + +# Install necessary runtime dependencies +RUN apk update && apk add --no-cache \ + iproute2 \ + iputils-ping \ + iptables \ + curl + +# Copy the compiled binary from the builder stage +COPY --from=builder /usr/src/pools-latency-calculator/target/release/pools-latency-calculator /usr/local/bin/pools-latency-calculator + +# Set the working directory +WORKDIR /usr/local/bin/ diff --git a/pools-latency-calculator/monitor_and_apply_latency.sh b/pools-latency-calculator/monitor_and_apply_latency.sh index cc61cd5..216d5cf 100755 --- a/pools-latency-calculator/monitor_and_apply_latency.sh +++ b/pools-latency-calculator/monitor_and_apply_latency.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh if [ -z "$1" ] || [ -z "$2" ]; then echo "Usage: $0 [TARGET_IP2] [-proxy-type=pool-translator]" diff --git a/sv1-custom-proxy/Dockerfile b/sv1-custom-proxy/Dockerfile index 93793ba..c70f922 100644 --- a/sv1-custom-proxy/Dockerfile +++ b/sv1-custom-proxy/Dockerfile @@ -1,15 +1,31 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/sv1-custom-proxy +# Build stage +FROM rust:1.75-alpine AS builder + +WORKDIR /usr/src/sv1-custom-proxy COPY ./sv1-custom-proxy . + +# Install necessary dependencies for building +RUN apk add musl-dev pkgconfig libressl-dev + +# Build the project in release mode RUN cargo build --release -FROM rust:1.75 -COPY --from=builder usr/src/sv1-custom-proxy/ usr/src/sv1-custom-proxy/ -RUN apt-get update && apt-get install -y --no-install-recommends \ +# Final stage +FROM alpine:latest + +# Install necessary runtime dependencies +RUN apk update && apk add --no-cache \ iproute2 \ iputils-ping \ iptables \ - curl -WORKDIR /usr/src/sv1-custom-proxy/ + curl + +# Copy the binary from the builder stage +COPY --from=builder /usr/src/sv1-custom-proxy/target/release/sv1-custom-proxy /usr/local/bin/sv1-custom-proxy + +# Set the working directory +WORKDIR /usr/local/bin/ + +# Copy the script and make it executable COPY ./pools-latency-calculator/monitor_and_apply_latency.sh /usr/local/bin/monitor_and_apply_latency.sh RUN chmod +x /usr/local/bin/monitor_and_apply_latency.sh \ No newline at end of file diff --git a/sv1-public-pool.dockerfile b/sv1-public-pool.dockerfile index 32351dd..3b6f125 100644 --- a/sv1-public-pool.dockerfile +++ b/sv1-public-pool.dockerfile @@ -1,7 +1,6 @@ ############################ # Docker build environment # ############################ - FROM node:18.16.1-bookworm-slim AS build # Upgrade all packages and install dependencies @@ -18,6 +17,7 @@ RUN apt-get update && \ curl \ && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# Clone the repository RUN git clone https://github.com/benjamin-wilson/public-pool.git WORKDIR /public-pool @@ -28,7 +28,6 @@ RUN npm i && npm run build ############################ # Docker final environment # ############################ - FROM node:18.16.1-bookworm-slim # Install necessary packages in the final image @@ -42,6 +41,7 @@ RUN apt-get update && \ # Expose ports for Stratum and Bitcoin RPC EXPOSE 3333 3334 8332 48332 +# Set the working directory WORKDIR /public-pool # Copy built binaries into the final image diff --git a/sv2-custom-proxy/Dockerfile b/sv2-custom-proxy/Dockerfile index b9ee138..6b78c20 100644 --- a/sv2-custom-proxy/Dockerfile +++ b/sv2-custom-proxy/Dockerfile @@ -1,15 +1,31 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/sv2-custom-proxy +# Build stage +FROM rust:1.75-alpine AS builder + +WORKDIR /usr/src/sv2-custom-proxy COPY ./sv2-custom-proxy . + +# Install necessary dependencies for building +RUN apk add musl-dev pkgconfig libressl-dev + +# Build the project in release mode RUN cargo build --release -FROM rust:1.75 -COPY --from=builder usr/src/sv2-custom-proxy/ usr/src/sv2-custom-proxy/ -RUN apt-get update && apt-get install -y --no-install-recommends \ +# Final stage +FROM alpine:latest + +# Install necessary runtime dependencies +RUN apk update && apk add --no-cache \ iproute2 \ iputils-ping \ iptables \ - curl -WORKDIR /usr/src/sv2-custom-proxy/ + curl + +# Copy the binary from the builder stage +COPY --from=builder /usr/src/sv2-custom-proxy/target/release/sv2-custom-proxy /usr/local/bin/sv2-custom-proxy + +# Set the working directory +WORKDIR /usr/local/bin/ + +# Copy the script and make it executable COPY ./pools-latency-calculator/monitor_and_apply_latency.sh /usr/local/bin/monitor_and_apply_latency.sh RUN chmod +x /usr/local/bin/monitor_and_apply_latency.sh \ No newline at end of file diff --git a/sv2-roles.dockerfile b/sv2-roles.dockerfile index 7912bca..aa92089 100644 --- a/sv2-roles.dockerfile +++ b/sv2-roles.dockerfile @@ -1,18 +1,37 @@ -FROM rust:1.75 as builder -WORKDIR usr/src/stratum/ +# Build stage +FROM rust:1.75-alpine AS builder + +WORKDIR /usr/src/stratum/ + +# Install git and necessary build dependencies +RUN apk add --no-cache git musl-dev pkgconfig libressl-dev + +# Clone the repository and checkout the main branch RUN git clone https://github.com/stratum-mining/stratum.git . -RUN git checkout main + +# Build the project in release mode WORKDIR /usr/src/stratum/roles/ RUN cargo build --release -FROM rust:1.75 -COPY --from=builder /usr/src/stratum/roles/ /usr/src/stratum/roles -RUN apt-get update && apt-get install -y --no-install-recommends \ +# Final stage +FROM alpine:latest + +# Install necessary runtime dependencies +RUN apk update && apk add --no-cache \ iproute2 \ iputils-ping \ iptables \ - curl - -WORKDIR /usr/src/stratum/roles + curl + +# Copy only the compiled binaries from the builder stage +COPY --from=builder /usr/src/stratum/roles/target/release/pool_sv2 /usr/local/bin/pool_sv2 +COPY --from=builder /usr/src/stratum/roles/target/release/jd_server /usr/local/bin/jd_server +COPY --from=builder /usr/src/stratum/roles/target/release/jd_client /usr/local/bin/jd_client +COPY --from=builder /usr/src/stratum/roles/target/release/translator_sv2 /usr/local/bin/translator_sv2 + +# Set the working directory +WORKDIR /usr/local/bin/ + +# Copy the script and make it executable COPY ./pools-latency-calculator/monitor_and_apply_latency.sh /usr/local/bin/monitor_and_apply_latency.sh -RUN chmod +x /usr/local/bin/monitor_and_apply_latency.sh +RUN chmod +x /usr/local/bin/monitor_and_apply_latency.sh \ No newline at end of file diff --git a/template-provider.dockerfile b/template-provider.dockerfile index 6235abc..f89c2e3 100644 --- a/template-provider.dockerfile +++ b/template-provider.dockerfile @@ -27,4 +27,7 @@ RUN ARCH=$(dpkg --print-architecture) && \ RUN tar -xzvf /tmp/bitcoin.tar.gz -C $BITCOIN_DIR --strip-components=1 # Cleanup -RUN rm /tmp/bitcoin.tar.gz \ No newline at end of file +RUN rm /tmp/bitcoin.tar.gz + +# Create a volume for blockchain data and configuration files +VOLUME ["/root/.bitcoin"] \ No newline at end of file