From e76a59b7f5ca0197139d8202a258b72f459edb0f Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Mon, 30 Oct 2023 10:54:57 -0600 Subject: [PATCH] feat: add arm docker build --- .github/workflows/release.yml | 12 +++- dockerfiles/Dockerfile.node-static | 76 ++++++++++++++++++++++ scripts/validator_setup/validator_setup.sh | 2 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 dockerfiles/Dockerfile.node-static diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f02cf0b..ca2ba29e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,6 +49,12 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -66,7 +72,11 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./dockerfiles/Dockerfile.node + file: ./dockers/Dockerfile.node-static + platforms: linux/amd64,linux/arm64 + GO_VERSION: "1.21" + RUNNER_IMAGE: "gcr.io/distroless/static-debian11:nonroot" + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/dockerfiles/Dockerfile.node-static b/dockerfiles/Dockerfile.node-static new file mode 100644 index 00000000..6ac1502f --- /dev/null +++ b/dockerfiles/Dockerfile.node-static @@ -0,0 +1,76 @@ +# syntax=docker/dockerfile:1 +ARG GO_VERSION="1.20" +ARG RUNNER_IMAGE="gcr.io/distroless/static-debian11" + +# -------------------------------------------------------- +# Builder +# -------------------------------------------------------- + +FROM golang:${GO_VERSION}-alpine as builder + +ARG GIT_VERSION +ARG GIT_COMMIT + +RUN apk add --no-cache \ + ca-certificates \ + build-base \ + linux-headers + +# Download go dependencies +WORKDIR /seda-chain +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + go mod download + +# Cosmwasm - Download correct libwasmvm version +RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \ + -O /lib/libwasmvm_muslc.a && \ + # verify checksum + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ + sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1) + +# Copy the remaining files +COPY . . + +# Build seda-chiand binary +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + GOWORK=off go build -v \ + -mod=readonly \ + -tags "netgo,ledger,muslc" \ + -ldflags \ + "-X github.com/cosmos/cosmos-sdk/version.Name="seda-chain" \ + -X github.com/cosmos/cosmos-sdk/version.AppName="seda-chaind" \ + -X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \ + -X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \ + -w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \ + -trimpath \ + -o /seda-chain/build/seda-chaind \ + cmd/seda-chaind/main.go +# --------- To include chmod and shell for static image +FROM busybox:1.35.0-uclibc as busybox +# -------------------------------------------------------- +# Runner +# -------------------------------------------------------- +FROM ${RUNNER_IMAGE} + +COPY --from=busybox ["/bin/sh", "/bin/chmod", "/bin/chown", "/bin/mkdir", "/bin/"] +RUN mkdir -p /seda-chain/.seda-chain && chown nonroot:nonroot -R /seda-chain/.seda-chain + +USER nonroot +COPY --from=builder --chown=nonroot:nonroot /seda-chain/build/seda-chaind /bin/seda-chaind + +ENV HOME /seda-chain +WORKDIR $HOME + +EXPOSE 26656 +EXPOSE 26657 +EXPOSE 1317 +EXPOSE 9090 + +COPY --chown=nonroot:nonroot scripts/validator_setup/validator_setup.sh . +RUN chmod +x validator_setup.sh +ENTRYPOINT ["sh", "validator_setup.sh"] diff --git a/scripts/validator_setup/validator_setup.sh b/scripts/validator_setup/validator_setup.sh index e7691939..03690103 100644 --- a/scripts/validator_setup/validator_setup.sh +++ b/scripts/validator_setup/validator_setup.sh @@ -52,7 +52,7 @@ echo "Initializing Node ..." # Check if configuration directory seda-chain config directory exist if it does not # exist initialize the node with the given MNEMONIC, MONIKER and NETWORK_ID -if ! [ -f /root/.seda-chain/config/genesis.json ]; then +if ! [ -f /seda-chain/.seda-chain/config/genesis.json ]; then echo "Setting Up seda configuration" $BIN config keyring-backend file # use file backend echo $MNEMONIC | $BIN init join ${MONIKER} --network ${NETWORK_ID} --recover