From d176908f3c5d8a76524b2b540bcf87b33883d2f0 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 26 Aug 2024 22:49:00 +0200 Subject: [PATCH] ci: Upload static build artifacts Make a static build and upload as artifact. This makes it possible to download the binary produced for each PR. In a follow up PR we could also automate binary upload upon release as well as enabling different arch or OS. Note that we use musl-gcc as it allows to statically link a libc implementation while CGO_ENABLED=0 only was leading to the error below: ``` ethermint@v0.22.0-sdk50-1/app/ante/eip712.go:293:36: undefined: secp256k1.RecoverPubkey ethermint@v0.22.0-sdk50-1/app/ante/eip712.go:319:17: undefined: secp256k1.VerifySignature ``` --- .github/workflows/build.yml | 40 ++++++++++++++++++++++++++++++++----- Dockerfile | 28 ++++++++++++++------------ 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f0dd70a2..085bd8fa2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,8 @@ on: - main - release/** - upgrade/** + # TODO: debugging + - feature/upload_build_artifact permissions: contents: read @@ -20,9 +22,10 @@ jobs: strategy: matrix: go-arch: ["amd64"] + go-os: ["linux"] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: "^1.21" - uses: technote-space/get-diff-action@v6.1.2 @@ -36,6 +39,33 @@ jobs: **/go.sum **/Makefile Makefile - - name: Build - if: env.GIT_DIFF - run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build + # TODO: reenable once everything is working + # Non-static build with Go + # - name: Non-static Build with Go + # run: | + # GOARCH=${{ matrix.go-arch }} GOOS=${{ matrix.go-os }} LEDGER_ENABLED=false make build + # mv ./build/cantod ./build/cantod-nonstatic-${{ matrix.go-os }}-${{ matrix.go-arch }} + - name: Install musl-tools + run: sudo apt-get update && sudo apt-get install -y musl-tools + - name: Static Build + env: + CC: musl-gcc + CGO_ENABLED: 1 + GOARCH: ${{ matrix.go-arch }} + GOOS: ${{ matrix.go-os }} + LEDGER_ENABLED: false + LDFLAGS: "-extldflags -static" + run: | + # TODO: move to env or line break + # CC=musl-gcc CGO_ENABLED=1 GOARCH=${{ matrix.go-arch }} GOOS=${{ matrix.go-os }} LEDGER_ENABLED=false make build LDFLAGS="-extldflags \"-static\"" + make build + # TODO debugging + ls -lh build/cantod + file build/cantod + build/cantod + mv build/cantod ./build/cantod-${{ matrix.go-os }}-${{ matrix.go-arch }} + - name: Upload cantod Binary (Static) + uses: actions/upload-artifact@v4 + with: + name: cantod-${{ matrix.go-os }}-${{ matrix.go-arch }} + path: ./build/cantod-${{ matrix.go-os }}-${{ matrix.go-arch }} diff --git a/Dockerfile b/Dockerfile index 3fbf07455..b980da766 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,25 @@ -FROM golang:stretch AS build-env +# TODO: debugging +FROM golang:1.21 AS build-env WORKDIR /go/src/github.com/canto/canto RUN apt-get update -y RUN apt-get install git -y +RUN curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun COPY . . RUN make build -FROM golang:stretch - -RUN apt-get update -y -RUN apt-get install ca-certificates jq -y - -WORKDIR /root - -COPY --from=build-env /go/src/github.com/canto/canto/build/cantod /usr/bin/cantod - -EXPOSE 26656 26657 1317 9090 - -CMD ["cantod"] +# FROM golang:stretch +# +# RUN apt-get update -y +# RUN apt-get install ca-certificates jq -y +# +# WORKDIR /root +# +# COPY --from=build-env /go/src/github.com/canto/canto/build/cantod /usr/bin/cantod +# +# EXPOSE 26656 26657 1317 9090 +# +# CMD ["cantod"]