Skip to content

Commit

Permalink
Merge pull request HemeraProtocol#186 from HemeraProtocol/pre-release…
Browse files Browse the repository at this point in the history
…/v0.4.0

Release/v0.4.0
  • Loading branch information
shanshuo0918 authored Oct 14, 2024
2 parents 2876d8f + c7dc068 commit 0137814
Show file tree
Hide file tree
Showing 86 changed files with 4,140 additions and 1,645 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
ETHEREUM_PUBLIC_NODE_RPC_URL: '${{ secrets.ETHEREUM_PUBLIC_NODE_RPC_URL }}'
LINEA_PUBLIC_NODE_DEBUG_RPC_URL: '${{ secrets.LINEA_PUBLIC_NODE_DEBUG_RPC_URL }}'
LINEA_PUBLIC_NODE_RPC_URL: '${{ secrets.LINEA_PUBLIC_NODE_RPC_URL }}'
MANTLE_PUBLIC_NODE_RPC_URL: '${{ secrets.MANTLE_PUBLIC_NODE_RPC_URL }}'
MANTLE_PUBLIC_NODE_DEBUG_RPC_URL: '${{ secrets.MANTLE_PUBLIC_NODE_DEBUG_RPC_URL }}'
POSTGRES_USER: hemera
POSTGRES_PASSWORD: password
POSTGRES_URL: postgresql://hemera:password@localhost:5432/hemera
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/push-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Push image to AWS ECR

