Skip to content

Commit

Permalink
Add support for building Debian packages (arm/amd) in the release wor…
Browse files Browse the repository at this point in the history
…kflow. (#13024)

See #12891 for more details.
Changes:
- new reusable workflow for building debian packages
- this reusable workflow is a part of release workflow. Binaries which
is built during build stage used to build docker image, debian package
and to publish as release artifacts.
  • Loading branch information
lystopad authored Dec 6, 2024
1 parent e638d76 commit 7181f4c
Show file tree
Hide file tree
Showing 2 changed files with 333 additions and 72 deletions.
266 changes: 194 additions & 72 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Release
run-name: "Build release ${{ inputs.release_version}} from branch ${{ inputs.checkout_ref }} by @${{ github.actor}}"

env:
APPLICATION: "erigon"
Expand All @@ -7,7 +8,7 @@ env:
APP_REPO: "erigontech/erigon"
PACKAGE: "github.com/erigontech/erigon"
DOCKERHUB_REPOSITORY: "erigontech/erigon"
DOCKERFILE_PATH: "./Dockerfile.release"
DOCKERFILE_PATH: "Dockerfile.release"
GITHUB_AUTOMATION_EMAIL: "[email protected]"
GITHUB_AUTOMATION_NAME: "Erigon Github Automation"
LABEL_DESCRIPTION: "Erigon is an implementation of Ethereum (execution layer with embeddable consensus layer), on the efficiency frontier. Archive Node by default."
Expand All @@ -16,12 +17,6 @@ on:
push:
branches-ignore:
- '**'
#branches:
# - 'master'
#tags:
## only trigger on release tags:
#- 'v*.*.*'
#- 'v*.*.*-*'
workflow_dispatch:
inputs:
checkout_ref:
Expand Down Expand Up @@ -50,8 +45,13 @@ jobs:
build-release:
## runs-on: ubuntu-22.04
runs-on: ubuntu-latest-devops-xxlarge
timeout-minutes: 60
name: Build Artifacts and multi-platform Docker image, publish draft of the Release Notes
timeout-minutes: 75
name: Create git tag, build and publish Artifacts
outputs:
commit-id: ${{ steps.getCommitId.outputs.id }}
short-commit-id: ${{ steps.getCommitId.outputs.short_commit_id }}
application: ${{ env.APPLICATION }}
parsed-version: ${{ steps.getCommitId.outputs.parsed_version}}

steps:
- name: Checkout git repository ${{ env.APP_REPO }}
Expand All @@ -69,19 +69,17 @@ jobs:
exit 1
else
echo "OK: tag ${{ inputs.release_version }} does not exists. Proceeding."
git tag ${{ inputs.release_version }}
git push origin ${{ inputs.release_version }}
echo; echo "Git TAG ${{ inputs.release_version }} created and pushed."
fi
- name: Get commit id
id: getCommitId
run: |
echo "id=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "short_commit_id=$(git rev-parse --short=7 HEAD)" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 ## v3.3.0
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}
echo "parsed_version=$(echo ${{ inputs.release_version }} | sed -e 's/^v//g')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf ## v3.2.0
Expand Down Expand Up @@ -110,37 +108,6 @@ jobs:
echo "DEBUG: content of the dist/ directory"
find dist/ -ls
- name: Build and push multi-platform docker images (${{ env.BUILD_VERSION }} and latest) in case perform_release is true
if: ${{ inputs.perform_release }}
env:
BUILD_VERSION: ${{ inputs.release_version }}
DOCKER_URL: ${{ env.DOCKERHUB_REPOSITORY }}
DOCKER_PUBLISH_LATEST_CONDITION: ${{ inputs.publish_latest_tag && format('--tag {0}:latest ',env.DOCKERHUB_REPOSITORY) || '' }}
run: |
docker buildx build \
--file ${{ env.DOCKERFILE_PATH }} \
--build-arg RELEASE_DOCKER_BASE_IMAGE=${{ env.DOCKER_BASE_IMAGE }} \
--build-arg VERSION=${{ env.BUILD_VERSION }} \
--build-arg APPLICATION=${{ env.APPLICATION }} \
--tag ${{ env.DOCKER_URL }}:${{ env.BUILD_VERSION }} \
--target release \
--attest type=provenance,mode=max \
--sbom=true \
${{ env.DOCKER_PUBLISH_LATEST_CONDITION }} \
--label org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--label org.opencontainers.image.authors="https://github.com/erigontech/erigon/graphs/contributors" \
--label org.opencontainers.image.url="https://github.com/erigontech/erigon/blob/main/Dockerfile" \
--label org.opencontainers.image.documentation="https://github.com/erigontech/erigon/blob/main/Dockerfile" \
--label org.opencontainers.image.source="https://github.com/erigontech/erigon/blob/main/Dockerfile" \
--label org.opencontainers.image.version=${{ inputs.release_version }} \
--label org.opencontainers.image.revision=${{ steps.getCommitId.outputs.id }} \
--label org.opencontainers.image.vcs-ref-short=${{ steps.getCommitId.outputs.short_commit_id }} \
--label org.opencontainers.image.vendor="${{ github.repository_owner }}" \
--label org.opencontainers.image.description="${{ env.LABEL_DESCRIPTION }}" \
--label org.opencontainers.image.base.name="${{ env.DOCKER_BASE_IMAGE }}" \
--push \
--platform linux/amd64,linux/amd64/v2,linux/arm64 .
- name: Upload artifact -- linux/arm64
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a ## v4.3.6
with:
Expand Down Expand Up @@ -186,30 +153,185 @@ jobs:
compression-level: 0
if-no-files-found: error

