diff --git a/.github/workflows/alpha-releases.yaml b/.github/workflows/alpha-releases.yaml new file mode 100644 index 0000000..e42791e --- /dev/null +++ b/.github/workflows/alpha-releases.yaml @@ -0,0 +1,59 @@ +name: alpha releases + +on: + push: + branches: + - 'release/*' + +jobs: + tag-release: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + token: ${{ secrets.EPOBOT_TOKEN }} + - name: Get latest release version for this release branch + if: startsWith(github.ref, 'refs/heads/release/') + id: latest_version + run: | + # Extract suffix from branch name (e.g., 'dencun' from 'release/dencun') + RELEASE_SUFFIX=${GITHUB_REF#refs/heads/release/} + + # Fetch all tags and get the latest that matches the pattern + # Using the refs/tags API + LATEST_VERSION=$(curl --silent "https://api.github.com/repos/$GITHUB_REPOSITORY/git/refs/tags" \ + | jq -r --arg suffix "$RELEASE_SUFFIX" '.[] | select(.ref | test("refs/tags/v?[0-9]+\\.[0-9]+\\.[0-9]+-" + $suffix + "$")) | .ref' \ + | sed 's|refs/tags/||' | sort -V | tail -n 1) + echo "Found latest $RELEASE_SUFFIX version: $LATEST_VERSION" + + # Default to 0.0.0 if no matching release was found + if [[ -z "$LATEST_VERSION" ]]; then + LATEST_VERSION="0.0.0" + fi + + # Increment the patch version using bash + LATEST_VERSION=$(echo "$LATEST_VERSION" | awk -F. -v OFS=. '{$NF = $NF + 1;} 1') + + VERSION=$LATEST_VERSION-$RELEASE_SUFFIX + + echo "Releasing version: $VERSION" + + git config --global user.email "ethpandaopsbot@ethereum.org" + git config --global user.name "ethpandaopsbot" + + # Log the short commit SHA + SHORT_COMMIT=$(git rev-parse --short HEAD) + + echo "Git commit: $SHORT_COMMIT" + + git tag -a "$VERSION" -m "Release $VERSION" + + echo "RELEASE_SUFFIX=$RELEASE_SUFFIX" >> $GITHUB_ENV + + # Push the tag + git push origin "$VERSION" + env: + GITHUB_TOKEN: ${{ secrets.EPOBOT_TOKEN }} diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index d1fca75..d8a94f9 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -7,28 +7,77 @@ on: jobs: goreleaser: - runs-on: ubuntu-latest + runs-on: + - environment=production + - size=xxlarge + - provider=ethpandaops + - realm=platform steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - - - name: Set up Go + ref: ${{ github.ref }} + - name: Derive release suffix from tag (if it exists) + run: | + # Strip the 'refs/tags/' prefix + TAG_NAME=${GITHUB_REF#refs/tags/} + + # Extract suffix from tag name after the last '-' (e.g., 'dencun' from 'v1.0.0-dencun') + RELEASE_SUFFIX=${TAG_NAME##*-} + + # Check if the suffix is still a version pattern (e.g., 'v0.0.44'), in which case there's no suffix + if [[ $RELEASE_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + RELEASE_SUFFIX="" + fi + + echo "RELEASE_SUFFIX=$RELEASE_SUFFIX" >> $GITHUB_ENV + + echo "Release suffix: $RELEASE_SUFFIX" + + - name: Set up Go uses: actions/setup-go@v3 - - - name: Login to DockerHub + with: + go-version: '1.19' + - name: Run apt-get update + run: sudo apt-get update + - name: Install cross-compiler for linux/arm64 + run: sudo apt-get -y install gcc-aarch64-linux-gnu + - name: Install make + run: sudo apt-get -y install make + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Context for Buildx + shell: bash + id: buildx-context + run: | + docker context create builders + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + endpoint: builders + - name: Login to DockerHub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Run GoReleaser + - name: Update GoReleaser config + run: | + cp .goreleaser.yaml ../.goreleaser.yaml.new + + # If we have a RELEASE_SUFFIX, update the goreleaser config to not set + # the release as the latest + if [[ -n "$RELEASE_SUFFIX" ]]; then + echo "release:" >> ../.goreleaser.yaml.new + echo " prerelease: true" >> ../.goreleaser.yaml.new + echo " make_latest: false" >> ../.goreleaser.yaml.new + fi + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser version: latest - args: release --rm-dist + args: release --clean --config ../.goreleaser.yaml.new env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_SUFFIX: ${{ env.RELEASE_SUFFIX }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 047d6db..b9837cd 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -45,9 +45,9 @@ dockers: dockerfile: goreleaser-scratch.Dockerfile image_templates: - "samcm/{{ .ProjectName }}:{{ .Version }}-amd64" - - "samcm/{{ .ProjectName }}:latest-amd64" + - "samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-amd64" - "ethpandaops/{{ .ProjectName }}:{{ .Version }}-amd64" - - "ethpandaops/{{ .ProjectName }}:latest-amd64" + - "ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-amd64" build_flag_templates: - "--platform=linux/amd64" - "--label=org.opencontainers.image.created={{.Date}}" @@ -60,9 +60,9 @@ dockers: dockerfile: goreleaser-scratch.Dockerfile image_templates: - "samcm/{{ .ProjectName }}:{{ .Version }}-arm64v8" - - "samcm/{{ .ProjectName }}:latest-arm64v8" + - "samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-arm64v8" - "ethpandaops/{{ .ProjectName }}:{{ .Version }}-arm64v8" - - "ethpandaops/{{ .ProjectName }}:latest-arm64v8" + - "ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-arm64v8" build_flag_templates: - "--platform=linux/arm64/v8" - "--label=org.opencontainers.image.created={{.Date}}" @@ -76,9 +76,9 @@ dockers: dockerfile: goreleaser-debian.Dockerfile image_templates: - "samcm/{{ .ProjectName }}:{{ .Version }}-debian-amd64" - - "samcm/{{ .ProjectName }}:debian-latest-amd64" + - "samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-amd64" - "ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian-amd64" - - "ethpandaops/{{ .ProjectName }}:debian-latest-amd64" + - "ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-amd64" build_flag_templates: - "--platform=linux/amd64" - "--label=org.opencontainers.image.created={{.Date}}" @@ -91,9 +91,9 @@ dockers: dockerfile: goreleaser-debian.Dockerfile image_templates: - "samcm/{{ .ProjectName }}:{{ .Version }}-debian-arm64v8" - - "samcm/{{ .ProjectName }}:debian-latest-arm64v8" + - "samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-arm64v8" - "ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian-arm64v8" - - "ethpandaops/{{ .ProjectName }}:debian-latest-arm64v8" + - "ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-arm64v8" build_flag_templates: - "--platform=linux/arm64/v8" - "--label=org.opencontainers.image.created={{.Date}}" @@ -109,10 +109,10 @@ docker_manifests: - name_template: samcm/{{ .ProjectName }}:{{ .Version }}-arm64 image_templates: - samcm/{{ .ProjectName }}:{{ .Version }}-arm64v8 - - name_template: samcm/{{ .ProjectName }}:latest + - name_template: samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest image_templates: - - samcm/{{ .ProjectName }}:latest-amd64 - - samcm/{{ .ProjectName }}:latest-arm64v8 + - samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-amd64 + - samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-arm64v8 - name_template: ethpandaops/{{ .ProjectName }}:{{ .Version }} image_templates: @@ -121,10 +121,10 @@ docker_manifests: - name_template: ethpandaops/{{ .ProjectName }}:{{ .Version }}-arm64 image_templates: - ethpandaops/{{ .ProjectName }}:{{ .Version }}-arm64v8 - - name_template: ethpandaops/{{ .ProjectName }}:latest + - name_template: ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest image_templates: - - ethpandaops/{{ .ProjectName }}:latest-amd64 - - ethpandaops/{{ .ProjectName }}:latest-arm64v8 + - ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-amd64 + - ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}latest-arm64v8 ## Debian - name_template: samcm/{{ .ProjectName }}:{{ .Version }}-debian @@ -134,10 +134,10 @@ docker_manifests: - name_template: samcm/{{ .ProjectName }}:{{ .Version }}-debian-arm64 image_templates: - samcm/{{ .ProjectName }}:{{ .Version }}-debian-arm64v8 - - name_template: samcm/{{ .ProjectName }}:debian-latest + - name_template: samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest image_templates: - - samcm/{{ .ProjectName }}:debian-latest-amd64 - - samcm/{{ .ProjectName }}:debian-latest-arm64v8 + - samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-amd64 + - samcm/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-arm64v8 - name_template: ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian image_templates: - ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian-amd64 @@ -145,7 +145,7 @@ docker_manifests: - name_template: ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian-arm64 image_templates: - ethpandaops/{{ .ProjectName }}:{{ .Version }}-debian-arm64v8 - - name_template: ethpandaops/{{ .ProjectName }}:debian-latest + - name_template: ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest image_templates: - - ethpandaops/{{ .ProjectName }}:debian-latest-amd64 - - ethpandaops/{{ .ProjectName }}:debian-latest-arm64v8 \ No newline at end of file + - ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-amd64 + - ethpandaops/{{ .ProjectName }}:{{ if .Env.RELEASE_SUFFIX }}{{ .Env.RELEASE_SUFFIX }}-{{ end }}debian-latest-arm64v8 \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8cbea54 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Go", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceRoot}", + "args": [ + "--config", + "${workspaceRoot}/config.yaml" + ], + } + ] +} \ No newline at end of file diff --git a/goreleaser-debian.Dockerfile b/goreleaser-debian.Dockerfile index 89450d1..1bad772 100644 --- a/goreleaser-debian.Dockerfile +++ b/goreleaser-debian.Dockerfile @@ -1,3 +1,8 @@ FROM debian:latest +RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ + libssl-dev \ + ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* COPY ethereum-metrics-exporter* /ethereum-metrics-exporter ENTRYPOINT ["/ethereum-metrics-exporter"]