Skip to content
Closed
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
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build artifacts
bin/
*.deb
*.rpm

# Test data and mocks
ci/e2e/resources/
cmd/convertor/testingresources/mocks/

# Documentation
docs/
*.md
!README.md

# Git
.git/
.gitignore

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

# OS files
.DS_Store
Thumbs.db

# Temporary files
*.tmp
*.temp
/tmp/
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Check
on:
workflow_dispatch:
push:
branches:
- main
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-basic.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI | Basic
on:
workflow_dispatch:
workflow_call:
inputs:
image-tag:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-build-image.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI | Build Image
on:
workflow_dispatch:
workflow_call:
inputs:
commit-hash:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI | E2E
on:
workflow_dispatch:
workflow_call:
inputs:
commit-hash:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Unit Test
on:
workflow_dispatch:
push:
branches:
- main
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI
on:
workflow_dispatch:
push:
branches:
- main
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bin/
.vscode
vendor/
tmp_conv/
tmp/
tmp/
*.deb
127 changes: 127 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Development Guide for Claude

This document provides development guidance for working with the accelerated-container-image project.

## Building

### Production Build (Linux)
The project is designed to run on Linux. Use the Makefile for production builds:

```bash
# Build all binaries
make binaries

# Build specific binary
make bin/overlaybd-snapshotter

# Clean build artifacts
make clean
```

### Development Build (macOS)
For development and testing on macOS, you can build with Linux target:

```bash
# Build for Linux from macOS
GOOS=linux go build -o bin/overlaybd-snapshotter ./cmd/overlaybd-snapshotter/

# Build other components
GOOS=linux go build -o bin/ctr ./cmd/ctr/
GOOS=linux go build -o bin/convertor ./cmd/convertor/
```

**Note**: The binaries won't run on macOS due to Linux-specific dependencies (overlayFS, disk quotas, etc.), but this is useful for compilation testing and development.

## Testing

### Unit Tests
```bash
# Run tests (requires root on Linux)
make test

# Run specific package tests
go test ./pkg/snapshot/...
go test ./internal/log/...
```

### Syntax Validation
```bash
# Check syntax without building
go list ./cmd/... ./pkg/... ./internal/...

# Format code
go fmt ./...

# Vet code
go vet ./...
```

## Code Formatting

The project uses standard Go formatting:

```bash
# Format all Go files
go fmt ./...

# Check formatting
gofmt -l .

# Fix imports
go mod tidy
```

## Linting

```bash
# Run go vet
go vet ./...

# Check for common issues
go mod verify
```

## Platform-Specific Notes

### Linux-Only Components
- `pkg/snapshot/diskquota/` - Project quota management
- OverlayFS mounting functionality
- Block device operations

### Cross-Platform Components
- gRPC service interfaces
- Logging and metrics
- Configuration parsing
- Basic snapshot logic

## Development Workflow

1. **Make changes** to Go files
2. **Test compilation**: `GOOS=linux go build ./cmd/overlaybd-snapshotter/`
3. **Format code**: `go fmt ./...`
4. **Validate**: `go vet ./...`
5. **Test on Linux** (if available): `make test`

## Package Structure

```
cmd/
├── overlaybd-snapshotter/ # Main snapshotter service
├── ctr/ # Container runtime tool
└── convertor/ # Image conversion tool

pkg/
├── snapshot/ # Core snapshotter implementation
├── metrics/ # Prometheus metrics
└── utils/ # Utility functions

internal/
└── log/ # Internal logging utilities
```

## Tips

- **macOS Development**: Use `GOOS=linux` for all builds
- **Testing**: Full testing requires Linux environment
- **Dependencies**: Run `go mod tidy` after adding new imports
- **Build Errors**: Check build constraints (`//go:build linux`) if compilation fails
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
SN_DESTDIR=/opt/overlaybd/snapshotter
SN_CFGDIR=/etc/overlaybd-snapshotter

# versioning
RELEASE_VERSION?=1.3.0-runloop
RELEASE_NUM?=1
OBD_VERSION?=1.0.15
GO_VERSION?=1.23

# command
COMMANDS=overlaybd-snapshotter ctr convertor
BINARIES=$(addprefix bin/,$(COMMANDS))
Expand Down Expand Up @@ -32,3 +38,43 @@ test: ## run tests that require root

clean:
@rm -rf ./bin
@rm -f *.deb

deb-amd64: ## build .deb package for amd64
@echo "Building .deb package for amd64..."
@mkdir -p /tmp/.buildx-cache
@DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/amd64 \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg RELEASE_NUM=$(RELEASE_NUM) \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache \
-f ci/build_image/Dockerfile.build_deb \
--target deb-only \
-t aci-builder-amd64 \
--load .
@docker run --rm -v $(PWD):/output aci-builder-amd64 \
sh -c "cp /app/overlaybd-snapshotter_*.deb /output/"

deb-arm64: ## build .deb package for arm64
@echo "Building .deb package for arm64..."
@mkdir -p /tmp/.buildx-cache
@DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64 \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg RELEASE_NUM=$(RELEASE_NUM) \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache \
-f ci/build_image/Dockerfile.build_deb \
--target deb-only \
-t aci-builder-arm64 \
--load .
@docker run --rm -v $(PWD):/output aci-builder-arm64 \
sh -c "cp /app/overlaybd-snapshotter_*.deb /output/"

deb: deb-amd64 deb-arm64 ## build .deb packages for both amd64 and arm64

