From 1b74650aa2271134d9f1f158a947cdf76aa417c4 Mon Sep 17 00:00:00 2001 From: Urban Modig Date: Thu, 9 Oct 2025 15:02:36 +0200 Subject: [PATCH] Dockerfile upd drone-config --- .dockerignore | 9 +++++++ .drone.yml | 59 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 .dockerignore create mode 100644 .drone.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cca5af3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.vscode +node_modules +.dist +dist +coverage +.vite +Dockerfile +.drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..37815e7 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,59 @@ +kind: pipeline +type: docker +name: build-test-and-push + +trigger: + event: + - push + branch: + - main + +steps: + - name: install+lint+typecheck+test + image: node:20-alpine + environment: + PNPM_HOME: /root/.local/share/pnpm + commands: + - corepack enable + - corepack prepare pnpm@9.12.0 --activate + - pnpm install --frozen-lockfile + - pnpm lint + - pnpm typecheck + - pnpm test -- --run + + - name: docker-push + image: plugins/docker:latest + settings: + context: . + dockerfile: Dockerfile + + # Registry och repo + registry: rubble.se:5000 + repo: rubble.se:5000/urban/hemhub-web + + # Inloggning (lägg in som secrets i Drone) + username: + from_secret: REGISTRY_USER + password: + from_secret: REGISTRY_PASS + + # Bygg-args till Dockerfile (Vite läser dem vid build) + build_args: + - VITE_API_BASE_URL=${VITE_API_BASE_URL} + - VITE_BASE_PATH=/hemhub/ + + # Taggar + tags: + - latest + - ${DRONE_COMMIT_SHA:0:7} + + # Sätt till false/ta bort om ditt registry har TLS + insecure: true + + environment: + # Drone-secret för backend-url, sätt i UI under repo -> Secrets + VITE_API_BASE_URL: + from_secret: VITE_API_BASE_URL + +depends_on: + - install+lint+typecheck+test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..66c0fd2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,65 @@ +# syntax=docker/dockerfile:1.7 + +############################ +# Build stage +############################ +FROM node:20-alpine AS build +WORKDIR /app + +# pnpm via Corepack +ENV PNPM_HOME="/root/.local/share/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable && corepack prepare pnpm@9.12.0 --activate + +# Installera beroenden +COPY package.json pnpm-lock.yaml* ./ +RUN pnpm install --frozen-lockfile + +# App-källor +COPY . . + +# --- Build args (styr Vite) --- +# Backend-url (ex sätts i Drone secrets) +ARG VITE_API_BASE_URL=http://localhost:8080 +# Base path för proxy under /hemhub/ +ARG VITE_BASE_PATH=/ +ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} +ENV VITE_BASE_PATH=${VITE_BASE_PATH} + +# Bygg (Vite läser env vid build) +RUN pnpm build + + +############################ +# Runtime stage (Nginx) +############################ +FROM nginx:1.27-alpine AS runtime + +# Minimal nginx-konfig med SPA-fallback +RUN <<'NGINX' sh -lc 'cat >/etc/nginx/conf.d/default.conf' +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # gzip statiska assets + gzip on; + gzip_types text/plain text/css application/javascript application/json image/svg+xml; + + # Single Page App fallback + location / { + try_files $uri /index.html; + } +} +NGINX + +# Statiska filer från builden +COPY --from=build /app/dist /usr/share/nginx/html + +# Hälsokoll (valfritt) +HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD wget -qO- http://127.0.0.1/ || exit 1 + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"]