## not required for now -- commented:
# - name: Create and push a git tag for the released version in case perform_release is set
# if: ${{ inputs.perform_release }}
# run: |
# git config --global user.email ${{ env.GITHUB_AUTOMATION_EMAIL }}
# git config --global user.name "${{ env.GITHUB_AUTOMATION_NAME }}"
# git tag -a ${{ inputs.release_version }} -m "Release ${{ inputs.release_version }}"
# git push origin ${{ inputs.release_version }}

- name: Publish draft of the Release notes with assets in case perform_release is set
if: ${{ inputs.perform_release }}
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
DOCKER_TAGS: ${{ env.DOCKERHUB_REPOSITORY }}:${{ inputs.release_version }}
GITHUB_RELEASE_TARGET: ${{ inputs.checkout_ref }}


build-debian-pkg:
name: Debian packages
needs: [ build-release ]
uses: erigontech/erigon/.github/workflows/reusable-release-build-debian-pkg.yml@main
with:
application: ${{ needs.build-release.outputs.application }}
version: ${{ needs.build-release.outputs.parsed-version }}



publish-docker-image:
needs: [ build-release ]
runs-on: ubuntu-latest
timeout-minutes: 30
name: Docker image

steps:

- name: Fast checkout just ${{ env.DOCKERFILE_PATH }} from git repository ${{ env.APP_REPO }}
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 ## 4.1.7 release
with:
repository: ${{ env.APP_REPO }}
sparse-checkout: ${{ env.DOCKERFILE_PATH }}
sparse-checkout-cone-mode: false
ref: ${{ needs.build-release.outputs.commit-id }}

- name: Download arm64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_arm64.tar.gz
path: dist/

- name: Download amd64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_amd64.tar.gz
path: dist/

- name: Download amd64v2 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_amd64v2.tar.gz
path: dist/

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf ## v3.2.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db ## v3.6.1

- name: Login to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 ## v3.3.0
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}

- name: Build and push multi-platform docker images (${{ env.BUILD_VERSION }} and maybe latest) in case perform_release is true
if: ${{ inputs.perform_release }}
env:
BUILD_VERSION: ${{ inputs.release_version }}
DOCKER_URL: ${{ env.DOCKERHUB_REPOSITORY }}
DOCKER_PUBLISH_LATEST_CONDITION: ${{ inputs.publish_latest_tag && format('--tag {0}:latest ',env.DOCKERHUB_REPOSITORY) || '' }}
run: |
pwd
find . -ls
docker buildx build \
--file ${{ env.DOCKERFILE_PATH }} \
--build-arg RELEASE_DOCKER_BASE_IMAGE=${{ env.DOCKER_BASE_IMAGE }} \
--build-arg VERSION=${{ env.BUILD_VERSION }} \
--build-arg APPLICATION=${{ env.APPLICATION }} \
--tag ${{ env.DOCKER_URL }}:${{ env.BUILD_VERSION }} \
--target release \
--attest type=provenance,mode=max \
--sbom=true \
${{ env.DOCKER_PUBLISH_LATEST_CONDITION }} \
--label org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--label org.opencontainers.image.authors="https://github.com/erigontech/erigon/graphs/contributors" \
--label org.opencontainers.image.url="https://github.com/erigontech/erigon/blob/${{ inputs.checkout_ref }}/${{ env.DOCKERFILE_PATH }}" \
--label org.opencontainers.image.documentation="https://github.com/erigontech/erigon/blob/${{ inputs.checkout_ref }}/${{ env.DOCKERFILE_PATH }}" \
--label org.opencontainers.image.source="https://github.com/erigontech/erigon/blob/${{ inputs.checkout_ref }}/${{ env.DOCKERFILE_PATH }}" \
--label org.opencontainers.image.version=${{ inputs.release_version }} \
--label org.opencontainers.image.revision=${{ needs.build-release.outputs.commit-id }} \
--label org.opencontainers.image.vcs-ref-short=${{ needs.build-release.outputs.short-commit-id }} \
--label org.opencontainers.image.vendor="${{ github.repository_owner }}" \
--label org.opencontainers.image.description="${{ env.LABEL_DESCRIPTION }}" \
--label org.opencontainers.image.base.name="${{ env.DOCKER_BASE_IMAGE }}" \
--push \
--platform linux/amd64,linux/amd64/v2,linux/arm64 .
publish-release:
needs: [ build-debian-pkg, publish-docker-image, build-release ]
runs-on: ubuntu-latest
timeout-minutes: 15
name: Publish release notes

