Skip to content

Commit

Permalink
chore: init images repository
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Aug 26, 2024
0 parents commit 319e80d
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 0 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: docker

on:
push:
branches:
- "master"
tags:
- "v*"

jobs:
docker:
strategy:
matrix:
chain:
# TODO: make it dynamic
- cosmoshub
- govgen
- juno
- nolus

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# TODO: first check if docker image not already exist

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Go Build Cache for Docker
uses: actions/cache@v3
with:
path: go-build-cache
key: ${{ runner.os }}-go-build-cache
restore-keys: |
${{ runner.os }}-go-build-cache
- name: inject go-build-cache into docker
uses: reproducible-containers/[email protected]
with:
cache-source: go-build-cache

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get version
id: version
uses: mikefarah/yq@master
with:
cmd: yq -r '.version' './${{ matrix.chain }}/build.yaml'

- name: Get go_version
id: go_version
uses: mikefarah/yq@master
with:
cmd: yq -r '.go_version' './${{ matrix.chain }}/build.yaml'

- name: Get chain_repository
id: chain_repository
uses: mikefarah/yq@master
with:
cmd: yq -r '.chain_repository' './${{ matrix.chain }}/build.yaml'

- name: Get daemon_name
id: daemon_name
uses: mikefarah/yq@master
with:
cmd: yq -r '.daemon_name' './${{ matrix.chain }}/build.yaml'

- name: Get daemon_home
id: daemon_home
uses: mikefarah/yq@master
with:
cmd: yq -r '.daemon_home' './${{ matrix.chain }}/build.yaml'

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.chain }}
tags: |
type=raw,value=latest
type=raw,value=${{ steps.version.outputs.result }}
# TODO: Check if the directory have a custom Dockerfile
# in that case, build a different image

- name: Build and push
uses: docker/build-push-action@v3
with:
file: "./Dockerfile"
context: ./${{ matrix.chain }}
build-args: |
CHAIN_NAME=${{ matrix.chain }}
VERSION=${{ steps.version.outputs.result }}
GO_VERSION=${{ steps.go_version.outputs.result }}
CHAIN_REPO=${{ steps.chain_repository.outputs.result }}
DAEMON_NAME=${{ steps.daemon_name.outputs.result }}
DAEMON_HOME=${{ steps.daemon_home.outputs.result }}
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
73 changes: 73 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
ARG GO_VERSION

FROM golang:${GO_VERSION} as builder

ARG CHAIN_NAME
ARG DAEMON_NAME
ARG DAEMON_HOME
ARG VERSION="master"
ARG CHAIN_REPO
ARG LIBWASM_VERSION

RUN apk add --no-cache \
git \
make \
linux-headers \
ca-certificates \
build-base \
libc6-compat

RUN git clone --depth=1 ${CHAIN_REPO} /go/chain

WORKDIR /go/chain

RUN git fetch --all --tags
RUN git checkout ${VERSION}

# Cosmwasm - Download correct libwasmvm version
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
set -eux; \
export ARCH=$(uname -m); \
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
[ -z ${WASM_VERSION} ] || wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
cp -v /lib/libwasmvm_muslc.a /lib/libwasmvm_muslc.${ARCH}.a; \
go mod download;

# Build chain binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
COMMIT_SHA="$(git log -1 --format='%H')" && \
GOWORK=off go build \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name=${CHAIN_NAME} \
-X github.com/cosmos/cosmos-sdk/version.AppName=${DAEMON_NAME} \
-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${COMMIT_SHA} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o /usr/bin/${DAEMON_NAME} \
./cmd/${DAEMON_NAME}


FROM alpine:3.18

ARG DAEMON_NAME
ENV DAEMON_NAME="${DAEMON_NAME}"

RUN apk add --no-cache bash jq supervisor curl lz4

WORKDIR /root

COPY --from=builder /usr/bin/${DAEMON_NAME} /usr/bin/

RUN /usr/bin/${DAEMON_NAME} version

RUN echo "#!/bin/sh" > /entrypoint.sh && \
echo "exec /usr/bin/${DAEMON_NAME} \$@" >> /entrypoint.sh && \
chmod +x /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]
7 changes: 7 additions & 0 deletions govgen/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "v1.0.2"
go_version: "1.22-alpine"
chain_repository: "https://github.com/atomone-hub/govgen"

daemon_name: "govgend"
daemon_home: "$HOME/.govgen"
7 changes: 7 additions & 0 deletions juno/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "v23.1.0"
go_version: "1.22-alpine"
chain_repository: "https://github.com/CosmosContracts/juno"

daemon_name: "junod"
daemon_home: "$HOME/.juno"
7 changes: 7 additions & 0 deletions nolus/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "v0.6.2"
go_version: "1.22-alpine"
chain_repository: "https://github.com/nolus-protocol/nolus-core"

daemon_name: "nolusd"
daemon_home: "$HOME/.nolus"
65 changes: 65 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env sh

set -ex

LOG_FORMAT=${LOG_FORMAT:-"json"}
LOG_LEVEL=${LOG_LEVEL:-"info"}

MONIKER=${MONIKER:-"node"}

MINIMUM_GAS_PRICES=${MINIMUM_GAS_PRICES:-""}

PRUNING=${PRUNING:-"default"}
PRUNING_KEEP_RECENT=${PRUNING_KEEP_RECENT:-"0"}
PRUNING_KEEP_EVERY=${PRUNING_KEEP_EVERY:-"0"}
PRUNING_INTERVAL=${PRUNING_INTERVAL:-"0"}

