-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-baked Anvil+XMTPD docker image (#273)
The purpose of this image is it's usage in `libxmtp` without having to pull all the requirements. We now automatically build a `ghcr.io/xmtp/anvil-xmtpd` image that contains 2 endpoints (localhost:5050 and localhost:5051) along with the default test keys. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a GitHub Actions workflow to automate Docker image building and pushing. - Added a new Dockerfile for building an image with the Foundry framework and XMTPD Node contracts. - Created a shell script to run the Anvil tool in the background. - **Documentation** - Updated metadata labels in the Dockerfile for better maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Build pre-baked images | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker Image to GitHub Packages | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
env: | ||
DOCKER_METADATA_PR_HEAD_SHA: true | ||
outputs: | ||
digest: ${{ steps.push.outputs.digest }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
- name: Log in to the container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/xmtp/anvil-xmtpd | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=sha | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
id: push | ||
with: | ||
context: . | ||
file: ./dev/baked/Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: "FOUNDRY_VERSION=nightly-2044faec64f99a21f0e5f0094458a973612d0712" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# BUILD IMAGE -------------------------------------------------------- | ||
ARG GO_VERSION=1.22 | ||
ARG FOUNDRY_VERSION=nightly | ||
FROM golang:${GO_VERSION}-bookworm as builder | ||
|
||
WORKDIR /app | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y curl git jq && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN curl -L https://foundry.paradigm.xyz | bash && \ | ||
source ~/.bashrc && \ | ||
foundryup -v "${FOUNDRY_VERSION}" && \ | ||
cp ~/.foundry/bin/* /usr/local/bin | ||
|
||
COPY . . | ||
|
||
# It seems that anvil flushes the file to disk on shutdown and it takes a few ms to be persisted | ||
# That gives us the pkill+sleep requirement | ||
RUN dev/docker/anvil-background && \ | ||
dev/contracts/deploy-local && \ | ||
dev/register-local-node && \ | ||
dev/register-local-node-2 && \ | ||
pkill -f anvil && \ | ||
sleep 5 | ||
|
||
RUN echo "export XMTPD_CONTRACTS_NODES_ADDRESS="$(jq -r '.deployedTo' build/Nodes.json)"" >> contracts.env && \ | ||
echo "export XMTPD_CONTRACTS_MESSAGES_ADDRESS="$(jq -r '.deployedTo' build/GroupMessages.json)"" >> contracts.env && \ | ||
echo "export XMTPD_CONTRACTS_IDENTITY_UPDATES_ADDRESS="$(jq -r '.deployedTo' build/IdentityUpdates.json)"" >> contracts.env | ||
|
||
# ACTUAL IMAGE ------------------------------------------------------- | ||
|
||
FROM ghcr.io/foundry-rs/foundry | ||
|
||
LABEL maintainer="engineering@xmtp.com" | ||
LABEL source="https://github.com/xmtp/xmtpd" | ||
LABEL description="Foundry with XMTPD Node contracts and registrations" | ||
|
||
EXPOSE 8545 | ||
|
||
COPY --from=builder /app/anvil-baked-state anvil-baked-state | ||
COPY --from=builder /app/contracts.env contracts.env | ||
|
||
ENTRYPOINT ["anvil", "--state", "anvil-baked-state"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
anvil -p 7545 --dump-state $PWD/anvil-baked-state & |