mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
Regular → Executable
+147
-25
@@ -1,41 +1,163 @@
|
||||
FROM golang:1.24-alpine AS go-builder
|
||||
# Use build argument for base image to allow using pre-cached base
|
||||
ARG BASE_IMAGE=golang:1.24.7-alpine3.22
|
||||
|
||||
FROM ${BASE_IMAGE} AS builder
|
||||
SHELL ["/bin/sh", "-ecuxo", "pipefail"]
|
||||
|
||||
RUN apk add --no-cache ca-certificates build-base git
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
ca-certificates \
|
||||
build-base \
|
||||
git \
|
||||
linux-headers \
|
||||
bash \
|
||||
binutils-gold \
|
||||
wget
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN set -eux; \
|
||||
export ARCH=$(uname -m); \
|
||||
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm || true); \
|
||||
if [ ! -z "${WASM_VERSION}" ]; then \
|
||||
WASMVM_REPO=$(echo $WASM_VERSION | awk '{print $1}');\
|
||||
WASMVM_VERS=$(echo $WASM_VERSION | awk '{print $2}');\
|
||||
wget -O /lib/libwasmvm_muslc.a https://${WASMVM_REPO}/releases/download/${WASMVM_VERS}/libwasmvm_muslc.$(uname -m).a;\
|
||||
fi; \
|
||||
go mod download;
|
||||
# Copy entire source code (including crypto module)
|
||||
COPY . .
|
||||
|
||||
# Copy over code
|
||||
COPY . /code
|
||||
# Fix git ownership issue
|
||||
RUN git config --global --add safe.directory /code
|
||||
|
||||
# force it to use static lib (from above) not standard libgo_cosmwasm.so file
|
||||
# then log output of file /code/bin/sonrd
|
||||
# then ensure static linking
|
||||
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build \
|
||||
&& file /code/bin/snrd \
|
||||
&& echo "Ensuring binary is statically linked ..." \
|
||||
&& (file /code/bin/snrd | grep "statically linked")
|
||||
# Download WasmVM library
|
||||
RUN --mount=type=cache,target=/tmp/wasmvm \
|
||||
set -eux; \
|
||||
export ARCH=$(uname -m); \
|
||||
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | head -1 || echo ""); \
|
||||
if [ ! -z "${WASM_VERSION}" ]; then \
|
||||
WASMVM_REPO=$(echo $WASM_VERSION | awk '{print $1}'); \
|
||||
WASMVM_VERS=$(echo $WASM_VERSION | awk '{print $2}'); \
|
||||
WASMVM_FILE="libwasmvm_muslc.${ARCH}.a"; \
|
||||
if [ ! -f "/tmp/wasmvm/${WASMVM_FILE}" ]; then \
|
||||
wget -O "/tmp/wasmvm/${WASMVM_FILE}" "https://${WASMVM_REPO}/releases/download/${WASMVM_VERS}/${WASMVM_FILE}"; \
|
||||
fi; \
|
||||
cp "/tmp/wasmvm/${WASMVM_FILE}" /lib/libwasmvm_muslc.a; \
|
||||
fi
|
||||
|
||||
# Download Go modules
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go mod download
|
||||
|
||||
# Build binary with optimizations
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
set -eux; \
|
||||
VERSION=$(git describe --tags --always 2>/dev/null || echo "dev"); \
|
||||
COMMIT=$(git log -1 --format='%H' 2>/dev/null || echo "unknown"); \
|
||||
LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true \
|
||||
CGO_ENABLED=1 GOOS=linux \
|
||||
go build \
|
||||
-mod=readonly \
|
||||
-tags "netgo,ledger,muslc" \
|
||||
-ldflags "-X github.com/cosmos/cosmos-sdk/version.Name=sonr \
|
||||
-X github.com/cosmos/cosmos-sdk/version.AppName=snrd \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION} \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Commit=${COMMIT} \
|
||||
-X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \
|
||||
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-o /code/build/snrd \
|
||||
./cmd/snrd; \
|
||||
file /code/build/snrd; \
|
||||
echo "Ensuring binary is statically linked ..."; \
|
||||
(file /code/build/snrd | grep "statically linked")
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Highway service build stage
|
||||
FROM ${BASE_IMAGE} AS highway-builder
|
||||
SHELL ["/bin/sh", "-ecuxo", "pipefail"]
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
ca-certificates \
|
||||
build-base \
|
||||
git \
|
||||
linux-headers \
|
||||
bash
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
# Copy entire source code
|
||||
COPY . .
|
||||
|
||||
# Fix git ownership issue
|
||||
RUN git config --global --add safe.directory /code
|
||||
|
||||
# Download Go modules
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go mod download
|
||||
|
||||
# Build Highway binary with optimizations
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
set -eux; \
|
||||
VERSION=$(git describe --tags --always 2>/dev/null || echo "dev"); \
|
||||
COMMIT=$(git log -1 --format='%H' 2>/dev/null || echo "unknown"); \
|
||||
CGO_ENABLED=1 GOOS=linux \
|
||||
go build \
|
||||
-mod=readonly \
|
||||
-tags "netgo" \
|
||||
-ldflags "-X main.Version=${VERSION} \
|
||||
-X main.Commit=${COMMIT} \
|
||||
-w -s -linkmode=external -extldflags '-static'" \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-o /code/build/hway \
|
||||
./cmd/hway; \
|
||||
file /code/build/hway; \
|
||||
echo "Ensuring binary is statically linked ..."; \
|
||||
(file /code/build/hway | grep "statically linked")
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Highway runtime image
|
||||
FROM alpine:3.17 AS highway
|
||||
|
||||
LABEL org.opencontainers.image.title="Sonr Highway Service"
|
||||
LABEL org.opencontainers.image.source="https://github.com/sonr-io/sonr"
|
||||
|
||||
# Copy binary from builder
|
||||
COPY --from=highway-builder /code/build/hway /usr/bin/hway
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN apk add --no-cache ca-certificates wget
|
||||
|
||||
# Create non-root user
|
||||
RUN adduser -D -u 1000 highway
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /home/highway
|
||||
|
||||
# Switch to non-root user
|
||||
USER highway
|
||||
|
||||
# Health check endpoint
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget --spider -q http://localhost:8090/health || exit 1
|
||||
|
||||
# Expose Highway port
|
||||
EXPOSE 8090
|
||||
|
||||
# Set default command
|
||||
ENTRYPOINT ["/usr/bin/hway"]
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Final minimal runtime image (default target for snrd)
|
||||
FROM alpine:3.17
|
||||
|
||||
LABEL org.opencontainers.image.title="snrd"
|
||||
LABEL org.opencontainers.image.authors="diDAO <hi@didao.xyz>"
|
||||
LABEL org.opencontainers.image.source=https://github.com/sonr-io/snrd
|
||||
LABEL org.opencontainers.image.title="Sonr Daemon"
|
||||
LABEL org.opencontainers.image.source="https://github.com/sonr-io/sonr"
|
||||
|
||||
COPY --from=go-builder /code/build/sonrd /usr/bin/sonrd
|
||||
# Copy binary from build stage
|
||||
COPY --from=builder /code/build/snrd /usr/bin
|
||||
COPY --from=builder /lib/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
|
||||
COPY --from=builder /code/scripts/test_node.sh /usr/bin/testnet
|
||||
RUN chmod +x /usr/bin/testnet
|
||||
|
||||
# Set up dependencies
|
||||
ENV PACKAGES="curl make bash jq sed"
|
||||
|
||||
Reference in New Issue
Block a user