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

Add Alpine support for Foundry binaries #8498

Closed
susruth opened this issue Jul 23, 2024 · 7 comments
Closed

Add Alpine support for Foundry binaries #8498

susruth opened this issue Jul 23, 2024 · 7 comments
Labels
A-compatibility Area: compatibility A-releases Area: releases/packaging T-feature Type: feature
Milestone

Comments

@susruth
Copy link

susruth commented Jul 23, 2024

Component

Forge, Cast, Anvil, Chisel

Describe the feature you would like

When attempting to run a Docker image that got build using Alpine, I encounter an error indicating that anvil is not found. However, using the same configuration with Ubuntu works as expected. Below are the respective Dockerfile configurations for both Alpine and Ubuntu.

Alpine Dockerfile:

FROM alpine:latest AS builder

WORKDIR /app

RUN apk update && apk add --no-cache wget

ARG TARGETARCH
RUN if [ "$TARGETARCH" = "amd64" ]; then \
    wget https://github.com/foundry-rs/foundry/releases/download/nightly-62cdea8ff9e6efef011f77e295823b5f2dbeb3a1/foundry_nightly_linux_amd64.tar.gz && \
    tar -xzf foundry_nightly_linux_amd64.tar.gz; \
    elif [ "$TARGETARCH" = "arm64" ]; then \
    wget https://github.com/foundry-rs/foundry/releases/download/nightly-62cdea8ff9e6efef011f77e295823b5f2dbeb3a1/foundry_nightly_linux_arm64.tar.gz && \
    tar -xzf foundry_nightly_linux_arm64.tar.gz; \
    else \
    echo "Unsupported architecture"; exit 1; \
    fi

FROM alpine:latest

EXPOSE 8545

WORKDIR /app

RUN apk update && apk add --no-cache curl

COPY --from=builder /app/anvil .
COPY ./cmd.sh .
COPY ./ignition/data/ .

CMD ["./cmd.sh"]

Ubuntu Dockerfile:

FROM ubuntu:latest AS builder

WORKDIR /app

RUN apt-get update && apt-get install -y wget --fix-missing --fix-broken

ARG TARGETARCH
RUN if [ "$TARGETARCH" = "amd64" ]; then \
    wget https://github.com/foundry-rs/foundry/releases/download/nightly-62cdea8ff9e6efef011f77e295823b5f2dbeb3a1/foundry_nightly_linux_amd64.tar.gz && \
    tar -xzf foundry_nightly_linux_amd64.tar.gz; \
    elif [ "$TARGETARCH" = "arm64" ]; then \
    wget https://github.com/foundry-rs/foundry/releases/download/nightly-62cdea8ff9e6efef011f77e295823b5f2dbeb3a1/foundry_nightly_linux_arm64.tar.gz && \
    tar -xzf foundry_nightly_linux_arm64.tar.gz; \
    else \
    echo "Unsupported architecture"; exit 1; \
    fi

FROM ubuntu:latest

EXPOSE 8545

WORKDIR /app

RUN apt-get update && apt-get install -y curl --fix-missing --fix-broken

COPY --from=builder /app/anvil .
COPY ./cmd.sh .
COPY ./ignition/data/ .

CMD ["./cmd.sh"]

External file cmd.sh that might be required is:

#!/bin/sh

./anvil --host 0.0.0.0 --block-time 10 &

sleep 3 

if [ -n "$CHAIN_ID" ]; then
    response=$(curl -s -X POST -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\", \"method\":\"anvil_setChainId\", \"params\":[$CHAIN_ID], \"id\":1}" http://localhost:8545)
    echo "Set chain ID response: $response"
else
    echo "CHAIN_ID is not set, default chain ID is 31337."
fi

if [ "$LIGHT" = "true" ]; then
    state_file="./lightState.json"
else
    state_file="./fullState.json"
fi

response=$(curl -s -X POST -H "Content-Type: application/json" --data-binary @$state_file http://localhost:8545)
echo "Set blockchain state response: $response"

tail -f /dev/null

Error Output

cmd.sh: line 3: ./anvil: not found

Expected Behavior

The Alpine Docker image should build and run successfully, similar to the Ubuntu image.

Additional Information

  • Alpine Version: latest
  • Ubuntu Version: latest
  • Foundry Release: nightly-62cdea8ff9e6efef011f77e295823b5f2dbeb3a1

Additional context

No response

@susruth susruth added the T-feature Type: feature label Jul 23, 2024
@zerosnacks zerosnacks added the A-releases Area: releases/packaging label Jul 23, 2024
@zerosnacks
Copy link
Member

I think this is because Alpine uses MUSL whereas Foundry has a dependency on GLIBC

A possible workaround is using the https://hub.docker.com/r/frolvlad/alpine-glibc/ image (see: https://github.com/foundry-rs/foundry/blob/master/Dockerfile)

@gnapoli23
Copy link
Contributor

gnapoli23 commented Sep 10, 2024

+1 on this, it would be very helpful to have it since it takes quite a bit to compile each crate; is there any kind of limitation behind the lack of musl targets so far? I would like to help with it, having a bit of context would be helpful.

@grandizzy
Copy link
Collaborator

@susruth @gnapoli23 we have this PR merged #8964 could you check if solves your issue? thank you

@gnapoli23
Copy link
Contributor

gnapoli23 commented Oct 1, 2024

@susruth @gnapoli23 we have this PR merged #8964 could you check if solves your issue? thank you

Confirming that it's working for me now. BTW is there a reason why #8964 uses alpine:3.18 instead of the latest stable alpine:3.20.3 version?

@grandizzy
Copy link
Collaborator

BTW is there a reason why #8964 uses alpine:3.18 instead of the latest stable alpine:3.20.3 version?

Hm, not sure if any deps on version. @DrakeEvans can you please chime in?

@grandizzy
Copy link
Collaborator

going to close this one as it is confirmed working, pls open new ticket if other issues. Thank you!

@DrakeEvans
Copy link
Contributor

DrakeEvans commented Oct 7, 2024

BTW is there a reason why #8964 uses alpine:3.18 instead of the latest stable alpine:3.20.3 version?

Hm, not sure if any deps on version. @DrakeEvans can you please chime in?

@gnapoli23 @grandizzy The initial build step was using alpine:3.18 (

FROM alpine:3.18 as build-environment
) and I wanted to keep the scope of my changes as small as possible. If we upgrade to latest we should upgrade both parts to keep build times as fast as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compatibility Area: compatibility A-releases Area: releases/packaging T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

5 participants