From c6bf318c5ccf3ec48f98b768c6ce60999ce36736 Mon Sep 17 00:00:00 2001 From: Harry Dam Date: Tue, 10 Sep 2024 00:00:37 -0600 Subject: [PATCH] Fix: enables CGo to allow Go to use C libs --- Dockerfile | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7f9ec22..4931907 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,32 @@ # Build stage -FROM golang:1.22 as builder +FROM golang:1.22 AS builder -# Set working directory -WORKDIR /tmp +# Set necessary environment variables +ENV CGO_ENABLED=1 +ENV GOOS=linux +ENV GOARCH=amd64 -# Install dependencies -#RUN apk add --no-cache make gcc musl-dev linux-headers git -RUN apt-get update && apt-get install -y git musl-dev make +WORKDIR /tmp -# Clean the Go module cache -RUN go clean -modcache +RUN apt-get update && apt-get install -y --no-install-recommends make gcc g++ musl-dev git && rm -rf /var/lib/apt/lists/* -# Clone the specific branch of the Sonic repository and build the application RUN git clone --depth 1 --branch v1.2.1-f https://github.com/Fantom-foundation/Sonic.git && \ cd Sonic && \ make all # Final stage -FROM alpine:latest -# Set working directory +FROM ubuntu:22.04 + WORKDIR /root/.sonic -# Install ca-certificates for HTTPS -RUN apk add --no-cache ca-certificates curl jq +# Install runtime dependencies, including glibc +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl jq && rm -rf /var/lib/apt/lists/* # Copy binaries from builder stage -COPY --from=builder /tmp/Sonic/build/sonicd /usr/local/bin/ -COPY --from=builder /tmp/Sonic/build/sonictool /usr/local/bin/ - -# Create a non-root user -RUN adduser -D -u 1000 sonic - -# Switch to non-root user -USER sonic +COPY --from=builder /tmp/Sonic/build/ /usr/local/bin -# Expose necessary ports -EXPOSE 5050 5050/udp 80 18546 18545 +# Expose Sonic's default ports (change if necessary) +EXPOSE 18545 18546 -# Set the entrypoint (default to running sonicd, but can be overridden) -ENTRYPOINT ["sonicd"] +ENTRYPOINT ["sonicd"] \ No newline at end of file