First commit

This commit is contained in:
Sofiane Gerhardt 2024-10-21 10:50:05 +02:00
commit b4a4842338
4 changed files with 140 additions and 0 deletions

View file

@ -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

62
Dockerfile Normal file
View file

@ -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 ]"

31
entrypoint.sh Normal file
View file

@ -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;

19
log4j2.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="root.log.level">INFO</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<EcsLayout serviceName="${env:HOSTNAME}" serviceNodeName="${env:SERVER_NAME}">
<KeyValuePair key="env" value="${env:BESU_ENV}"/>
</EcsLayout>
</Console>
</Appenders>
<Loggers>
<Root level="${sys:root.log.level}">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>