From 7b6bab4986dca3e26566cb02ddfe3e5ca8d4a7f2 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Tue, 9 Nov 2021 13:14:11 +0100 Subject: [PATCH] Release multi-platform with goreleaser Packages, docker images CI automated --- .github/workflows/dockerimage-latest.yml | 26 ----- .github/workflows/dockerimage.yml | 25 ----- .github/workflows/linuxpackage.yml | 67 ------------ .github/workflows/release.yml | 43 ++++++++ .gitignore | 2 + .goreleaser.yml | 126 +++++++++++++++++++++++ Dockerfile.release | 10 ++ Makefile | 34 ++++++ builder/files/bor.service | 18 ++++ 9 files changed, 233 insertions(+), 118 deletions(-) delete mode 100644 .github/workflows/dockerimage-latest.yml delete mode 100644 .github/workflows/dockerimage.yml delete mode 100644 .github/workflows/linuxpackage.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile.release create mode 100644 builder/files/bor.service diff --git a/.github/workflows/dockerimage-latest.yml b/.github/workflows/dockerimage-latest.yml deleted file mode 100644 index 0bfa73503e..0000000000 --- a/.github/workflows/dockerimage-latest.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Docker Images For Latest Branches - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build docker image - env: - DOCKERHUB: ${{ secrets.DOCKERHUB }} - DOCKERHUB_KEY: ${{ secrets.DOCKERHUB_KEY }} - run: | - set -x - ls -l - echo "Docker login" - docker login -u $DOCKERHUB -p $DOCKERHUB_KEY - echo "Running build" - docker build -t maticnetwork/bor:${GITHUB_REF/refs\/heads\//} . - echo "Pushing image" - docker push maticnetwork/bor:${GITHUB_REF/refs\/heads\//} - echo "Done" diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml deleted file mode 100644 index a357399dfb..0000000000 --- a/.github/workflows/dockerimage.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Bor Docker Image CI - -on: - push: - tags: - - 'v*.*.*' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build the Bor Docker image - env: - DOCKERHUB: ${{ secrets.DOCKERHUB }} - DOCKERHUB_KEY: ${{ secrets.DOCKERHUB_KEY }} - run: | - ls -l - echo "Docker login" - docker login -u $DOCKERHUB -p $DOCKERHUB_KEY - echo "running build" - docker build -t maticnetwork/bor:${GITHUB_REF/refs\/tags\//} . - echo "pushing image" - docker push maticnetwork/bor:${GITHUB_REF/refs\/tags\//} - echo "DONE!" diff --git a/.github/workflows/linuxpackage.yml b/.github/workflows/linuxpackage.yml deleted file mode 100644 index f4937e426f..0000000000 --- a/.github/workflows/linuxpackage.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Linux package - -on: - push: - tags: - - "v*.*.*" -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v1 - with: - go-version: 1.17 - - - name: Set up Ruby 2.6 - uses: actions/setup-ruby@v1 - with: - ruby-version: 2.6 - - - name: Retrieve release version - run: | - echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV - - - name: Build package - run: | - set -x - - echo "Release version: ${{ env.RELEASE_VERSION }}" - - sudo apt-get -yqq install libpq-dev build-essential - gem install --no-document fpm - fpm --version - - make bor-all - - fpm -s dir -t deb --deb-user root --deb-group root -n matic-bor -v ${{ env.RELEASE_VERSION }} \ - build/bin/bor=/usr/bin/ \ - build/bin/bootnode=/usr/bin/ - - mkdir packages-v${{ env.RELEASE_VERSION }} - - mv matic-bor_${{ env.RELEASE_VERSION }}_amd64.deb packages-v${{ env.RELEASE_VERSION }}/ - - ls packages-v${{ env.RELEASE_VERSION }}/ - - - name: S3 upload - uses: jakejarvis/s3-sync-action@master - with: - args: --acl public-read - env: - AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_REGION: "us-east-1" # optional: defaults to us-east-1 - SOURCE_DIR: "packages-v${{ env.RELEASE_VERSION }}" - DEST_DIR: "v${{ env.RELEASE_VERSION }}" - - - name: Slack Notification - uses: rtCamp/action-slack-notify@v2.0.0 - env: - SLACK_CHANNEL: code-releases - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_TITLE: "New linux package for Bor v${{ env.RELEASE_VERSION }} just got released" - SLACK_MESSAGE: "Package has been uploaded to S3 bucket for public use and available at https://matic-public.s3.amazonaws.com/v${{ env.RELEASE_VERSION }}/matic-bor_${{ env.RELEASE_VERSION }}_amd64.deb" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..b615cf639e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Release + +on: + push: + branches-ignore: + - '**' + tags: + - 'v*.*.*' + # to be used by fork patch-releases ^^ + - 'v*.*.*-*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: 1.17.x + + - name: Prepare + id: prepare + run: | + TAG=${GITHUB_REF#refs/tags/} + echo ::set-output name=tag_name::${TAG} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Run GoReleaser + run: | + make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.prepare.outputs.tag_name }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + DOCKER_USERNAME: ${{ secrets.DOCKERHUB }} + DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_KEY }} diff --git a/.gitignore b/.gitignore index a56d252322..ad4242c519 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ profile.cov **/yarn-error.log ./test ./bor-debug-* + +dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..b25a316449 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,126 @@ +project_name: bor + +release: + disable: false + draft: true + prerelease: auto + +builds: + - id: darwin-amd64 + main: ./cmd/geth + binary: bor + goos: + - darwin + goarch: + - amd64 + env: + - CC=o64-clang + - CXX=o64-clang++ + ldflags: + -s -w + + - id: darwin-arm64 + main: ./cmd/geth + binary: bor + goos: + - darwin + goarch: + - arm64 + env: + - CC=oa64-clang + - CXX=oa64-clang++ + ldflags: + -s -w + + - id: linux-amd64 + main: ./cmd/geth + binary: bor + goos: + - linux + goarch: + - amd64 + env: + - CC=gcc + - CXX=g++ + ldflags: + # We need to build a static binary because we are building in a glibc based system and running in a musl container + -s -w -linkmode external -extldflags "-static" + + - id: linux-arm64 + main: ./cmd/geth + binary: bor + goos: + - linux + goarch: + - arm64 + env: + - CC=aarch64-linux-gnu-gcc + - CXX=aarch64-linux-gnu-g++ + ldflags: + # We need to build a static binary because we are building in a glibc based system and running in a musl container + -s -w -linkmode external -extldflags "-static" + +nfpms: + - vendor: 0xPolygon + homepage: https://polygon.technology + maintainer: Polygon Team + description: Polygon Blockchain + license: GPLv3 LGPLv3 + + formats: + - apk + - deb + - rpm + + contents: + - src: builder/files/bor.service + dst: /lib/systemd/system/bor.service + type: config + + overrides: + rpm: + replacements: + amd64: x86_64 + +snapshot: + name_template: "{{ .Tag }}.next" + +dockers: + - image_templates: + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-amd64 + dockerfile: Dockerfile.release + use: buildx + goarch: amd64 + ids: + - linux-amd64 + build_flag_templates: + - --platform=linux/amd64 + skip_push: true + + - image_templates: + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-arm64 + dockerfile: Dockerfile.release + use: buildx + goarch: arm64 + ids: + - linux-arm64 + build_flag_templates: + - --platform=linux/arm64 + skip_push: true + +docker_manifests: + - name_template: 0xpolygon/{{ .ProjectName }}:{{ .Version }} + image_templates: + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-amd64 + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-arm64 + + - name_template: 0xpolygon/{{ .ProjectName }}:latest + image_templates: + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-amd64 + - 0xpolygon/{{ .ProjectName }}:{{ .Version }}-arm64 + +announce: + slack: + enabled: true + # The name of the channel that the user selected as a destination for webhook messages. + channel: '#code-releases' diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000000..c0ae7f9c29 --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,10 @@ +FROM alpine:3.14 + +RUN set -x \ + && apk add --update --no-cache \ + ca-certificates \ + && rm -rf /var/cache/apk/* +COPY bor /usr/local/bin/ + +EXPOSE 8545 8546 8547 30303 30303/udp +ENTRYPOINT ["bor"] diff --git a/Makefile b/Makefile index b9bc9db602..462f129f51 100644 --- a/Makefile +++ b/Makefile @@ -163,3 +163,37 @@ geth-windows-amd64: $(GORUN) build/ci.go xgo -- --go=$(GO) --targets=windows/amd64 -v ./cmd/geth @echo "Windows amd64 cross compilation done:" @ls -ld $(GOBIN)/geth-windows-* | grep amd64 + +PACKAGE_NAME := github.com/maticnetwork/bor +GOLANG_CROSS_VERSION ?= v1.17.2 + +.PHONY: release-dry-run +release-dry-run: + @docker run \ + --rm \ + --privileged \ + -e CGO_ENABLED=1 \ + -e GITHUB_TOKEN \ + -e DOCKER_USERNAME \ + -e DOCKER_PASSWORD \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + ghcr.io/troian/golang-cross:${GOLANG_CROSS_VERSION} \ + --rm-dist --skip-validate --skip-publish + +.PHONY: release +release: + @docker run \ + --rm \ + --privileged \ + -e CGO_ENABLED=1 \ + -e GITHUB_TOKEN \ + -e DOCKER_USERNAME \ + -e DOCKER_PASSWORD \ + -e SLACK_WEBHOOK \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + ghcr.io/troian/golang-cross:${GOLANG_CROSS_VERSION} \ + --rm-dist --skip-validate diff --git a/builder/files/bor.service b/builder/files/bor.service new file mode 100644 index 0000000000..18d075f799 --- /dev/null +++ b/builder/files/bor.service @@ -0,0 +1,18 @@ +[Unit] + Description=bor + StartLimitIntervalSec=500 + StartLimitBurst=5 + +[Service] + Restart=on-failure + RestartSec=5s + WorkingDirectory=$NODE_DIR + EnvironmentFile=/etc/matic/metadata + ExecStart=/usr/local/bin/bor $VALIDATOR_ADDRESS + Type=simple + User=$USER + KillSignal=SIGINT + TimeoutStopSec=120 + +[Install] + WantedBy=multi-user.target