diff --git a/sonic.yml b/sonic.yml new file mode 100644 index 00000000..d18e86bf --- /dev/null +++ b/sonic.yml @@ -0,0 +1,29 @@ +version: "3.1" +services: + sonic: + build: + context: ./sonic + dockerfile: Dockerfile + stop_grace_period: 3m + volumes: + - "sonic:/var/sonic" + expose: + - "18544" + - "19921" + ports: + - "19921:19921" + - "19921:19921/udp" + networks: + - chains + restart: unless-stopped + labels: + - "traefik.enable=true" + - "traefik.http.middlewares.sonic-stripprefix.stripprefix.prefixes=/sonic" + - "traefik.http.services.sonic.loadbalancer.server.port=18544" + - "traefik.http.routers.sonic.entrypoints=websecure" + - "traefik.http.routers.sonic.tls.certresolver=myresolver" + - "traefik.http.routers.sonic.rule=Host(`$DOMAIN`) && PathPrefix(`/sonic`)" + - "traefik.http.routers.sonic.middlewares=sonic-stripprefix, ipwhitelist" + +volumes: + sonic: diff --git a/sonic/Dockerfile b/sonic/Dockerfile new file mode 100644 index 00000000..b8d649fb --- /dev/null +++ b/sonic/Dockerfile @@ -0,0 +1,31 @@ +# Running Sonic in Docker is Experimental - not recommended for production use! + +# Example of usage: +# docker build -t sonic . +# docker run --name sonic1 --entrypoint sonictool sonic --datadir=/var/sonic genesis fake 1 +# docker run --volumes-from sonic1 -p 5050:5050 -p 5050:5050/udp -p 18545:18545 sonic --fakenet 1/1 --http --http.addr=0.0.0.0 + +FROM golang:1.22 as builder + +RUN apt-get update && apt-get install -y git musl-dev make + +RUN cd /go && git clone https://github.com/Fantom-foundation/Sonic.git && git fetch --tags && git checkout -b v2.0.1 tags/v2.0.1 + +WORKDIR /go/Sonic + +ARG GOPROXY +RUN go mod download +RUN make all + +FROM golang:1.22 + +COPY --from=builder /go/Sonic/build/sonicd /usr/local/bin/ +COPY --from=builder /go/Sonic/build/sonictool /usr/local/bin/ + +COPY ./entrypoint.sh /entrypoint.sh + +EXPOSE 18545 18546 5050 5050/udp + +VOLUME /var/sonic + +ENTRYPOINT ["bash", "entrypoint.sh"] \ No newline at end of file diff --git a/sonic/entrypoint.sh b/sonic/entrypoint.sh new file mode 100644 index 00000000..dec2292f --- /dev/null +++ b/sonic/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ ! -f /var/sonic/initialized ]; then + echo "Initializing Sonic..." + + # Add your initialization commands here + # Example: + # mkdir -p /var/sonic/data + # touch /var/sonic/config.json + + wget https://genesis.soniclabs.com/sonic-mainnet/genesis/sonic.g.md5 + GOMEMLIMIT=50GiB sonictool --datadir /var/sonic --cache 12000 genesis sonic.g.md5 + rm sonic.g + + # Create the file to mark initialization + touch /var/sonic/initialized + + echo "Initialization complete." +else + echo "Sonic is already initialized." +fi + +touch /var/sonic/initialized + +exec sonicd --datadir /var/sonic "$@"