Skip to content

Commit

Permalink
ci: Upload static build artifacts
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
AndreMiras committed Aug 27, 2024
1 parent 12a18d7 commit d176908
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
40 changes: 35 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- main
- release/**
- upgrade/**
# TODO: debugging
- feature/upload_build_artifact
permissions:
contents: read

Expand All @@ -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
Expand All @@ -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 }}
28 changes: 15 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit d176908

Please sign in to comment.