πŸ”§ DevOps

Build

Build

The process of converting source code into an executable form. Includes compiling and packaging.

Detailed Explanation

A Build is the process of converting source code into executable software artifacts. It includes several stages such as compilation, linking, dependency resolution, test execution, and packaging, and is the core of automation in modern software development.

The build process differs by language and platform. Java compiles and then packages into JAR/WAR, JavaScript does bundling and transpiling, Go produces static binaries, and Python creates wheel packages. In container environments, the Docker image is the final artifact.

Build tools handle dependency management and build automation. There are language-specific tools such as Maven/Gradle (Java), npm/yarn (JavaScript), pip/poetry (Python), and cargo (Rust), as well as general-purpose tools such as Bazel and Make.

In practice, the build is the starting point of the CI/CD pipeline. It builds and tests automatically on every code push, and on success pushes the artifact to a repository. Build time optimization, caching, and parallel builds directly affect developer productivity.

Code Example

# Dockerfile - λ©€ν‹°μŠ€ν…Œμ΄μ§€ λΉŒλ“œ 예제
# 1단계: λΉŒλ“œ ν™˜κ²½
FROM node:20-alpine AS builder

WORKDIR /app
COPY package*.json ./

# μ˜μ‘΄μ„± μ„€μΉ˜ (μΊμ‹œ ν™œμš©μ„ μœ„ν•΄ 별도 λ ˆμ΄μ–΄)
RUN npm ci --only=production

COPY . .
RUN npm run build

# 2단계: ν”„λ‘œλ•μ…˜ ν™˜κ²½ (μ΅œμ†Œ 이미지)
FROM node:20-alpine AS production

# λ³΄μ•ˆ: λΉ„λ£¨νŠΈ μ‚¬μš©μž
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nextjs -u 1001

WORKDIR /app

# λΉŒλ“œ μ•„ν‹°νŒ©νŠΈλ§Œ 볡사
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./

USER nextjs
EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=3s \
    CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1

CMD ["node", "dist/server.js"]

How It's Said in Practice

Senior: "The build takes 8 minutes, which is too long to wait on every PR. Let's apply parallel builds and caching to get it under 3 minutes."

Junior: "The Docker layer cache keeps getting invalidated, it seems."

Senior: "It's probably a COPY order issue. Copy things that change less often first, and copy package.json separately so you can use the npm install cache."

Interviewer: "What are the advantages of a Docker multi-stage build?"

Candidate: "You can separate the build environment from the runtime environment. The tools needed for building are not included in the final image, so the image size gets smaller and the attack surface shrinks, which is a security benefit."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

Reviewer: "If you use npm ci instead of npm install, it installs based on the lock file, which makes the build more deterministic."

Developer: "Right, npm ci is more suitable in a CI environment. I'll separate it from the Dockerfile for local development."

Cautions

Learn More