Earthly
A container-based build automation tool
A container-based build automation tool
Earthly is a container-based build automation tool that combines the strengths of Dockerfile and Makefile. By running builds inside containers, it solves the "it works on my machine" problem and guarantees identical results locally and in CI environments.
It uses a configuration file called an Earthfile. Its syntax is similar to Dockerfile, but it structures build steps with the concept of targets. Each target can have dependencies, so complex build workflows can be expressed declaratively.
A powerful caching system is its hallmark. If the input files have not changed, it reuses the previous build result, and remote caching lets team members share build caches, significantly reducing CI build time.
It is especially useful in monorepo environments. You can manage the builds of multiple services in a single Earthfile and selectively build only the parts that changed. It integrates with all CI systems, including GitHub Actions and GitLab CI.
# Earthfile - ๋ชจ๋
ธ๋ ํฌ ๋น๋ ์ค์
VERSION 0.7
# ๊ณตํต ๋ฒ ์ด์ค ์ด๋ฏธ์ง
base:
FROM node:20-alpine
WORKDIR /app
RUN apk add --no-cache python3 make g++
# ํ๋ก ํธ์๋ ๋น๋
frontend:
FROM +base
COPY frontend/package*.json ./frontend/
RUN cd frontend && npm ci
COPY frontend ./frontend
RUN cd frontend && npm run build
SAVE ARTIFACT frontend/dist AS LOCAL ./frontend/dist
# ๋ฐฑ์๋ ๋น๋
backend:
FROM +base
COPY backend/package*.json ./backend/
RUN cd backend && npm ci --only=production
COPY backend ./backend
RUN cd backend && npm run build
SAVE ARTIFACT backend/dist AS LOCAL ./backend/dist
# ํตํฉ ํ
์คํธ
integration-test:
FROM +base
COPY +frontend/dist ./frontend/dist
COPY +backend/dist ./backend/dist
COPY tests ./tests
WITH DOCKER --compose docker-compose.test.yml
RUN npm run test:integration
END
# Docker ์ด๋ฏธ์ง ๋น๋
docker:
FROM node:20-alpine
WORKDIR /app
COPY +backend/dist ./dist
COPY +backend/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/main.js"]
SAVE IMAGE --push myregistry/myapp:latest
# ์ ์ฒด ๋น๋
all:
BUILD +frontend
BUILD +backend
BUILD +integration-test
BUILD +docker
Senior: "The CI build takes 20 minutes. If we switch to Earthly and set up a remote cache, it should get a lot faster."
Junior: "Can we use the cache built locally in CI as well?"
Senior: "Yes, if you store the cache in S3 or GCS, everyone on the team shares it. Except for the first build, it finishes within 5 minutes."
Interviewer: "What strategies did you use to reduce build time in a monorepo?"
Candidate: "I adopted Earthly so the whole team shared the build cache, and I built only the services that changed. The average build time dropped from 15 minutes to 3 minutes."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "This target's COPY is too broad. If you copy only src, the npm install cache will be hit when package.json hasn't changed."
Developer: "Ah, it's the same principle as Dockerfile optimization. I'll fix it."