help: ## show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
55 changes: 38 additions & 17 deletions ci/build_image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ ARG GO_VERSION
ARG GO_IMAGE=golang:${GO_VERSION}
FROM --platform=${BUILDPLATFORM} ${GO_IMAGE} AS builder
WORKDIR /src
COPY . .
# Copy go.mod and go.sum first for better layer caching
COPY go.mod go.sum ./
ENV DEBIAN_FRONTEND=noninteractive
RUN echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list && \
apt update && \
apt install -y nfpm && \
go mod tidy
go mod download
# Copy the rest of the source code
COPY . .

ARG TARGETOS TARGETARCH
ENV GOOS=${TARGETOS}
Expand All @@ -37,29 +40,47 @@ RUN make && \
nfpm pkg --packager rpm --target /tmp/

# build image
FROM ubuntu:22.04 AS release
FROM ubuntu:24.04 AS release
ARG OBD_VERSION
ARG RELEASE_VERSION
SHELL ["/bin/bash", "-c"]
WORKDIR /app
COPY --from=builder /tmp/overlaybd-snapshotter_${RELEASE_VERSION}_amd64.deb .
COPY ./ci/build_image/start_services.sh .

# Install system dependencies first for better caching
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Add Docker repository and install Docker components
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io && \
apt-get install -y libnl-3-200 libnl-genl-3-200 libcurl4-openssl-dev libaio-dev wget less kmod && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
wget https://github.com/containerd/overlaybd/releases/download/v${OBD_VERSION}/overlaybd-${OBD_VERSION}-20240717.b5b704b.ubuntu1.22.04.x86_64.deb && \
dpkg -i overlaybd-${OBD_VERSION}-20240717.b5b704b.ubuntu1.22.04.x86_64.deb && \
dpkg -i overlaybd-snapshotter_${RELEASE_VERSION}_amd64.deb && \
sed -i 's/"autoRemoveDev": false,/"autoRemoveDev": true,/g' /etc/overlaybd-snapshotter/config.json && \
cat /etc/overlaybd-snapshotter/config.json && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Install runtime dependencies
RUN apt-get update && apt-get install -y libnl-3-200 libnl-genl-3-200 libcurl4-openssl-dev libaio-dev wget less kmod && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Download and install overlaybd (architecture-specific)
RUN case "$(dpkg --print-architecture)" in \
amd64) OBD_ARCH=x86_64 ;; \
arm64) OBD_ARCH=aarch64 ;; \
*) echo "Unsupported architecture: $(dpkg --print-architecture)"; exit 1 ;; \
esac && \
wget https://github.com/containerd/overlaybd/releases/download/v${OBD_VERSION}/overlaybd-${OBD_VERSION}-20250610.859f8c8.ubuntu1.24.04.${OBD_ARCH}.deb && \
dpkg -i overlaybd-${OBD_VERSION}-20250610.859f8c8.ubuntu1.24.04.${OBD_ARCH}.deb && \
rm overlaybd-${OBD_VERSION}-20250610.859f8c8.ubuntu1.24.04.${OBD_ARCH}.deb

# Copy and install the built snapshotter package
COPY --from=builder /tmp/overlaybd-snapshotter_*.deb .
RUN dpkg -i overlaybd-snapshotter_*.deb

# Configure the snapshotter
RUN sed -i 's/"autoRemoveDev": false,/"autoRemoveDev": true,/g' /etc/overlaybd-snapshotter/config.json && \
mkdir -p /etc/containerd/ && \
echo -e '[proxy_plugins.overlaybd]\n\ttype = "snapshot"\n\taddress = "/run/overlaybd-snapshotter/overlaybd.sock"' | tee -a /etc/containerd/config.toml && \
cat /etc/containerd/config.toml && \
chmod +x /app/start_services.sh && \
cat /app/start_services.sh
echo -e '[proxy_plugins.overlaybd]\n\ttype = "snapshot"\n\taddress = "/run/overlaybd-snapshotter/overlaybd.sock"' | tee -a /etc/containerd/config.toml

# Copy startup script (only needed for running, not for deb extraction)
COPY ./ci/build_image/start_services.sh .
RUN chmod +x /app/start_services.sh
45 changes: 45 additions & 0 deletions ci/build_image/Dockerfile.build_deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright The Accelerated Container Image Authors

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# build overlaybd-snapshotter
ARG GO_VERSION
ARG GO_IMAGE=golang:${GO_VERSION}
FROM --platform=${BUILDPLATFORM} ${GO_IMAGE} AS builder
WORKDIR /src
# Copy go.mod and go.sum first for better layer caching
COPY go.mod go.sum ./
ENV DEBIAN_FRONTEND=noninteractive
RUN echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list && \
apt update && \
apt install -y nfpm && \
go mod download
# Copy the rest of the source code
COPY . .

ARG TARGETOS TARGETARCH
ENV GOOS=${TARGETOS}
ENV GOARCH=${TARGETARCH}
ARG RELEASE_VERSION
ENV SEMVER=${RELEASE_VERSION}
ARG RELEASE_NUM
ENV RELEASE=${RELEASE_NUM}
ENV COMMIT_ID="${RELEASE_VERSION}_${RELEASE_NUM}"
RUN make && \
nfpm pkg --packager deb --target /tmp/ && \
nfpm pkg --packager rpm --target /tmp/

# minimal image for deb extraction
FROM ubuntu:24.04 AS deb-only
WORKDIR /app
COPY --from=builder /tmp/overlaybd-snapshotter_*.deb .
Loading
Loading