๐Ÿ”ง DevOps

Earthly

A container-based build automation tool

Detailed Explanation

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.

Code Example

# 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

How It's Said in Practice

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."

Cautions

Learn More