STATESYNC_SNAPSHOT_INTERVAL=${STATESYNC_SNAPSHOT_INTERVAL:-"0"}
STATESYNC_SNAPSHOT_KEEP_RECENT=${STATESYNC_SNAPSHOT_KEEP_RECENT:-"0"}

INDEXER=${INDEXER:-"kv"}

P2P_SEEDS=${P2P_SEEDS:-""}
P2P_PEERS=${P2P_PEERS:-""}
P2P_EXTERNAL_ADDR=${P2P_EXTERNAL_ADDR:-""}

P2P_LADDR=${P2P_LADDR:-"tcp://0.0.0.0:26656"}
RPC_LADDR=${RPC_LADDR:-"tcp://0.0.0.0:26657"}
GRPC_LADDR=${GRPC_LADDR:-""}

PROMETHEUS_ENABLED=${PROMETHEUS_ENABLED:-"false"}
PROMETHEUS_LISTEN_ADDR=${PROMETHEUS_LISTEN_ADDR:-":26660"}

sed -i "s#moniker = .*#moniker = \"${MONIKER}\"#g" $DAEMON_HOME/config/config.toml

sed -i "s#^minimum-gas-prices = .*#minimum-gas-prices = \"${MINIMUM_GAS_PRICES}\"#g" $DAEMON_HOME/config/app.toml

sed -i "s#indexer = .*#indexer = \"$INDEXER\"#g" $DAEMON_HOME/config/config.toml
# MUST be grpc.address in app.toml
#sed -i "s#grpc_laddr =.*#grpc_laddr = \"$GRPC_LADDR\"#g" $DAEMON_HOME/config/config.toml

sed -i "s#^pruning = .*#pruning = \"${PRUNING}\"#g" $DAEMON_HOME/config/app.toml
sed -i "s#^pruning-keep-recent = .*#pruning-keep-recent = \"${PRUNING_KEEP_RECENT}\"#g" $DAEMON_HOME/config/app.toml
sed -i "s#^pruning-keep-every = .*#pruning-keep-every = \"${PRUNING_KEEP_EVERY}\"#g" $DAEMON_HOME/config/app.toml
sed -i "s#^pruning-interval = .*#pruning-interval = \"${PRUNING_INTERVAL}\"#g" $DAEMON_HOME/config/app.toml

sed -i "s#^snapshot-interval =.*#snapshot-interval = ${STATESYNC_SNAPSHOT_INTERVAL}#" $DAEMON_HOME/config/app.toml
sed -i "s#^snapshot-keep-recent =.*#snapshot-keep-recent = ${STATESYNC_SNAPSHOT_KEEP_RECENT}#" $DAEMON_HOME/config/app.toml

sed -i "s#^seeds = .*#seeds = \"${P2P_SEEDS}\"#g" $DAEMON_HOME/config/config.toml
sed -i "s#^persistent_peers = .*#persistent_peers = \"${P2P_PEERS}\"#g" $DAEMON_HOME/config/config.toml

sed -i "s#external_address =.*#external_address = \"$P2P_EXTERNAL_ADDR\"#g" $DAEMON_HOME/config/config.toml

sed -i "s#^prometheus = .*#prometheus = ${PROMETHEUS_ENABLED}#g" $DAEMON_HOME/config/config.toml
sed -i "s#^prometheus_listen_addr = .*#prometheus_listen_addr = \"${PROMETHEUS_LISTEN_ADDR}\"#g" $DAEMON_HOME/config/config.toml

for file in /entrypoint.d/*.sh; do
bash "$file" || true
done

exec /usr/bin/${DAEMON_NAME} start \
--home=${DAEMON_HOME} \
--rpc.laddr="${RPC_LADDR}" \
--p2p.laddr="${P2P_LADDR}" \
--log_level=$LOG_LEVEL
37 changes: 37 additions & 0 deletions scripts/init.snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env sh

FORCE=${FORCE:-"false"}

CHAIN_TYPE=${CHAIN_TYPE:-"mainnet"}

POLKACHU_SECRET=${POLKACHU_SECRET:-""}
SNAPSHOT_PROVIDER=${SNAPSHOT_PROVIDER:-"polkachu"}


if [ "${FORCE}" = "true" ]; then
cp -v ${DAEMON_HOME}/data/priv_validator_state.json ${DAEMON_HOME}
${DAEMON_NAME} tendermint unsafe-reset-all --keep-addr-book
fi

if [ -f "${DAEMON_HOME}/data/priv_validator_state.json" ]; then
echo "Data already provided, please start with FORCE=true to reset"
exit 1
fi

case "${SNAPSHOT_PROVIDER}" in
"polkachu")
echo "Getting snapshots from polkachu.com"
SNAP_INFO=$(curl -s -H "x-polkachu: ${POLKACHU_SECRET}" https://polkachu.com/api/v2/chain_snapshots/${CHAIN_NAME}/${CHAIN_TYPE} | jq)
curl -o - -L $(echo $SNAP_INFO | jq -r ".snapshot.url") | lz4 -c -d - | tar -x -C $DAEMON_HOME
;;
"nodestake.top")
SNAP_NAME=$(curl -s https://ss.teritori.nodestake.top/ | egrep -o ">20.*\.tar.lz4" | tr -d ">")
curl -o - -L https://ss.teritori.nodestake.top/${SNAP_NAME} | lz4 -c -d - | tar -x -C $DAEMON_HOME
;;
"nysa.network")
echo "TODO"
;;
"*")
curl -o - -L ${URL} | lz4 -c -d - | tar -x -C $DAEMON_HOME
;;
esac

0 comments on commit 319e80d

Please sign in to comment.