on:
push:
branches:
- master
tags:
- 'v*'
workflow_dispatch:
inputs:
runPushAWS:
description: 'Run push image to aws (yes/no)'
required: true
default: 'false'
arch:
required: false
default: 'amd64'

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set arch variable
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ARCH=${{ github.event.inputs.arch }}" >> $GITHUB_ENV
else
echo "ARCH=amd64" >> $GITHUB_ENV
fi
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Configure AWS CLI profile
run: |
aws configure set aws_access_key_id ${{ secrets.PROD_AWS_ACCESS_KEY_ID }} --profile prod
aws configure set aws_secret_access_key ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }} --profile prod
- name: Build and Push to AWS ECR
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') || github.event.inputs.runPushAWS == 'yes'
env:
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
ECR_REPO: hemera-protocol
run: |
echo "Architecture: ${{ env.ARCH }}"
echo "Building and pushing to AWS ECR"
if [[ $GITHUB_REF == refs/tags/* ]]; then
# It's a tag push, use the tag as is
TAG=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
TAG=${TAG#v}
else
# Use the original naming convention
VERSION=$(grep '^version = ' pyproject.toml | sed 's/^version = //;s/"//g')
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
# It's a pull request
BUILD=$(echo ${{ github.event.pull_request.head.sha }} | cut -c 1-7)
else
# It's a push to a branch (e.g., master)
BUILD=$(git rev-parse --short=7 HEAD)
fi
TAG=$VERSION-$BUILD-${{ env.ARCH }}
fi
echo "Tag: $TAG"
# Build the Docker image using make
make image TAG=$TAG ARCH=${{ env.ARCH }}
# Login to ECR
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} --profile prod | docker login --username AWS --password-stdin $ECR_REGISTRY
# Tag the image for ECR
docker tag $ECR_REPO:$TAG $ECR_REGISTRY/$ECR_REPO:$TAG
# Push the image to ECR
docker push $ECR_REGISTRY/$ECR_REPO:$TAG
4 changes: 3 additions & 1 deletion .github/workflows/ut.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
ETHEREUM_PUBLIC_NODE_RPC_URL: '${{ secrets.ETHEREUM_PUBLIC_NODE_RPC_URL }}'
LINEA_PUBLIC_NODE_DEBUG_RPC_URL: '${{ secrets.LINEA_PUBLIC_NODE_DEBUG_RPC_URL }}'
LINEA_PUBLIC_NODE_RPC_URL: '${{ secrets.LINEA_PUBLIC_NODE_RPC_URL }}'
MANTLE_PUBLIC_NODE_RPC_URL: '${{ secrets.MANTLE_PUBLIC_NODE_RPC_URL }}'
MANTLE_PUBLIC_NODE_DEBUG_RPC_URL: '${{ secrets.MANTLE_PUBLIC_NODE_DEBUG_RPC_URL }}'
run: |
export PYTHONPATH=$(pwd)
make test indexer
make test indexer
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ resource/hemera.ini
sync_record
alembic.ini
!indexer/modules/custom/hemera_ens/abi/*.json
!indexer/modules/custom/cyber_id/abi/*.json
70 changes: 61 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
VERSION := $(shell poetry version -s)
ARCH=amd64
VERSION := $(shell grep '^version = ' pyproject.toml | sed 's/^version = //;s/"//g')
BUILD := `git rev-parse --short=7 HEAD`
SERVICES =
.PHONY: all build image test

TAG := $(VERSION)-$(BUILD)-$(ARCH)


PRE_COMMIT_INSTALLED := $(shell command -v pre-commit > /dev/null 2>&1 && echo yes || echo no)
VENV_DIR := .venv
POETRY_INSTALLED := $(shell command -v poetry > /dev/null 2>&1 && echo yes || echo no)

IMAGE_FLAGS := $(IMAGE_FLAGS) --platform linux/$(ARCH)

RED=\033[31m
GREEN=\033[32m
YELLOW=\033[33m
RESET=\033[0m

image:

docker build $(IMAGE_FLAGS) --network host -t hemera-protocol:$(VERSION)-$(BUILD) . --no-cache
echo "Built image hemera-protocol:$(VERSION)-$(BUILD)"
.PHONY: format init_db development image test

image:
@echo "Build tag: $(TAG)"
@echo "Build flags: $(IMAGE_FLAGS)"
docker buildx build $(IMAGE_FLAGS) --network host -t hemera-protocol:$(TAG) . --no-cache
@echo "Built image hemera-protocol:$(TAG)"

test:
@if [ "$(filter-out $@,$(MAKECMDGOALS))" = "" ]; then \
Expand All @@ -21,8 +33,6 @@ test:
fi


PRE_COMMIT_INSTALLED := $(shell command -v pre-commit > /dev/null 2>&1 && echo yes || echo no)

format:
ifeq ($(PRE_COMMIT_INSTALLED),yes)
@echo "$(YELLOW)Formatting code...$(RESET)"
Expand All @@ -33,4 +43,46 @@ endif

init_db:
@echo "Initializing database..."
poetry run python -m hemera.py init_db
poetry run python -m hemera.py init_db

development:
@echo "Setting up development environment..."
@bash -c 'set -euo pipefail; \
PYTHON_CMD=$$(command -v python3 || command -v python); \
if [ -z "$$PYTHON_CMD" ] || ! "$$PYTHON_CMD" --version 2>&1 | grep -q "Python 3"; then \
echo "Python 3 is not found. Please install Python 3 and try again."; \
exit 1; \
fi; \
python_version=$$($$PYTHON_CMD -c "import sys; print(\"{}.{}\".format(sys.version_info.major, sys.version_info.minor))"); \
if ! echo "$$python_version" | grep -qE "^3\.(8|9|10|11)"; then \
echo "Python version $$python_version is not supported. Please use Python 3.8, 3.9, 3.10, or 3.11."; \
exit 1; \
fi; \
echo "Using Python: $$($$PYTHON_CMD --version)"; \
if [ ! -d ".venv" ]; then \
echo "Creating virtual environment..."; \
$$PYTHON_CMD -m venv .venv || { \
echo "Failed to create virtual environment. Installing venv..."; \
sudo apt-get update && sudo apt-get install -y python3-venv && $$PYTHON_CMD -m venv .venv; \
}; \
fi; \
echo "Activating virtual environment..."; \
. .venv/bin/activate; \
if ! pip --version &> /dev/null; then \
echo "Installing pip..."; \
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; \
$$PYTHON_CMD get-pip.py; \
rm get-pip.py; \
fi; \
if ! poetry --version &> /dev/null; then \
echo "Installing Poetry..."; \
pip install poetry; \
else \
echo "Poetry is already installed."; \
fi; \
echo "Installing project dependencies..."; \
poetry install -v; \
echo "Development environment setup complete."; \
echo ""; \
echo "To activate the virtual environment, run:"; \
echo "source .venv/bin/activate"'
Loading

0 comments on commit 0137814

Please sign in to comment.