diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5250b4b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +node_modules +server/node_modules +dist +secrets +.git +.claude +.env* +.gh-*.json +*.log diff --git a/.env.example b/.env.example index 9c87058..2f8f2eb 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,13 @@ -# Copy this file to secrets/.env and fill in your own values. -# secrets/ is gitignored, so real values never leave your machine. +# For running WITHOUT Docker (npm run dev / npm start): copy this file to +# secrets/.env and fill in your own values. secrets/ is gitignored. +# Docker does NOT read this file; set the same values in docker-compose.yml. VITE_NAME=Your Name -VITE_LOCATION=City, Country VITE_EMAIL=you@example.com VITE_GITHUB_USER=your-github-username VITE_LINKEDIN=https://www.linkedin.com/in/your-profile -VITE_CV_URL=/CV/Bob-CV.pdf +VITE_CV_URL=/CV/your-cv.pdf +VITE_UNIVERSITY=Your University +# Demo mode: leave VITE_EMAIL, VITE_LINKEDIN and VITE_CV_URL empty to hide those buttons. # Server-side only (server/index.js). Deliberately not prefixed with VITE_, # so Vite never inlines these into the browser bundle. @@ -14,7 +16,7 @@ VITE_CV_URL=/CV/Bob-CV.pdf # only thing that ever sees it now, but keep it minimal-scope regardless. GITHUB_TOKEN= # Exact origin(s) allowed to call /api/* (your deployed domain). -ALLOWED_ORIGIN=https://mudabbir.co.uk +ALLOWED_ORIGIN=https://example.com PORT=3001 # Encryption in transit. Pick ONE: @@ -23,3 +25,4 @@ PORT=3001 # TLS_KEY=/etc/letsencrypt/live/example.com/privkey.pem # b) Behind a TLS reverse proxy: redirect any plain-HTTP request to HTTPS. # FORCE_HTTPS=true + diff --git a/.gitignore b/.gitignore index 43ce681..a6d6fd9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,12 @@ public/CV/* .claude/ .gh-*.json scripts/diff-tracker.mjs + +# Real values for the container (compose merges the override file in) +docker-compose.override.yml +/.env + +# Screenshot capture: cloned source for git-based projects, and raw hand-taken shots +# (the processed images in public/images/projects/ are kept) +.capture-work/ +scripts/capture/manual/*/ diff --git a/DEPLOY.md b/DEPLOY.md index 61933b8..3683255 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -1,20 +1,31 @@ # Deploying +## Where the settings live +| Run mode | Name, email, links, GitHub token come from | +|---|---| +| Without Docker (`npm run dev`, `npm start`) | `secrets/.env` (copy `.env.example`) | +| Docker | the `environment:` block in `docker-compose.yml` only | + +Everything else (About text, experience, projects, skills...) is in `src/data/*.json`. + ## Adding project images 1. Copy the files into `public/images/projects/`. -2. Add the filenames under the project's id in `src/project-images.json`. +2. Add the filenames to that project's `images` list in `src/data/projects.json`. Several filenames = carousel. -## First-time server setup -1. `git clone` the repo, then create `secrets/.env` from `.env.example` - (set `VITE_*` values, `GITHUB_TOKEN` (read-only PAT), `ALLOWED_ORIGIN`, and - either `TLS_CERT`/`TLS_KEY` or `FORCE_HTTPS=true` behind a TLS proxy). -2. Put your CV at `public/CV/` (gitignored, so copy it over manually). -3. `npm run deploy` — installs, builds, and starts the server (default port 3001). +## Docker +``` +docker compose up -d --build # or: npm run docker +``` +The container is non-root, read-only, capability-less and resource-capped, and bound +to 127.0.0.1 (put a TLS proxy in front, or set `TLS_CERT`/`TLS_KEY` / `FORCE_HTTPS`). +Values are passed at run time, so the same image works for any identity. Keep the +committed compose file generic and put real values in a gitignored +`docker-compose.override.yml`, or edit the environment block directly. +To ship a CV, set `VITE_CV_URL` and uncomment the `volumes:` line (the CV is never baked in). -## Updating +## Without Docker ``` -git pull && npm run setup && npm run build +npm run deploy # install, build, start on :3001 ``` -then restart the process (systemd/pm2). The token lives only in `secrets/.env` -and is only ever used by `server/index.js`; the browser never sees it. +Update with `git pull && npm run setup && npm run build`, then restart the process. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7be3c8b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Stage 1: build the static site. Nothing personal is baked in: name, email and +# links are read at start-up from `docker run -e VITE_...` (see server/index.js). +FROM node:22-alpine AS build +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +# Never ship a CV inside the image; mount it at run time (see scripts/start.mjs). +RUN find public/CV -type f ! -name README.txt -delete +RUN npm run build + +# Stage 2: tiny runtime. Only the server's prod deps + built site, non-root user. +FROM node:22-alpine +ENV NODE_ENV=production +WORKDIR /app +COPY server/package*.json server/ +RUN npm ci --omit=dev --prefix server && npm cache clean --force +COPY server server +COPY --from=build /app/dist dist +USER node +EXPOSE 3001 +# Everything is supplied with `docker run -e` / --env-file, never baked in: +# VITE_NAME, VITE_EMAIL, VITE_GITHUB_USER, VITE_LINKEDIN, VITE_CV_URL, VITE_UNIVERSITY +# GITHUB_TOKEN, ALLOWED_ORIGIN, FORCE_HTTPS, PORT +HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO /dev/null --header "X-Forwarded-Proto: https" http://127.0.0.1:3001/ || exit 1 +CMD ["node", "server/index.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..df32465 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +# Container deployment: docker compose up -d --build (or: npm run docker) +# +# Inside the container the site reads ONLY the values below. secrets/ is never +# copied into the image (.dockerignore), so nothing personal lives in it. +# Running without Docker (npm run dev / npm start) reads secrets/.env instead. +# +# Edit the placeholders here, or keep this file generic and put your real +# values in a gitignored docker-compose.override.yml (compose merges it in +# automatically) or in a root .env file (compose substitutes ${VARS} from it). +services: + portfolio: + build: . + image: portfolio + container_name: portfolio + restart: unless-stopped + ports: + # Localhost only; put a TLS reverse proxy in front for public access. + - "${BIND:-127.0.0.1}:${HOST_PORT:-3001}:3001" + environment: + VITE_NAME: "${VITE_NAME:-Your Name}" + VITE_EMAIL: "${VITE_EMAIL:-}" # empty hides the email button + VITE_GITHUB_USER: "${VITE_GITHUB_USER:-your-github-username}" + VITE_LINKEDIN: "${VITE_LINKEDIN:-}" # empty hides the LinkedIn button + VITE_UNIVERSITY: "${VITE_UNIVERSITY:-Your University}" + VITE_CV_URL: "${VITE_CV_URL:-}" # e.g. /CV/your-cv.pdf; empty hides CV buttons + GITHUB_TOKEN: "${GITHUB_TOKEN:-}" # read-only PAT; empty disables the contribution graph + ALLOWED_ORIGIN: "${ALLOWED_ORIGIN:-http://localhost:3001}" + FORCE_HTTPS: "${FORCE_HTTPS:-false}" + # Only if you set VITE_CV_URL: the CV is never baked into the image. + # volumes: + # - ./public/CV:/app/dist/CV:ro + read_only: true + tmpfs: [/tmp] + cap_drop: [ALL] + security_opt: ["no-new-privileges:true"] + pids_limit: 100 + mem_limit: 256m + cpus: 0.5 diff --git a/index.html b/index.html index 092657b..f7e0b73 100644 --- a/index.html +++ b/index.html @@ -2,25 +2,26 @@
+ - + -About
+{p}
++ {p} +
))} -{profile.education.institution}
-- {profile.name} ({profile.email}) is the data controller for this + {profile.name}{profile.email && ` (${profile.email})`} is the data controller for this site. No cookies, analytics, or third-party trackers are used, and nothing you do here is logged or stored on a server. Your light/dark theme choice is saved in your browser's local storage only and is never transmitted anywhere. The Contributions graph above is fetched by this site's own server, not your browser, so GitHub never - sees you as a visitor. If you email me, I'll only use your details to reply. Under UK - GDPR you can request access to or deletion of any data held about you by emailing{" "} - {profile.email}. + sees you as a visitor. If you email me, I'll only use your details to reply. + {profile.email && ` Under UK GDPR you can request access to or deletion of any data held about you by emailing ${profile.email}.`}