-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (72 loc) · 3.13 KB
/
Dockerfile
File metadata and controls
81 lines (72 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Build webapp
FROM node:24-alpine AS webapp
WORKDIR /app
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy dependency files
COPY webapp/package.json webapp/pnpm-lock.yaml ./
# Install dependencies with cache mount
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile
# Copy source and build
COPY webapp ./
RUN pnpm run build
# Build Go binary
FROM golang:1.25 AS builder
WORKDIR /src
# Copy go mod files
COPY go.mod go.sum ./
# Copy local spec module files for replace directive
COPY spec/go.mod spec/go.sum ./spec/
# Download dependencies with cache
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Copy source code and helper script
COPY . .
COPY scripts/find-wasmer-lib.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/find-wasmer-lib.sh
# Build with cache mounts and proper library path
ARG BUILDARGS
# Find and copy libwasmer.so dynamically, then build
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
# First, prepare a libwasmer.so for the build
/usr/local/bin/find-wasmer-lib.sh save && \
# Build the binary
CGO_ENABLED=1 \
go build -trimpath \
-ldflags="-w -s -X=github.com/vocdoni/davinci-node/internal.Version=$(git describe --always --tags --dirty --match='v[0-9]*' 2>/dev/null || echo dev)" \
-o davinci-sequencer $BUILDARGS ./cmd/davinci-sequencer && \
# After building, use ldd to find the correct libwasmer.so path
/usr/local/bin/find-wasmer-lib.sh save-after-build
# Final minimal image
FROM debian:bookworm-slim
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y ca-certificates libc6-dev libomp-dev openmpi-common libgomp1 && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Support for go-rapidsnark witness calculator (https://github.com/iden3/go-rapidsnark/tree/main/witness)
# Copy the helper script and library files from builder
COPY --from=builder /usr/local/bin/find-wasmer-lib.sh /usr/local/bin/
COPY --from=builder /src/libwasmer.so /src/wasmer_path.txt ./
RUN chmod +x /usr/local/bin/find-wasmer-lib.sh && \
/usr/local/bin/find-wasmer-lib.sh restore && \
rm /usr/local/bin/find-wasmer-lib.sh libwasmer.so wasmer_path.txt
# Copy binaries and webapp
COPY --from=builder /src/davinci-sequencer ./
COPY --from=webapp /app/dist ./webapp
# Create entrypoint script
RUN echo '#!/bin/sh' > entrypoint.sh && \
echo 'export SEQUENCER_API_URL=${SEQUENCER_API_URL:-http://localhost:9090}' >> entrypoint.sh && \
echo 'export BLOCK_EXPLORER_URL=${BLOCK_EXPLORER_URL:-https://sepolia.etherscan.io/address}' >> entrypoint.sh && \
echo 'if [ -f webapp/config.js ]; then' >> entrypoint.sh && \
echo ' sed -i "s|__SEQUENCER_API_URL__|${SEQUENCER_API_URL}|g" webapp/config.js' >> entrypoint.sh && \
echo ' sed -i "s|__BLOCK_EXPLORER_URL__|${BLOCK_EXPLORER_URL}|g" webapp/config.js' >> entrypoint.sh && \
echo 'fi' >> entrypoint.sh && \
echo 'exec ./davinci-sequencer "$@"' >> entrypoint.sh && \
chmod +x entrypoint.sh
EXPOSE 9090
ENTRYPOINT ["/app/entrypoint.sh"]