Skip to content
Latchkey

CI/CD for Fastify with GitHub Actions

A fast pipeline for your high-throughput Fastify API.

Fastify is a low-overhead Node web framework. Its pipeline is a standard Node API flow: install, type-check, test, build, deploy. This recipe runs the test suite and builds a container image for deploy.

What the pipeline does

  • install deps with npm ci
  • lint with eslint
  • type-check with tsc
  • run tests with node --test or tap
  • build and push a Docker image

The workflow

This builds the app, then builds and pushes a Docker image to GHCR on main. Adapt the test command to tap, vitest, or node:test.

.github/workflows/ci.yml
name: CI
on:
  push:
    branches: [main]
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm run lint --if-present
      - run: npx tsc --noEmit --if-present
      - run: npm test
      - run: npm run build --if-present
  docker:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    permissions:
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v6
        with:
          push: true
          tags: ghcr.io/${{ github.repository }}:latest

Caching and speed

cache: npm covers installs and docker/build-push-action supports GitHub Actions cache via cache-from and cache-to for layer reuse. Image builds are the slow step; cheaper managed runners such as Latchkey (around 69% cheaper than GitHub-hosted) cut build time and auto-retry transient registry pushes.

Deploying

Pull the GHCR image on your platform: ECS, Cloud Run, Fly.io, or Kubernetes. For a non-container deploy, run npm ci --omit=dev on the host and start with node dist/server.js behind a process manager and a reverse proxy.

Key takeaways

  • Fastify follows a standard Node API pipeline.
  • Use Actions cache with build-push-action for Docker layers.
  • Deploy the GHCR image or a Node bundle.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →