Earthly is a build automation tool that combines the best of Makefiles and Dockerfiles. It gives you repeatable, containerized builds that work the same on your laptop and in CI.
What Is Earthly?
Earthly provides a syntax that combines Dockerfile and Makefile concepts into Earthfiles. Every build step runs in a container, so builds are reproducible regardless of the host environment. No more 'works on my machine' problems.
Key Features:
- Reproducible containerized builds
- Dockerfile + Makefile hybrid syntax
- Automatic caching
- Parallel execution
- Multi-platform builds (ARM, x86)
- Works with any CI system
- Shared cache via Earthly Cloud
- Monorepo-friendly
Installation
# Install Earthly
curl -sSL https://earthly.dev/get-earthly | sh
# Verify
earthly --version
# Bootstrap (sets up BuildKit)
earthly bootstrap
Earthfile Example
# Earthfile
VERSION 0.8
# Base image for all targets
FROM node:20-alpine
WORKDIR /app
# Install dependencies (cached)
deps:
COPY package.json package-lock.json .
RUN npm ci
SAVE ARTIFACT node_modules
# Run tests
test:
FROM +deps
COPY . .
RUN npm test
# Build the app
build:
FROM +deps
COPY . .
RUN npm run build
SAVE ARTIFACT dist AS LOCAL ./dist
# Create Docker image
docker:
FROM +build
EXPOSE 3000
CMD ["node", "dist/server.js"]
SAVE IMAGE my-app:latest
# Multi-platform build
docker-multiplatform:
BUILD --platform=linux/amd64 --platform=linux/arm64 +docker
# Integration tests
integration-test:
FROM earthly/dind:alpine
COPY docker-compose.test.yml .
WITH DOCKER --compose docker-compose.test.yml
RUN npm run test:integration
END
# CI target: run everything
ci:
BUILD +test
BUILD +build
BUILD +docker
BUILD +integration-test
Running Earthly
# Run a specific target
earthly +build
# Run tests
earthly +test
# Build Docker image
earthly +docker
# Run full CI pipeline
earthly +ci
# Multi-platform build
earthly +docker-multiplatform
Python Project Earthfile
VERSION 0.8
FROM python:3.12-slim
WORKDIR /app
deps:
COPY requirements.txt .
RUN pip install -r requirements.txt
SAVE ARTIFACT /usr/local/lib/python3.12/site-packages
test:
FROM +deps
COPY . .
RUN pytest tests/ -v
lint:
FROM +deps
COPY . .
RUN ruff check .
RUN mypy src/
build:
FROM +deps
COPY . .
RUN python -m build
SAVE ARTIFACT dist/*.whl AS LOCAL ./dist/
docker:
FROM python:3.12-slim
COPY +deps/ /usr/local/lib/python3.12/site-packages
COPY . .
ENTRYPOINT ["python", "-m", "myapp"]
SAVE IMAGE myapp:latest
Monorepo Setup
# services/api/Earthfile
VERSION 0.8
IMPORT ../shared AS shared
build:
FROM node:20-alpine
COPY +shared/lib ./shared
COPY . .
RUN npm run build
# Root Earthfile
VERSION 0.8
all:
BUILD ./services/api+build
BUILD ./services/web+build
BUILD ./services/worker+build
Earthly vs Alternatives
| Feature | Earthly | Makefile | Dockerfile |
|---|---|---|---|
| Reproducible | Always | Host-dependent | Build only |
| Caching | Smart | Manual | Layer cache |
| Parallel | Built-in | -j flag | Multi-stage |
| CI agnostic | Yes | Mostly | Build only |
| Multi-platform | Native | Manual | BuildKit |
Resources
- Earthly Docs
- Earthly GitHub — 11K+ stars
- Earthfile Reference
Need to scrape web data for your build pipelines? Check out my web scraping tools on Apify — production-ready actors for Reddit, Google Maps, and more. Questions? Email me at spinov001@gmail.com
Top comments (0)