Skip to content

Commit

Permalink
refactor: refactored docker file to be far more lightweight, and usin…
Browse files Browse the repository at this point in the history
…g only one now
  • Loading branch information
ohager committed Jan 17, 2024
1 parent 9521d65 commit 9e29f3b
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 286 deletions.
96 changes: 96 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 2 additions & 23 deletions docker/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .`

Expand Down
44 changes: 0 additions & 44 deletions docker/mainnet/h2/Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions docker/mainnet/mariadb/Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions docker/mainnet/postgres/Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions docker/scripts/start-node.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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/
44 changes: 0 additions & 44 deletions docker/testnet/h2/Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions docker/testnet/mariadb/Dockerfile

This file was deleted.

Loading

0 comments on commit 9e29f3b

Please sign in to comment.