diff --git a/.github/workflows/build-release-artifacts.yml b/.github/workflows/build-release-artifacts.yml deleted file mode 100644 index 4b25b110..00000000 --- a/.github/workflows/build-release-artifacts.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Build Release Binaries - -on: - release: - types: - - created - - edited - # pull_request: - # branches: - # - main - -permissions: - id-token: write - contents: write - pull-requests: write - actions: write - -jobs: - Timestamp: - uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main - - build: - needs: Timestamp - name: Build Release Assets - runs-on: ubuntu-latest - strategy: - matrix: - platform: - [linux-amd64, linux-arm64, darwin-amd64, darwin-arm64] - - steps: - - name: Checkout code - uses: actions/checkout@v4.1.5 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.0' - - - name: Display Go version - run: go version - - - name: Display the release tag - run: | - echo "Release tag: ${{ github.event.release.tag_name }}" - - - name: Set up environment for cross-compilation - run: | - IFS="-" read -r GOOS GOARCH <<< "${{ matrix.platform }}" - output_name=./build/bin/story-${{ matrix.platform }} - - echo "Building for $GOOS/$GOARCH..." - env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name - - - name: Calculate checksum - run: | - sha256sum ./build/bin/story-${{ matrix.platform }} > ./build/bin/story-${{ matrix.platform }}.sha256 - - - name: Upload binaries and source code to GitHub Release - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.event.release.tag_name }} - file: | - ./build/bin/story-${{ matrix.platform }} - ./build/bin/story-${{ matrix.platform }}.sha256 - file_glob: false diff --git a/.github/workflows/ci-docker-hub.yml b/.github/workflows/ci-docker-hub.yml new file mode 100644 index 00000000..18d8c07b --- /dev/null +++ b/.github/workflows/ci-docker-hub.yml @@ -0,0 +1,55 @@ +name: Build and Push to Docker Hub + +on: + workflow_dispatch: + push: + branches: + - main + +env: + DOCKERHUB_REPOSITORY: jinnuae40/story + NETWORK: iliad + +jobs: + build_and_push: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - run: | + echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "VERSION=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV + echo "BUILDNUM=$GITHUB_RUN_NUMBER" >> $GITHUB_ENV + echo "REPOSITORY_URI=$DOCKERHUB_REPOSITORY" >> $GITHUB_ENV + echo "NETWORK=$NETWORK" >> $GITHUB_ENV + + - uses: docker/setup-buildx-action@v2 + + - uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: ${{ runner.os }}-buildx- + + - uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - run: | + docker buildx create --use + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm64/v8 \ + --build-arg COMMIT=$COMMIT \ + --build-arg VERSION=$VERSION \ + --build-arg BUILDNUM=$BUILDNUM \ + --build-arg NETWORK=$NETWORK \ + -t $REPOSITORY_URI:latest \ + -t $REPOSITORY_URI:$COMMIT \ + -t $REPOSITORY_URI:$VERSION \ + --cache-from=type=local,src=/tmp/.buildx-cache \ + --cache-to=type=local,dest=/tmp/.buildx-cache \ + --push \ + -f ./Dockerfile \ + . diff --git a/.github/workflows/ci-foundry.yml b/.github/workflows/ci-foundry.yml deleted file mode 100644 index 926d7a8d..00000000 --- a/.github/workflows/ci-foundry.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Run this separately from pre-commit for nice visual coverage. -name: Foundry CI - -on: - workflow_call: - -jobs: - # Add a timestamp to the build - Timestamp: - uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main - - foundry-test: - strategy: - fail-fast: true - name: Foundry Unit Test - runs-on: ubuntu-latest - needs: [Timestamp] - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - submodules: recursive - fetch-depth: 0 - - uses: pnpm/action-setup@v2 - with: - package_json_file: contracts/package.json - - - name: Run install - uses: borales/actions-yarn@v4 - with: - cmd: install # will run `yarn install` command - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly - - # First, install the dependencies - - run: pnpm install - working-directory: contracts - - # Run lint - # TODO: Fix and unify linting - # - name: Check lint - # run: pnpm lint-check - # working-directory: contracts - - # first, build contracts excluding the tests and scripts. Check contract sizes in this step. - - name: Run Contract Size check - run: | - forge --version - forge build --force --sizes --skip test --skip script - working-directory: contracts - - # This step requires full build to be run first - - name: Upgrade Safety test - run: | - forge clean && forge build --build-info - working-directory: contracts - # npx @openzeppelin/upgrades-core validate out/build-info - - - name: Run Forge tests - run: | - forge test -vvv --gas-limit 800000000000 - id: forge-test - working-directory: contracts diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml deleted file mode 100644 index 2912c0ac..00000000 --- a/.github/workflows/ci-pr.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: ci pr -# continuous integration on pull requests to main - -on: - pull_request: - branches: - - main - -permissions: - contents: read - pull-requests: read - -jobs: - pre-commit: - uses: ./.github/workflows/pre-commit.yml - go-tests: - uses: ./.github/workflows/gotest.yml - go-lint: - uses: ./.github/workflows/golangci-lint.yml - sol-tests: - uses: ./.github/workflows/ci-foundry.yml diff --git a/.github/workflows/ci-s3.yml b/.github/workflows/ci-s3.yml deleted file mode 100644 index 161cd762..00000000 --- a/.github/workflows/ci-s3.yml +++ /dev/null @@ -1,184 +0,0 @@ -name: Build and Upload story Binary - -on: - workflow_dispatch: - push: - branches: - - main - # # TESTING ONLY - # pull_request: - # branches: - # - main - -permissions: - id-token: write - contents: write - pull-requests: write - actions: write - -env: - NUM_INTERNAL_BINARIES_TO_KEEP: 50 - NUM_PUBLIC_BINARIES_TO_KEEP: 400 - S3_BUCKET: story-geth-binaries - BIN_NAME: story - -jobs: - # Add timestamp - Timestamp: - uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main - - # Build and upload the story binary - build_and_push: - needs: Timestamp - runs-on: ubuntu-latest - strategy: - matrix: - platform: [linux-amd64, linux-arm64, darwin-amd64, darwin-arm64] - - steps: - - name: Checkout code - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_SERVICE_STAGING }}:role/iac-max-role - aws-region: us-west-1 - role-session-name: github-actions - - - name: Extract the version - run: | - PARAMS_FILE="./lib/buildinfo/buildinfo.go" - VERSION_MAJOR=$(awk -F= '/VersionMajor/ {gsub(/[^0-9]/, "", $2); printf "%s", $2}' $PARAMS_FILE) - VERSION_MINOR=$(awk -F= '/VersionMinor/ {gsub(/[^0-9]/, "", $2); printf "%s", $2}' $PARAMS_FILE) - VERSION_PATCH=$(awk -F= '/VersionPatch/ {gsub(/[^0-9]/, "", $2); printf "%s", $2}' $PARAMS_FILE) - VERSION_META=$(awk -F\" '/VersionMeta/ {print $2; exit}' $PARAMS_FILE) - - VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" - if [ "$VERSION_META" != "stable" ]; then - VERSION+="-${VERSION_META}" - fi - - echo "Version extracted: $VERSION" - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "VERSION_META=$VERSION_META" >> $GITHUB_ENV - - - name: Build the story binary - run: | - IFS="-" read -r GOOS GOARCH <<< "${{ matrix.platform }}" - if [ "$GOOS" = "windows" ]; then - export BIN_NAME="${BIN_NAME}.exe" - fi - - echo "Building for $GOOS/$GOARCH..." - cd client - env GOOS=$GOOS GOARCH=$GOARCH go build -o $BIN_NAME > /dev/null 2>&1 - - # Apply chmod only for non-windows platforms - if [ "$GOOS" != "windows" ]; then - chmod +x $BIN_NAME - fi - - - name: Upload the story binary to S3 - run: | - export TZ=America/Los_Angeles - IFS="-" read -r GOOS GOARCH <<< "${{ matrix.platform }}" - TIMESTAMP=$(date +%Y%m%d%H%M%S) - HUMAN_READABLE_VERSION=$(date) - COMMIT_HASH=$(git rev-parse --short HEAD) - FOLDER_NAME="story-${{ matrix.platform }}-${VERSION}-${COMMIT_HASH}" - ARCHIVE_NAME="${FOLDER_NAME}.tar.gz" - PUBLIC_DOWNLOAD_URL="https://$S3_BUCKET.s3.us-west-1.amazonaws.com/$BIN_NAME-public/$ARCHIVE_NAME" - - BIN_NAME_WITH_PATH=./client/$BIN_NAME - if [ "$GOOS" = "windows" ]; then - export BIN_NAME_WITH_PATH="${BIN_NAME_WITH_PATH}.exe" - fi - - mkdir $FOLDER_NAME - mv $BIN_NAME_WITH_PATH $FOLDER_NAME/ - - echo "Archiving the story binary..." - tar -czvf $ARCHIVE_NAME $FOLDER_NAME - - if [ $? -ne 0 ]; then - echo "Failed to create the archive: $ARCHIVE_NAME" - exit 1 - fi - - aws s3 cp $ARCHIVE_NAME s3://$S3_BUCKET/$BIN_NAME-public/$ARCHIVE_NAME --quiet - - if [ "${{ matrix.platform }}" = "linux-amd64" ]; then - - echo "Uploading binary for internal use..." - aws s3 cp $ARCHIVE_NAME s3://$S3_BUCKET/$BIN_NAME/$BIN_NAME-$TIMESTAMP --quiet - - # Update manifest file - aws s3 cp s3://$S3_BUCKET/$BIN_NAME/manifest.txt manifest.txt --quiet || touch manifest.txt - echo "$TIMESTAMP" >> manifest.txt - aws s3 cp manifest.txt s3://$S3_BUCKET/$BIN_NAME/manifest.txt --quiet - - # Update version file - aws s3 cp s3://$S3_BUCKET/$BIN_NAME-public/version.txt version.txt --quiet || printf "File Name\t\t\tVerison\t\t\t\tCommit Hash\t\tTimestamp\n" > version.txt - - if [ "${VERSION_META}" != "stable" ]; then - printf "$VERSION-$COMMIT_HASH\t\t$VERSION\t\t\t$COMMIT_HASH\t\t\t$TIMESTAMP\n" >> version.txt - else - printf "$VERSION-$COMMIT_HASH\t\t\t$VERSION\t\t\t\t$COMMIT_HASH\t\t\t$TIMESTAMP\n" >> version.txt - fi - - aws s3 cp version.txt s3://$S3_BUCKET/$BIN_NAME-public/version.txt --quiet - fi - - echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV - echo "PUBLIC_DOWNLOAD_URL=$PUBLIC_DOWNLOAD_URL" >> $GITHUB_ENV - - - name: Add binary version back to PR - if: matrix.platform == 'linux-amd64' - uses: mshick/add-pr-comment@v2 - with: - message: | - ### Binary uploaded successfully 🎉 - 📦 **Version Name:** ${{ env.VERSION }}-${{ env.COMMIT_HASH }} - 📦 **Download Source:** [AWS S3](${{ env.PUBLIC_DOWNLOAD_URL }}) - - cleanup: - runs-on: ubuntu-latest - needs: build_and_push - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_SERVICE_STAGING }}:role/iac-max-role - aws-region: us-west-1 - role-session-name: github-actions - - - name: Cleanup internal binaries - run: | - cleanup_s3() { - PREFIX=$1 - KEEP=$2 - - echo "Cleaning up in bucket $S3_BUCKET with prefix: $PREFIX, keeping latest $KEEP binaries" - - aws s3api list-objects-v2 --bucket $S3_BUCKET --prefix $PREFIX --query "sort_by(Contents,&LastModified)[*].Key" > all_binaries.json - - # Extract the list of keys, remove the latest $KEEP binaries - BINARIES_TO_DELETE=$(jq -r ".[0:-${KEEP}][]" all_binaries.json) - - if [ -n "$BINARIES_TO_DELETE" ]; then - # Delete old binaries - for key in $BINARIES_TO_DELETE; do - aws s3 rm s3://$S3_BUCKET/$key --quiet - done - echo "Deleted old binaries: $BINARIES_TO_DELETE" - else - echo "No old binaries to delete." - fi - } - - # Cleanup internal binaries - cleanup_s3 "${BIN_NAME}/" "${NUM_INTERNAL_BINARIES_TO_KEEP}" - - # Cleanup public binaries - cleanup_s3 "${BIN_NAME}-public/" "${NUM_PUBLIC_BINARIES_TO_KEEP}" diff --git a/.github/workflows/ci-verifypr.yml b/.github/workflows/ci-verifypr.yml deleted file mode 100644 index 30e743d4..00000000 --- a/.github/workflows/ci-verifypr.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: verifypr -on: - pull_request: - types: [opened, reopened, edited, synchronize] - -jobs: - verify: - runs-on: ubuntu-latest - env: - GITHUB_PR: ${{ toJSON(github.event.pull_request) }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: 'stable' - - name: "Verify PR" - run: go run github.com/piplabs/story/scripts/verifypr diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index e3f5c388..00000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: go lint -# Run this separately from pre-commit since then we get nice inline messages in PRs. - -on: - workflow_call: - -jobs: - golangci: - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.0' - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.59.1 - # Verbose with color. Just fail, don't fix issues. Use both annotations and normal output. - args: -v --color=always --fix=false --timeout=10m --out-format=colored-line-number,github-actions diff --git a/.github/workflows/gotest.yml b/.github/workflows/gotest.yml deleted file mode 100644 index 06c47aad..00000000 --- a/.github/workflows/gotest.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: go tests -# Run this separately from pre-commit for nice visual coverage. - -on: - workflow_call: - -jobs: - unit_tests: - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.0' - # TODO: add coverage - - run: go test -timeout=5m -race -tags=verify_logs ./... diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 4659d26f..00000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: pre-commit hooks - -on: - workflow_call: - -jobs: - pre-commit: - runs-on: ubuntu-latest - env: - # Skip a few hooks: Golangci-lint and go-tests have their own actions. Allow lints against main commits. - SKIP: golangci-lint,run-go-tests,no-commit-to-branch,run-forge-tests,run-solidity-lint - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - name: Install Python - uses: actions/setup-python@v5 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.0' - - name: Run pre-commit hooks - uses: pre-commit/action@v3.0.0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..67f8e606 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Support setting various labels on the final image +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" +ARG NETWORK="" + +# Build Geth in a stock Go builder container +FROM golang:1.22-alpine as builder + +# Set the Current Working Directory inside the container +WORKDIR /story + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download all dependencies. Dependencies are cached if the go.mod and go.sum files are not changed +RUN go mod download + +ADD . /story/ +RUN go build -o story ./client + +# Pull Geth into a second stage deploy alpine container +FROM alpine:latest + +RUN apk add --no-cache ca-certificates +COPY --from=builder /story/story /usr/local/bin/ + +EXPOSE 8545 8546 30303 30303/udp + +RUN story init --network iliad +ENTRYPOINT ["story", "run"] + +# Add some metadata labels to help programmatic image consumption +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"