FROM rockylinux:9 COPY ./scripts/init.sh /usr/local/bin/init.sh RUN chmod +x /usr/local/bin/init.sh #RUN yum install -y curl tar gzip && yum clean all ARG ZERO_GRAVITY_VERSION ARG ZERO_GRAVITY_CHAIN_SPEC # 0G publishes each network from a DIFFERENT repository, and the release-tag format is not # consistent within either of them. The asset filename is always "-v.tar.gz"; # only the tag varies: # # aristotle -> 0gchain-Aristotle 1.0.4 = "1.0.4" 1.0.6 = "v1.0.6" # galileo -> 0gchain-NG 3.0.3 = "v3.0.3" 3.0.7 = "galileo-v3.0.7" 3.0.8 = "v3.0.8" # # So the tag cannot be hardcoded. Resolve it by trying the known forms in order and taking # the first that actually yields the asset. # # curl uses -f (fail on HTTP error). Without it a 404 HTML body is written into the .tar.gz # and the build dies several layers later at "tar: not in gzip format" -- an error that # points nowhere near the real cause. That has cost three separate misdiagnoses. RUN set -eu; \ ASSET="${ZERO_GRAVITY_CHAIN_SPEC}-v${ZERO_GRAVITY_VERSION}.tar.gz"; \ if [ "${ZERO_GRAVITY_CHAIN_SPEC}" = "aristotle" ]; then \ REPO="0gfoundation/0gchain-Aristotle"; \ TAGS="${ZERO_GRAVITY_VERSION} v${ZERO_GRAVITY_VERSION} ${ZERO_GRAVITY_CHAIN_SPEC}-v${ZERO_GRAVITY_VERSION}"; \ else \ REPO="0gfoundation/0gchain-NG"; \ TAGS="v${ZERO_GRAVITY_VERSION} ${ZERO_GRAVITY_CHAIN_SPEC}-v${ZERO_GRAVITY_VERSION} ${ZERO_GRAVITY_VERSION}"; \ fi; \ for TAG in ${TAGS}; do \ URL="https://github.com/${REPO}/releases/download/${TAG}/${ASSET}"; \ echo "0g: trying tag '${TAG}' -> ${URL}"; \ if curl -fsSL "${URL}" -o "/tmp/${ASSET}"; then \ echo "0g: resolved ${ZERO_GRAVITY_CHAIN_SPEC} ${ZERO_GRAVITY_VERSION} from tag '${TAG}'"; \ break; \ fi; \ rm -f "/tmp/${ASSET}"; \ done; \ if [ ! -s "/tmp/${ASSET}" ]; then \ echo "0g: FATAL - no release asset '${ASSET}' found in ${REPO} under any of: ${TAGS}" >&2; \ echo "0g: aristotle and galileo are SEPARATE repos on SEPARATE version lines" >&2; \ echo "0g: aristotle = 0gchain-Aristotle (1.0.x), galileo = 0gchain-NG (3.0.x)" >&2; \ echo "0g: check that version '${ZERO_GRAVITY_VERSION}' exists for '${ZERO_GRAVITY_CHAIN_SPEC}'" >&2; \ exit 1; \ fi # Extract by DETECTING the layout rather than assuming one per chain. 0G has shipped # three shapes so far and changed between them without notice: # # galileo <= 3.0.3 /{rpc,validator,archive,seed}/bin/ + configs (168 MB) # -> binaries duplicated inside every profile dir # galileo >= 3.0.8 /bin/ shared, + /{rpc,...}/ configs (69 MB) # -> binaries DEDUPLICATED to the tarball root; rpc/ is configs-only # aristotle 1.0.x /bin/ + configs, no profile dirs at all # # So "does /rpc exist" is NOT sufficient: 3.0.8 still has rpc/, it just no longer # holds bin/. Take configs from the profile dir when present, then top the binaries up # from the shared root bin/ if the profile dir didn't supply them. # # The old code hardcoded "galileo -> mv /rpc /0g", so 3.0.8 yielded configs but no # binaries and the build died two layers later at # `chmod: cannot access '/0g/bin/0gchaind'` — an error naming neither the chain, the # version, nor the layout. Assert on the binaries here so the NEXT upstream reshuffle # reports itself at the point of failure instead. RUN set -eu; \ SRC="/tmp/${ZERO_GRAVITY_CHAIN_SPEC}-v${ZERO_GRAVITY_VERSION}"; \ tar -xzf "${SRC}.tar.gz" -C /tmp; \ mkdir -p /0g; \ if [ -d "${SRC}/rpc" ]; then \ echo "0g: profile dir found -> ${SRC}/rpc"; \ cp -a "${SRC}/rpc/." /0g/; \ else \ echo "0g: no profile dir -> using tarball root ${SRC}"; \ cp -a "${SRC}/." /0g/; \ fi; \ if [ ! -f /0g/bin/0gchaind ] && [ -d "${SRC}/bin" ]; then \ echo "0g: binaries not in the profile dir -> topping up from ${SRC}/bin"; \ cp -a "${SRC}/bin" /0g/; \ fi; \ rm -rf "${SRC}"; \ missing=""; \ for b in 0gchaind geth; do \ [ -f "/0g/bin/${b}" ] || missing="${missing} bin/${b}"; \ done; \ if [ -n "${missing}" ]; then \ echo "0g: FATAL - missing after extraction:${missing}" >&2; \ echo "0g: ${ZERO_GRAVITY_CHAIN_SPEC} v${ZERO_GRAVITY_VERSION} tarball layout not recognised." >&2; \ echo "0g: known layouts are '/rpc/bin/' (per-profile) and '/bin/' (flat)." >&2; \ echo "0g: contents of /0g were:" >&2; \ ls -la /0g >&2 || true; \ exit 1; \ fi; \ chmod +x /0g/bin/0gchaind /0g/bin/geth ENTRYPOINT [ "init.sh" ]