From 54d54c2e1afc67bc9bfeafe5f5c2b041e380a4b6 Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:07:41 -0400 Subject: [PATCH] Add GitHub Actions CI/CD and Docker Compose - ci.yml: lint + type-check + build on every push/PR to main; uploads dist artifact - docker.yml: builds and pushes image to ghcr.io/nmemmert/letter on main push and version tags; uses GHA layer cache - docker-compose.yml: `app` service runs the production nginx image on :8080; `dev` profile mounts source and runs vite dev server on :5173 Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/ci.yml | 34 +++++++++++++++++++++++ .github/workflows/docker.yml | 52 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 21 +++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker.yml create mode 100644 docker-compose.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..91fd017 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + name: Type-check & build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - run: npm ci + + - name: Lint + run: npm run lint + + - name: Type-check + build + run: npm run build + + - name: Upload dist artifact + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + retention-days: 7 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..9c4fb65 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,52 @@ +name: Docker + +on: + push: + branches: [main] + tags: ["v*"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + docker: + name: Build & push image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags & labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix=sha-,format=short + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..de556bf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + app: + build: . + image: ghcr.io/nmemmert/letter:main + ports: + - "8080:80" + restart: unless-stopped + + dev: + image: node:20-alpine + working_dir: /app + volumes: + - .:/app + - node_modules:/app/node_modules + ports: + - "5173:5173" + command: sh -c "npm install && npm run dev -- --host 0.0.0.0" + profiles: [dev] + +volumes: + node_modules: