Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add static binary build in Dockerfile #1323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mamirpanah
Copy link

This PR aims to add static binary build in Dockerfile

@taariq taariq requested a review from byte-bandit January 2, 2025 15:12
@taariq
Copy link
Contributor

taariq commented Jan 2, 2025

Thank you for the PR @mamirpanah. We'll take a look and review!

@taariq taariq added the devops label Jan 2, 2025
Copy link
Contributor

@byte-bandit byte-bandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Left a few comments to improve.

I'm curious, does this solution actually result in a working container that lets you run a full node?

FROM golang:1.22-alpine3.19 AS static-builder
WORKDIR /app
COPY . .
RUN apk add --no-cache make git gcc linux-headers build-base curl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to an earlier layer to avoid rebuilding every time a file chances.

################################
FROM golang:1.22-alpine3.19 AS static-builder
WORKDIR /app
COPY . .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually better to copy only go.mod and perform the download, then copy the remaining files and perform the build. That way, you don't touch dependencies for every build.

Comment on lines +30 to +31
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a -O /lib/libwasmvm.$(uname -m).a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paloma uses a fixed version of libwasm, which deviates from the latest. This needs to use the same version specified in the README.

Also, move this step to the external dependency resolution layer above (apk add...) to cache this properly.

-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(go list -m github.com/cometbft/cometbft | sed 's:.* ::') \
-linkmode=external -extldflags '-Wl,-z,muldefs -static'" ./cmd/palomad

ENTRYPOINT ["/app/build/palomad"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split into two images, builder and runner. Runner image can be much slimmer by stripping all dependencies needed only for building. It also doesn't need a full copy of the source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants