Skip to content
Open

Ci #4

Show file tree
Hide file tree
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
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Git files
.git
.gitignore

# Docker files
Dockerfile*
docker-compose.yml
.dockerignore

# Build artifacts
out/
cache/
target/

# Environment files (we'll pass these as environment variables)
.env
.env.*

# IDE files
.vscode/
.idea/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Documentation (we'll generate this fresh)
docs/

# Large library files (we'll install these in the container)
lib/

# Logs
*.log
8 changes: 7 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ jobs:
fetch-depth: 0
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Lint Solidity code
run: forge lint
- name: Deployment Dry Run
run: |
export MANAGER_ADDRESS=0x1234567890123456789012345678901234567890
script/deploy.sh --dry-run
- name: Run contract tests
run: forge test -vvv
run: forge test -vvv --summary
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ out/
# Docs
docs/

# Dotenv file
# Dotenv files
.env
docker/docker.env

# Lock files
foundry.lock
42 changes: 42 additions & 0 deletions docker/DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Docker Setup

Run everything in Docker containers.

All commands need `cd docker` first.

## Setup

```bash
cd docker
cp docker.env.example docker.env
./build-docker-images.sh
```

## Usage

```bash
cd docker

# start blockchain
docker-compose up -d anvil

# deploy
docker-compose run --rm dev script/deploy.sh

# test
docker-compose run --rm dev forge test

# interactive shell
docker-compose run --rm dev bash

# stop
docker-compose down
```

## Troubleshooting

- **"exec format error"**: Use `docker-compose run` not `exec`
- **"Port 8545 in use"**: `pkill anvil`
- **"Build failed"**: `./build-docker-images.sh clean`


41 changes: 41 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Development environment for Timeboost Contracts
# Use Ubuntu as base
FROM ubuntu:22.04

# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
git \
bash \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install Foundry
RUN curl -L https://foundry.paradigm.xyz | bash
RUN /root/.foundry/bin/foundryup

# Verify installation
RUN /root/.foundry/bin/forge --version

# Add Foundry to PATH
ENV PATH="/root/.foundry/bin:${PATH}"

# Set working directory
WORKDIR /app

# Copy project files
COPY . .

# Initialize git (needed for forge install)
RUN git init

# Install dependencies
RUN forge install

# Make scripts executable
RUN chmod +x script/deploy.sh

# Set default command
CMD ["bash"]


138 changes: 138 additions & 0 deletions docker/build-docker-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env bash
set -euo pipefail

# Build script for Timeboost Contracts Docker images
# Supports multi-architecture builds for CI and local development

usage() {
>&2 cat <<"EOF"
Usage:

build-docker-images [--image image] [--platform platform]
build-docker-images clean

Build timeboost-contracts docker images for multiple architectures.

- The script supports building all images (the default) or one specific image
- By default builds for both linux/amd64 and linux/arm64 (multi-arch)
- Use --platform to build for specific architecture only

Examples:

# build for all supported platforms
build-docker-images

# build for specific platform (CI)
build-docker-images --platform linux/amd64

# build for Apple Silicon only
build-docker-images --platform linux/arm64

# clean the build artifacts
build-docker-images clean
EOF
}

# Default values
docker_build_args=""
image=""
platform=""
clean=""

# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-i|--image)
if [[ -n "${image:-}" ]]; then
>&2 echo "Error: --image option specified multiple times"
>&2 echo ""
usage
exit 1
fi
image="$2"
shift 2
;;
-p|--platform)
if [[ -n "${platform:-}" ]]; then
>&2 echo "Error: --platform option specified multiple times"
>&2 echo ""
usage
exit 1
fi
platform="$2"
shift 2
;;
clean)
clean="true"
shift
;;
*)
>&2 echo "Error: Unknown option '$1'"
>&2 echo ""
usage
exit 1
;;
esac
done

# Handle clean command
if [[ "${clean:-}" == "true" ]]; then
echo "Cleaning Docker build artifacts..."
docker system prune -f
docker builder prune -f
echo "Clean complete!"
exit 0
fi

# Set default platform if not specified
if [[ -z "${platform:-}" ]]; then
platform="linux/amd64,linux/arm64"
fi

# Set default image if not specified
if [[ -z "${image:-}" ]]; then
image="all"
fi

echo "Building Docker images..."
echo "Image: ${image}"
echo "Platform: ${platform}"
echo ""

build_base_image() {
echo "Building base image..."

if [[ "$platform" == *","* ]]; then
echo "Multi-platform build for: ${platform}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between this and the else?

docker buildx build \
--platform "${platform}" \
--file "Dockerfile.dev" \
--tag "timeboost-contracts:latest" \
--load \
..
else
echo "Single platform build for: ${platform}"
docker buildx build \
--platform "${platform}" \
--file "Dockerfile.dev" \
--tag "timeboost-contracts:latest" \
--load \
..
fi

echo "Base image built successfully"
echo ""
}

# Build the single image (all services use the same image)
build_base_image

echo "Build complete!"
echo ""
echo "To test the images:"
echo " docker-compose up -d anvil"
echo " docker-compose run --rm dev script/deploy.sh"
56 changes: 56 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
services:
# Our main development environment
dev:
# Build the image directly
build:
context: ..
dockerfile: docker/Dockerfile.dev
image: timeboost-contracts:latest

volumes:
- ../src:/app/src # Source code
- ../script:/app/script # Deployment scripts
- ../test:/app/test # Test files
- ../lib:/app/lib # Dependencies (forge-std, openzeppelin, etc.)
- ../broadcast:/app/broadcast # Deployment transaction logs
- ../foundry.toml:/app/foundry.toml # Foundry configuration
- ../README.md:/app/README.md # Documentation

env_file:
- docker.env

# Set the working directory
working_dir: /app

# Keep the container running and allow interaction
stdin_open: true
tty: true

command: bash

depends_on:
- anvil

# Local Ethereum blockchain for testing
anvil:
# Use the same base image
image: timeboost-contracts:latest

# Command to run when container starts
command: anvil --host 0.0.0.0 --port 8545

# Expose port 8545 to your computer
ports:
- "8545:8545"

# Health check for anvil
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8545"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s

# Keep container running
stdin_open: true
tty: true
6 changes: 6 additions & 0 deletions docker/docker.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Docker environment variables for development
# Copy this file to docker.env and customize as needed
MANAGER_ADDRESS=0x1234567890123456789012345678901234567890
RPC_URL=http://anvil:8545
MNEMONIC=test test test test test test test test test test test junk
ACCOUNT_INDEX=0
Loading