commit b4a4842338544a1c239eabd8c28a7a0f15037f9d Author: Sofiane Gerhardt Date: Mon Oct 21 10:50:05 2024 +0200 First commit diff --git a/.gitea/workflows/docker-build.yaml b/.gitea/workflows/docker-build.yaml new file mode 100644 index 0000000..41416ed --- /dev/null +++ b/.gitea/workflows/docker-build.yaml @@ -0,0 +1,28 @@ +name: Docker Image Build and Push + +on: + push: + branches: + - main + - 'release/*' + +jobs: + build_and_push_docker_image: + runs-on: [ "docker://docker" ] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + run: | + docker build --build-arg VERSION=${GITHUB_REF_NAME} -t registry.example.com/${GITHUB_REPOSITORY}:${GITHUB_SHA} . + docker push registry.example.com/${GITHUB_REPOSITORY}:${GITHUB_SHA} + + - name: Tag latest image + if: github.ref == 'refs/heads/main' + run: | + docker tag registry.example.com/${GITHUB_REPOSITORY}:${GITHUB_SHA} registry.example.com/${GITHUB_REPOSITORY}:latest + docker push registry.example.com/${GITHUB_REPOSITORY}:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..657d0e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +# This dockerfile generates an s390x docker image for HPC containing an Hyperledger/Besu installation. +# Build arguments: +# VERSION: Required. Used to label the image. + +ARG VERSION + +########################### Stage 0 ######################## +# Use distro from amd64 image +FROM --platform=amd64 hyperledger/besu:$VERSION as linux_stage_0 + +########################### Stage 1 ######################## +# Build the actual release docker image +FROM ibm-semeru-runtimes:open-17-jre + +ARG UID=1000 +ARG GID=1000 +ARG BESU_HOME=/opt/besu + +RUN apt-get update && \ +apt-get install --no-install-recommends -q --assume-yes libjemalloc-dev=5.* && \ +apt-get clean && \ +rm -rf /var/lib/apt/lists/* + +RUN groupadd -g $GID besu && \ + adduser --uid $UID --gid $GID --disabled-password --gecos "" --home $BESU_HOME besu && \ + chown $UID:$GID /opt/besu + +COPY --from=linux_stage_0 --chown=$UID:$GID $BESU_HOME $BESU_HOME + +# Add ECS formatter for Log4j2 +RUN curl -s -o $BESU_HOME/lib/log4j2-ecs-layout-1.3.0.jar https://repo1.maven.org/maven2/co/elastic/logging/log4j2-ecs-layout/1.3.0/log4j2-ecs-layout-1.3.0.jar && \ + curl -s -o $BESU_HOME/lib/ecs-logging-core-1.3.0.jar https://repo1.maven.org/maven2/co/elastic/logging/ecs-logging-core/1.3.0/ecs-logging-core-1.3.0.jar +RUN sed -i 's|\(^CLASSPATH=.*$\)|\1:$APP_HOME/lib/log4j2-ecs-layout-1.3.0.jar:$APP_HOME/lib/ecs-logging-core-1.3.0.jar|g' $BESU_HOME/bin/besu +COPY --chown=$UID:$GID log4j2.xml $BESU_HOME/ + +# Add entrypoint for HPC +COPY --chown=$UID:$GID entrypoint.sh /usr/local/bin/entrypoint.sh + +# Expose services ports +# 8545 HTTP JSON-RPC +# 8546 WS JSON-RPC +# 8547 HTTP GraphQL +# 8550 HTTP ENGINE JSON-RPC +# 8551 WS ENGINE JSON-RPC +# 30303 P2P +EXPOSE 8545 8546 8547 8550 8551 30303 + +# defaults for host interfaces +ENV BESU_RPC_HTTP_HOST 0.0.0.0 +ENV BESU_RPC_WS_HOST 0.0.0.0 +ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 +ENV BESU_PID_PATH "/tmp/pid" + +ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION" + +ENV PATH="$BESU_HOME/bin:${PATH}" + +USER besu +WORKDIR $BESU_HOME + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +HEALTHCHECK --start-period=5s --interval=5s --timeout=1s --retries=10 CMD bash -c "[ -f /tmp/pid ]" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2256d73 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +echo $CONFIGFILE | base64 --decode >> /config/config.toml +echo $GENESISFILE | base64 --decode >> /config/genesis.json +echo $LOGCONFIGFILE | base64 --decode >> /config/log-config.xml +echo $STATICNODESFILE | base64 --decode >> /config/static-nodes.json + +if [[ -z "${NODEKEY}" ]]; then + echo "Key is not set" +else + echo $NODEKEY | base64 --decode > /opt/besu/data/key +fi + +if [[ -z "${PERMISSIONSFILE}" ]]; then + echo "Permissions File not set" +else + echo $PERMISSIONSFILE | base64 --decode >> /config/permissions_config.toml +fi + +/opt/besu/bin/besu \ + --config-file=/config/config.toml \ + --genesis-file=/config/genesis.json \ + --nat-method="$NATMETHOD" \ + --p2p-port="$P2PPORT" \ + --p2p-host="$P2PHOST" \ + --rpc-http-port="$RPCHTTPPORT" \ + --rpc-ws-port="$RPCWSPORT" \ + --graphql-http-port="$GRAPHQLHTTPPORT" \ + --logging="$LOGGING" \ + --sync-mode="$SYNCMODE" \ + --node-private-key-file=/opt/besu/data/key; diff --git a/log4j2.xml b/log4j2.xml new file mode 100644 index 0000000..f38fda6 --- /dev/null +++ b/log4j2.xml @@ -0,0 +1,19 @@ + + + + INFO + + + + + + + + + + + + + + +