We recently set up a GitHub Actions CI/CD frontend pipeline in our team and learned a lot along the way. I'm sharing the experience as a reference, hoping it helps anyone doing similar work.
Core Concepts
The key is to understand the core logic:
javascript
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM nginx:alpine AS runner
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Performance tuning should fit the specific scenario—you don't need to over-optimize every case.
In-Depth Analysis
Here are a few ways we can improve on this:
javascript
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM nginx:alpine AS runner
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This approach has been running stably in production for over half a year, so it's battle-tested.
Implementation Experience
Let's start with the basic implementation:
javascript
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM nginx:alpine AS runner
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This snippet shows the basic usage. In a real project, you'll also need to handle errors and edge cases.
Tuning Strategy
Building on that, we can optimize further:
javascript
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM nginx:alpine AS runner
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This pattern is especially handy in large projects, and it noticeably cuts maintenance cost.
Summary
- A GitHub Actions CI/CD frontend pipeline isn't a silver bullet—choose it based on your project's scale and tech stack.
- Understanding the underlying principles matters more than memorizing the API.
- Before using it in production, be sure to verify compatibility.
- In a team, conventions and documentation matter more than the technology itself.