steps:
- name: Download linux/arm64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_arm64.tar.gz
path: dist/

- name: Download linux/amd64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_amd64.tar.gz
path: dist/

- name: Download linux/amd64v2 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_linux_amd64v2.tar.gz
path: dist/

- name: Download darwin/amd64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_darwin_amd64.tar.gz
path: dist/

- name: Download darwin/arm64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ inputs.release_version }}_darwin_arm64.tar.gz
path: dist/

- name: Download arm64 debian package
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ needs.build-release.outputs.parsed-version }}_arm64.deb
path: dist/

- name: Download amd64 debian package
uses: actions/download-artifact@v4
with:
name: ${{ env.APPLICATION }}_${{ needs.build-release.outputs.parsed-version }}_amd64.deb
path: dist/

- name: Publish draft of the Release notes with assets in case perform_release is set
if: ${{ inputs.perform_release }}
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
DOCKER_TAGS: ${{ env.DOCKERHUB_REPOSITORY }}:${{ inputs.release_version }}
GITHUB_RELEASE_TARGET: ${{ inputs.checkout_ref }}
run: |
cd dist
sha256sum *.tar.gz *.deb > ${HOME}/${{ env.APPLICATION }}_${{ inputs.release_version }}_checksums.txt
gh release create \
--generate-notes \
--target ${GITHUB_RELEASE_TARGET} \
--draft=true \
--title "${{ inputs.release_version }}" \
--notes "**Improvements:**<br>- ...coming soon <br><br>**Bugfixes:**<br><br>- ...coming soon<br><br>**Docker images:**<br><br>Docker image released:<br> ${{ env.DOCKER_TAGS }}<br><br>... coming soon<br>" \
"${{ inputs.release_version }}" \
*.tar.gz *.deb ${HOME}/${{ env.APPLICATION }}_${{ inputs.release_version }}_checksums.txt
In-case-of-failure:
name: "In case of failure: remove remote git tag pointing to the new version."
needs: [ publish-release, build-release ]
if: always() && !contains(needs.build-release.result, 'success')
runs-on: ubuntu-22.04

steps:
- name: Checkout git repository ${{ env.APP_REPO }} reference ${{ inputs.checkout_ref }}
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 ## 4.1.7 release
with:
repository: ${{ env.APP_REPO }}
fetch-depth: 0
ref: ${{ inputs.checkout_ref }}
path: 'erigon'

- name: Rollback - remove git tag ${{ inputs.release_version }}
if: ${{ (inputs.perform_release) && (inputs.release_version != '') }}
run: |
cd dist
sha256sum *.tar.gz > ${HOME}/${{ env.APPLICATION }}_${{ inputs.release_version }}_checksums.txt
gh release create \
--generate-notes \
--target ${GITHUB_RELEASE_TARGET} \
--draft=true \
--title "${{ inputs.release_version }}" \
--notes "**Improvements:**<br>- ...coming soon <br><br>**Bugfixes:**<br><br>- ...coming soon<br><br>**Docker images:**<br><br>Docker image released:<br> ${{ env.DOCKER_TAGS }}<br><br>... coming soon<br>" \
"${{ inputs.release_version }}" \
*.tar.gz ${HOME}/${{ env.APPLICATION }}_${{ inputs.release_version }}_checksums.txt
cd erigon
git push -d origin ${{ inputs.release_version }}
Loading

0 comments on commit 7181f4c

Please sign in to comment.