This commit is contained in:
G4MM4 2024-09-27 17:42:45 -05:00
parent c3c13056c8
commit 49158c24ce
2 changed files with 60 additions and 107 deletions

View File

@ -1,110 +1,91 @@
name: Build and Release
name: Build and Release Erigon Pulse
on:
repository_dispatch:
types: [erigon_pulse_update]
workflow_dispatch:
inputs:
version:
description: 'Version to build (e.g., v1.0.0, latest)'
required: true
default: 'latest'
push:
tags:
- 'v*'
env:
DOCKER_IMAGE_NAME: ${{ vars.GITEA_REGISTRY_URL }}/erigon-pulse:${{ github.event.client_payload.ref }}
DOCKER_IMAGE_NAME: git.g4mm4.io/mirror/erigon-pulse
DOCKER_PLATFORMS: linux/amd64,linux/arm64
ERIGON_REPO: ${{ vars.ERIGON_REPO_URL }}
jobs:
compile_binaries:
runs-on: ubuntu-latest
steps:
- name: Checkout Erigon
uses: actions/checkout@v3
with:
repository: ${{ env.ERIGON_REPO }}
ref: ${{ github.event.client_payload.ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Build for Linux AMD64
run: GOOS=linux GOARCH=amd64 go build -trimpath -tags nosqlite,noboltdb -o _build/linux/erigon-amd64 ./cmd/erigon
- name: Build for Linux ARM64
run: GOOS=linux GOARCH=arm64 go build -trimpath -tags nosqlite,noboltdb -o _build/linux/erigon-arm64 ./cmd/erigon
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: _build/
docker_build:
needs: compile_binaries
runs-on: ubuntu-latest
steps:
- name: Checkout Erigon
- name: Checkout Erigon Pulse Repo
uses: actions/checkout@v3
with:
repository: ${{ env.ERIGON_REPO }}
ref: ${{ github.event.client_payload.ref }}
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: _build/
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
with:
registry: ${{ vars.GITEA_REGISTRY_URL }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
registry: git.g4mm4.io
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.ACCESS_TOKEN }}
- name: Prepare Docker tags
id: prep
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION=${{ github.event.inputs.version }}
elif [[ $GITEA_REF == refs/tags/* ]]; then
VERSION=${GITEA_REF#refs/tags/}
else
VERSION=$(echo $GITEA_SHA | cut -c1-7)
fi
TAGS="${DOCKER_IMAGE_NAME}:${VERSION}"
if [ "$VERSION" = "latest" ]; then
TAGS="$TAGS,${DOCKER_IMAGE_NAME}:latest"
fi
echo "tags=${TAGS}" >> $GITEA_OUTPUT
echo "version=${VERSION}" >> $GITEA_OUTPUT
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ env.DOCKER_IMAGE_NAME }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
BUILD_DATE=${{ github.event.client_payload.timestamp }}
VCS_REF=${{ github.event.client_payload.sha }}
VERSION=${{ github.event.client_payload.ref }}
BUILD_DATE=${{ env.GITEA_COMMIT_TIMESTAMP }}
VCS_REF=${{ gitea.sha }}
VERSION=${{ steps.prep.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
needs: [compile_binaries, docker_build]
if: startsWith(github.event.client_payload.ref, 'refs/tags/')
create_release:
needs: docker_build
if: startsWith(gitea.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: _build/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
_build/linux/erigon-amd64
_build/linux/erigon-arm64
body: |
**Docker Image**
- erigon multi-arch (amd64/arm64): `${{ env.DOCKER_IMAGE_NAME }}`
## Release Notes
_Release created by Gitea Actions (pending release notes)._
tag_name: ${{ github.event.client_payload.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}
docker_tag_latest:
needs: release
if: startsWith(github.event.client_payload.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
with:
registry: ${{ vars.GITEA_REGISTRY_URL }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
- name: Tag latest
run: |
docker buildx imagetools create -t ${{ vars.GITEA_REGISTRY_URL }}/erigon-pulse:latest ${{ env.DOCKER_IMAGE_NAME }}
TAG_NAME=${GITEA_REF#refs/tags/}
curl -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository.full_name }}/releases" \
-H "accept: application/json" \
-H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "'"$TAG_NAME"'",
"target_commitish": "${{ gitea.sha }}",
"name": "Release '"$TAG_NAME"'",
"body": "**Docker Image**\n- erigon-pulse multi-arch (amd64/arm64): `${{ env.DOCKER_IMAGE_NAME }}:'"$TAG_NAME"'`\n\n## Release Notes\n_Release created by Gitea Actions (pending release notes)._",
"draft": false,
"prerelease": false
}'

View File

@ -1,28 +0,0 @@
FROM alpine:latest
ARG TARGETARCH
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
# Labels
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Erigon" \
org.label-schema.description="Erigon Ethereum client" \
org.label-schema.url="https://github.com/ledgerwatch/erigon" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/ledgerwatch/erigon" \
org.label-schema.vendor="Erigon" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
# Install dependencies
RUN apk add --no-cache ca-certificates libgcc
# Copy the pre-built binary into the image
COPY _build/linux/erigon-$TARGETARCH /usr/local/bin/erigon
# Expose default ports
EXPOSE 8545 8551 8546 30303 30303/udp
ENTRYPOINT ["erigon"]