Skip to content

Commit 21b30fd

Browse files
authored
Feat/add docker compose (#128)
* add docker-compose.yaml * update * update cmd * update * add promethues * add grafana * multiarch * revert dockerfile * format dockerfile * format * format * format * remove platform * typo
1 parent 3ae1566 commit 21b30fd

File tree

13 files changed

+15755
-6
lines changed

13 files changed

+15755
-6
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ jobs:
4444
username: ${{ secrets.DOCKERHUB_USERNAME }}
4545
password: ${{ secrets.DOCKERHUB_TOKEN }}
4646

47-
- name: Build docker image
47+
- name: Build and push multi-arch docker image
4848
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
4949
with:
5050
context: .
5151
file: Dockerfile
52-
# push: ${{ startsWith(github.ref, 'refs/tags/') }}
52+
platforms: linux/amd64,linux/arm64
5353
push: true
5454
tags: ${{ steps.meta.outputs.tags }}
5555
labels: ${{ steps.meta.outputs.labels }}
56-
# cache-from: type=gha,scope=${{ github.workflow }}
57-
# cache-to: type=gha,scope=${{ github.workflow }}
56+
cache-from: type=gha,scope=${{ github.workflow }}
57+
cache-to: type=gha,scope=${{ github.workflow }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ target/
2222

2323
.vscode/
2424

25-
.idea/
25+
.idea/
26+
docker-compose/grafana_data/
27+
docker-compose/l2reth/
28+
docker-compose/prometheus_data/

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ COPY --from=builder /app-target/release/rollup-node /bin/
3232
EXPOSE 30303 30303/udp 9001 8545 8546
3333

3434
ENTRYPOINT ["rollup-node"]
35-

MULTIARCH_BUILD.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Multi-Architecture Docker Image Build Guide
2+
3+
## Overview
4+
5+
This project now supports building multi-architecture Docker images for both `linux/amd64` and `linux/arm64` platforms.
6+
7+
## Prerequisites
8+
9+
1. Docker version >= 19.03
10+
2. Docker Buildx (usually included in newer Docker versions)
11+
12+
## Quick Start
13+
14+
### 1. Setup Docker Buildx
15+
16+
Before first use, you need to set up the buildx builder:
17+
18+
```bash
19+
make docker-setup-buildx
20+
```
21+
22+
Or execute manually:
23+
24+
```bash
25+
docker buildx create --name multiarch --driver docker-container --bootstrap --use
26+
```
27+
28+
### 2. Build Multi-Architecture Images
29+
30+
#### Local Build (without pushing to registry)
31+
32+
```bash
33+
make docker-multiarch
34+
```
35+
36+
This will build images for both `linux/amd64` and `linux/arm64` architectures, but will only save them in the local build cache.
37+
38+
39+
### 3. Single Architecture Build (Traditional Way)
40+
41+
If you only need to build an image for the current platform:
42+
43+
```bash
44+
make docker
45+
```
46+
47+
## Technical Details
48+
49+
### Dockerfile Modifications
50+
51+
1. **Multi-platform Base Images**: Uses `--platform=$BUILDPLATFORM` to ensure base images support multi-architecture
52+
2. **Cross-compilation Support**:
53+
- Added `gcc-aarch64-linux-gnu` cross-compiler for ARM64
54+
- Configured corresponding Rust targets and linkers
55+
3. **Conditional Building**: Selects the correct compilation target based on `$TARGETPLATFORM` environment variable
56+
4. **Smart Binary Copying**: Copies the correct binary file based on the target platform
57+
58+
### Supported Platforms
59+
60+
- `linux/amd64` (x86_64)
61+
- `linux/arm64` (aarch64)
62+
63+
### Build Time Optimization
64+
65+
- Uses `cargo-chef` to cache dependency builds
66+
- Leverages Docker multi-stage builds to reduce final image size
67+
- BuildKit cache mechanism improves repeated build performance
68+
69+
## Troubleshooting
70+
71+
### Issue: buildx not available
72+
73+
**Solution**: Update Docker to the latest version, or manually install buildx:
74+
75+
```bash
76+
# Check if buildx is available
77+
docker buildx version
78+
79+
# If not available, you can install it with:
80+
docker buildx install
81+
```
82+
83+
### Issue: Cross-compilation failures
84+
85+
**Solution**: Ensure your system has sufficient memory and storage space, as cross-compilation typically requires more resources.
86+
87+
### Issue: ARM64 builds are slow on Apple Silicon Macs
88+
89+
**Solution**: This is normal behavior, as even on ARM64 hosts, Docker still needs to emulate the Linux ARM64 environment.
90+
91+
## Verifying Build Results
92+
93+
After the build is complete, you can check if the image contains multiple architectures:
94+
95+
```bash
96+
docker buildx imagetools inspect scrolltech/rollup-node:latest
97+
```
98+
99+
## Usage Recommendations
100+
101+
1. **Development Phase**: Use `make docker` for fast single-architecture builds
102+
2. **Testing Phase**: Use `make docker-multiarch` for multi-architecture validation
103+
3. **Release Phase**: GitHub Actions will automatically build and push multi-architecture images when you create a release or push a tag
104+
105+
## GitHub Actions Integration
106+
107+
The project includes a GitHub Actions workflow (`.github/workflows/release.yml`) that automatically builds and pushes multi-architecture images to Docker Hub when:
108+
109+
- A new tag is pushed
110+
- A GitHub release is published
111+
112+
### Workflow Features
113+
114+
- **Multi-platform builds**: Automatically builds for `linux/amd64` and `linux/arm64`
115+
- **Smart caching**: Uses GitHub Actions cache to speed up builds
116+
- **Automatic tagging**: Tags images based on Git tags and releases
117+
- **Secure authentication**: Uses Docker Hub credentials stored in GitHub Secrets
118+
119+
### Required Secrets
120+
121+
Make sure the following secrets are configured in your GitHub repository:
122+
123+
- `DOCKERHUB_USERNAME`: Your Docker Hub username
124+
- `DOCKERHUB_TOKEN`: Your Docker Hub access token
125+
126+
## Performance Notes

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,11 @@ pr: lint test docs
8080
.PHONY: docker
8181
docker:
8282
docker build -t scrolltech/rollup-node:latest . -f Dockerfile
83+
84+
.PHONY: docker-multiarch
85+
docker-multiarch:
86+
docker buildx build --platform linux/amd64,linux/arm64 -t scrolltech/rollup-node:latest . -f Dockerfile
87+
88+
.PHONY: docker-setup-buildx
89+
docker-setup-buildx:
90+
docker buildx create --name multiarch --driver docker-container --bootstrap --use || docker buildx use multiarch

docker-compose/docker-compose.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '3'
2+
3+
services:
4+
rollup-node:
5+
image: scrolltech/rollup-node:v0.0.1-rc9
6+
container_name: rollup-node
7+
entrypoint: ["sh", "-c"]
8+
command: >
9+
'
10+
if [ "$${ENV:-}" = "dev" ]; then
11+
exec rollup-node node --chain dev --datadir=/l2reth --metrics=0.0.0.0:6060 --disable-discovery --http --http.addr=0.0.0.0 --http.port=8545 --http.corsdomain "*" --http.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --log.stdout.format log-fmt -vvv --sequencer.enabled --sequencer.block-time 250 --sequencer.payload-building-duration 230 --txpool.pending-max-count=1000000 --builder.gaslimit=10000000000 --rpc.max-connections=5000
12+
elif [ "$${ENV:-}" = "sepolia" ]; then
13+
exec rollup-node node --chain scroll-sepolia --datadir=/l2reth --metrics=0.0.0.0:6060 --disable-discovery --http --http.addr=0.0.0.0 --http.port=8545 --http.corsdomain "*" --http.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --log.stdout.format log-fmt -vvv --l1.url http://l1geth-rpc.sepolia.scroll.tech:8545/l1 --l1.cups 10000 --network.bridge --scroll-wire.enabled --optimistic-sync --builder.gaslimit 20000000 --trusted-peers enode://29cee709c400533ae038a875b9ca975c8abef9eade956dcf3585e940acd5c0ae916968f514bd37d1278775aad1b7db30f7032a70202a87fd7365bd8de3c9f5fc@44.242.39.33:30303
14+
elif [ "$${ENV:-}" = "mainnet" ]; then
15+
exec rollup-node node --chain scroll --datadir=/l2reth --metrics=0.0.0.0:6060 --disable-discovery --http --http.addr=0.0.0.0 --http.port=8545 --http.corsdomain "*" --http.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,miner,mev --log.stdout.format log-fmt -vvv --l1.url http://l1geth-rpc.mainnet.scroll.tech:8545/l1 --l1.cups 10000 --network.bridge --scroll-wire.enabled --optimistic-sync --builder.gaslimit 30000000
16+
fi
17+
'
18+
environment:
19+
- ENV=${ENV:-dev}
20+
ports:
21+
- "8545:8545" # JSON-RPC
22+
- "8546:8546" # WebSocket
23+
- "6060:6060" # Metrics
24+
volumes:
25+
- ./l2reth:/l2reth
26+
networks:
27+
- scroll-network
28+
29+
prometheus:
30+
image: prom/prometheus:latest
31+
container_name: prometheus
32+
ports:
33+
- "19090:9090" # Prometheus Web UI
34+
volumes:
35+
- ./resource/prometheus.yml:/etc/prometheus/prometheus.yml:ro
36+
- ./prometheus_data:/prometheus
37+
command:
38+
- '--config.file=/etc/prometheus/prometheus.yml'
39+
- '--storage.tsdb.path=/prometheus'
40+
- '--storage.tsdb.retention.time=1d'
41+
- '--storage.tsdb.retention.size=512MB'
42+
- '--storage.tsdb.wal-compression'
43+
- '--web.console.libraries=/etc/prometheus/console_libraries'
44+
- '--web.console.templates=/etc/prometheus/consoles'
45+
- '--web.enable-lifecycle'
46+
networks:
47+
- scroll-network
48+
depends_on:
49+
- rollup-node
50+
51+
grafana:
52+
image: grafana/grafana:latest
53+
container_name: grafana
54+
ports:
55+
- "13000:3000" # Grafana Web UI
56+
volumes:
57+
- ./resource/grafana-datasource.yml:/config/datasources/datasource.yml:ro
58+
- ./resource/grafana-dashboard-providers.yml:/config/dashboards/dashboard-providers.yml:ro
59+
- ./resource/dashboards:/dashboards:ro
60+
- ./grafana_data:/var/lib/grafana
61+
environment:
62+
- GF_AUTH_ANONYMOUS_ENABLED=true
63+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
64+
- GF_AUTH_ANONYMOUS_ORG_NAME=Main Org.
65+
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/dashboards/overview.json
66+
- GF_PATHS_PROVISIONING=/config
67+
networks:
68+
- scroll-network
69+
depends_on:
70+
- prometheus
71+
72+
networks:
73+
scroll-network:
74+
driver: bridge

0 commit comments

Comments
 (0)