From 9e29f3be143c80e440016a466249d3661eb0e528 Mon Sep 17 00:00:00 2001 From: ohager Date: Wed, 17 Jan 2024 14:30:49 -0300 Subject: [PATCH] refactor: refactored docker file to be far more lightweight, and using only one now --- Dockerfile | 96 ++++++++++++++++++++++++++++++ build.gradle | 1 + docker/DOCKER.md | 25 +------- docker/mainnet/h2/Dockerfile | 44 -------------- docker/mainnet/mariadb/Dockerfile | 43 ------------- docker/mainnet/postgres/Dockerfile | 43 ------------- docker/scripts/start-node.sh | 4 +- docker/testnet/h2/Dockerfile | 44 -------------- docker/testnet/mariadb/Dockerfile | 43 ------------- docker/testnet/postgres/Dockerfile | 43 ------------- update-classic.sh | 2 +- 11 files changed, 102 insertions(+), 286 deletions(-) create mode 100644 Dockerfile delete mode 100644 docker/mainnet/h2/Dockerfile delete mode 100644 docker/mainnet/mariadb/Dockerfile delete mode 100644 docker/mainnet/postgres/Dockerfile delete mode 100644 docker/testnet/h2/Dockerfile delete mode 100644 docker/testnet/mariadb/Dockerfile delete mode 100644 docker/testnet/postgres/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..2bf56eba2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,96 @@ +# Build the node software +#FROM gradle:7.3.3-jdk11 as builder +FROM amazoncorretto:11-alpine-jdk as builder +RUN apk update && apk upgrade \ + && apk add --no-cache --update coreutils bind-tools git unzip wget curl nodejs npm \ + && rm -rf /var/cache/apk/* + +WORKDIR /signum-node + +COPY . . + +RUN node -v +RUN npm -v + +# Build Signum Node Jar +RUN chmod +x /signum-node/gradlew \ + && /signum-node/gradlew clean dist jdeps \ + --no-daemon \ + -Pjdeps.recursive=true \ + -Pjdeps.ignore.missing.deps=true \ + -Pjdeps.print.module.deps=true + +# Unpack the build to /signum +RUN unzip -o build/distributions/signum-node.zip -d /signum + +# provide needed update scripts +RUN chmod +x update-phoenix.sh +RUN chmod +x update-classic.sh +COPY update-phoenix.sh /signum/update-phoenix.sh +COPY update-classic.sh /signum/update-classic.sh + +WORKDIR /signum + +# Clean up /signum +RUN rm -rf /signum/signum-node.exe 2> /dev/null || true \ + && rm -rf /signum/signum-node.zip 2> /dev/null || true + +## Create a custom JRE +RUN $JAVA_HOME/bin/jlink \ + --add-modules $(cat /signum-node/build/reports/jdeps/print-module-deps-main.txt) \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=2 \ + --output /jre + +RUN mkdir -p /requirements \ + && ldd /jre/bin/java | awk 'NF == 4 { system("cp --parents " $3 " /requirements") }' + +# Prepare final image +FROM alpine:3.18 +LABEL name="Signum Node" +LABEL description="This is the official Signum Node image" +LABEL credits="gittrekt,damccull,ohager" +ENV JAVA_HOME=/jre +ENV PATH="${JAVA_HOME}/bin:${PATH}" + +# minimum required env needed for wallet update scripts on container restarts -> see start-node.sh +RUN apk update && apk upgrade \ + && apk add --no-cache --update coreutils bind-tools git unzip wget curl bash \ + && rm -rf /var/cache/apk/* + +COPY --from=builder /jre $JAVA_HOME +COPY --from=builder /signum /signum +COPY --from=builder /requirements/ / + +WORKDIR /signum + +VOLUME ["/conf", "/db"] +RUN ln -s /conf /signum/conf +RUN ln -s /db /signum/db + +# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script +# use one of [h2,mariadb,postgres] +ARG DATABASE=h2 + +# Injectable ports defaulting to mainnet +ARG PORT_P2P=8123 +ARG PORT_HTTP=8125 +ARG PORT_WS=8126 + +RUN mkdir ./bootstrap +COPY conf/logging-default.properties ./bootstrap/logging-default.properties +COPY conf/node-default.properties ./bootstrap/node-default.properties +COPY conf/node.properties.${DATABASE} ./bootstrap/node.properties + +COPY docker/scripts/start-node.sh ./start-node.sh +RUN chmod +x start-node.sh + +# Clean up +RUN rm signum-node.exe 2> /dev/null || true +RUN rm signum-node.zip 2> /dev/null || true + +EXPOSE $PORT_WS $PORT_HTTP $PORT_P2P + +ENTRYPOINT [ "./start-node.sh" ] diff --git a/build.gradle b/build.gradle index e248c0ee3..92524437b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ plugins { id "de.undercouch.download" version "5.5.0" id 'jacoco' id "com.github.node-gradle.node" version "7.0.1" + id 'org.kordamp.gradle.jdeps' version '0.20.0' } java { diff --git a/docker/DOCKER.md b/docker/DOCKER.md index 3b4d385f7..58370da31 100644 --- a/docker/DOCKER.md +++ b/docker/DOCKER.md @@ -209,31 +209,10 @@ Within the `conf` folder you'll see three file created: # Building Image Manually -The _official_ Dockerfiles are all within the folder `./docker` and structured like this: - -``` -├── DOCKER.md -├── mainnet -│   ├── h2 -│   │   └── Dockerfile -│   ├── mariadb -│   │   └── Dockerfile -│   └── postgres -│   └── Dockerfile -├── scripts -│   └── start-node.sh -└── testnet - ├── h2 - │   └── Dockerfile - ├── mariadb - │   └── Dockerfile - └── postgres - └── Dockerfile -``` > requires to have cloned this repository using `git clone --depth 1 https://github.com/signum-network/signum-node.git` -The structure should be self-explanatory. To build your own image, e.g. with some modified Dockerfile maybe, -just copy the desired build from the related folder to the projects root directory and then run +The _official_ Dockerfile is in the root folder. +To build your own image, e.g. with some modified Dockerfile maybe, `docker build -t signumnode:custom-h2 .` diff --git a/docker/mainnet/h2/Dockerfile b/docker/mainnet/h2/Dockerfile deleted file mode 100644 index 827abe067..000000000 --- a/docker/mainnet/h2/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node H2 [Mainnet]" -LABEL description="This is the official Signum Node using H2 (Version 2) database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf", "/db"] -RUN ln -s /conf /signum/conf -RUN ln -s /db /signum/db - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.mariadb /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 8126 8125 8123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/docker/mainnet/mariadb/Dockerfile b/docker/mainnet/mariadb/Dockerfile deleted file mode 100644 index cc9e646d6..000000000 --- a/docker/mainnet/mariadb/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node MariaDB [Mainnet]" -LABEL description="This is the official Signum Node using MariaDB database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf"] -RUN ln -s /conf /signum/conf - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.mariadb /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 8126 8125 8123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/docker/mainnet/postgres/Dockerfile b/docker/mainnet/postgres/Dockerfile deleted file mode 100644 index 778504e27..000000000 --- a/docker/mainnet/postgres/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node Postgres [Mainnet]" -LABEL description="This is the official Signum Node using MariaDB database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf"] -RUN ln -s /conf /signum/conf - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.postgres /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 8126 8125 8123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/docker/scripts/start-node.sh b/docker/scripts/start-node.sh index 7fe2efdf6..d322742d0 100755 --- a/docker/scripts/start-node.sh +++ b/docker/scripts/start-node.sh @@ -1,7 +1,7 @@ #!/bin/bash # This script will be executed inside the docker container -# The paths are all relative to docker /signum folder +# The paths are all relative to docker root folder '/signum' set -e @@ -31,4 +31,4 @@ fi ./update-classic.sh echo "🚀Starting Signum Node" -exec java -XX:MaxRAMPercentage=90.0 -jar signum-node.jar --headless +exec java -XX:MaxRAMPercentage=90.0 -jar signum-node.jar --headless -c /conf/ diff --git a/docker/testnet/h2/Dockerfile b/docker/testnet/h2/Dockerfile deleted file mode 100644 index 2aa0ee0dd..000000000 --- a/docker/testnet/h2/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node H2 [Testnet]" -LABEL description="This is the official Signum Node using H2 (Version 2) database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf", "/db"] -RUN ln -s /conf /signum/conf -RUN ln -s /db /signum/db - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.mariadb /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 6877 6876 7123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/docker/testnet/mariadb/Dockerfile b/docker/testnet/mariadb/Dockerfile deleted file mode 100644 index 0178d5298..000000000 --- a/docker/testnet/mariadb/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node MariaDB [Testnet]" -LABEL description="This is the official Signum Node using MariaDB database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf"] -RUN ln -s /conf /signum/conf - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.mariadb /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 6877 6876 7123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/docker/testnet/postgres/Dockerfile b/docker/testnet/postgres/Dockerfile deleted file mode 100644 index 8083f7047..000000000 --- a/docker/testnet/postgres/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -# Build the node software -FROM gradle:7.3.3-jdk11 as builder -WORKDIR /signum -COPY . . -RUN gradle dist --no-daemon - - -# Prepare final image -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y bash curl wget unzip git -LABEL name="Signum Node Postgres [Testnet]" -LABEL description="This is the official Signum Node using MariaDB database" -WORKDIR /signum -COPY --from=builder /signum/build/distributions . -RUN unzip -o signum-node.zip -RUN rm -rf conf - -VOLUME ["/conf"] -RUN ln -s /conf /signum/conf - -# We use the bootstrap folder to copy the config files to the host machine in the start-node.sh script -COPY conf/logging-default.properties /signum/bootstrap/logging-default.properties -COPY conf/node-default.properties /signum/bootstrap/node-default.properties -COPY conf/node.properties.postgres /signum/bootstrap/node.properties - -# Update phoenix and classic wallets -COPY update-phoenix.sh /signum/update-phoenix.sh -COPY update-classic.sh /signum/update-classic.sh -RUN chmod +x update-phoenix.sh -RUN chmod +x update-classic.sh -RUN bash -c /signum/update-phoenix.sh -RUN bash -c /signum/update-classic.sh - -COPY docker/scripts/start-node.sh /signum/start-node.sh -RUN chmod +x start-node.sh - -# Clean up -RUN rm signum-node.exe 2> /dev/null || true -RUN rm signum-node.zip 2> /dev/null || true -RUN rm -rf tmp 2> /dev/null || true - -EXPOSE 6877 6876 7123 -ENTRYPOINT [ "./start-node.sh" ] diff --git a/update-classic.sh b/update-classic.sh index 2091446b3..ebb57bb76 100755 --- a/update-classic.sh +++ b/update-classic.sh @@ -14,7 +14,7 @@ echo "⬇️ Downloading latest release..." git clone --depth 1 https://github.com/signum-network/signum-classic-wallet.git echo "📝 Updating code base..." -cp -r signum-classic-wallet/src/* /signum/html/ui/classic/ +cp -r signum-classic-wallet/src/* ./html/ui/classic/ echo "🛀 Cleaning up..." rm -rf signum-classic-wallet