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

Fix: enables CGo to allow Go to use C libs #2

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]