mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-25 20:12:53 +02:00
🚀 feat(zitare-web): add Docker deployment infrastructure
- Add Dockerfile for production build - Add docker-entrypoint.sh for runtime config - Add hooks.server.ts for client-side env injection - Add zitare-web service to docker-compose.macmini.yml - Port 5012 - Depends on zitare-backend - Health check on /health endpoint
This commit is contained in:
parent
ef9bd5656d
commit
533bd90093
4 changed files with 170 additions and 0 deletions
104
apps/zitare/apps/web/Dockerfile
Normal file
104
apps/zitare/apps/web/Dockerfile
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
# Build arguments for SvelteKit static env vars
|
||||||
|
ARG PUBLIC_MANA_CORE_AUTH_URL=http://mana-auth:3001
|
||||||
|
ARG PUBLIC_ZITARE_API_URL=http://zitare-backend:3007
|
||||||
|
|
||||||
|
# Set as environment variables for build
|
||||||
|
ENV PUBLIC_MANA_CORE_AUTH_URL=$PUBLIC_MANA_CORE_AUTH_URL
|
||||||
|
ENV PUBLIC_ZITARE_API_URL=$PUBLIC_ZITARE_API_URL
|
||||||
|
|
||||||
|
# Install pnpm
|
||||||
|
RUN corepack enable && corepack prepare pnpm@9.15.0 --activate
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy root workspace files
|
||||||
|
COPY pnpm-workspace.yaml ./
|
||||||
|
COPY package.json ./
|
||||||
|
COPY pnpm-lock.yaml ./
|
||||||
|
|
||||||
|
# Copy shared packages needed by zitare web
|
||||||
|
COPY packages/shared-api-client ./packages/shared-api-client
|
||||||
|
COPY packages/shared-auth ./packages/shared-auth
|
||||||
|
COPY packages/shared-auth-ui ./packages/shared-auth-ui
|
||||||
|
COPY packages/shared-branding ./packages/shared-branding
|
||||||
|
COPY packages/shared-config ./packages/shared-config
|
||||||
|
COPY packages/shared-feedback-service ./packages/shared-feedback-service
|
||||||
|
COPY packages/shared-feedback-types ./packages/shared-feedback-types
|
||||||
|
COPY packages/shared-feedback-ui ./packages/shared-feedback-ui
|
||||||
|
COPY packages/shared-i18n ./packages/shared-i18n
|
||||||
|
COPY packages/shared-icons ./packages/shared-icons
|
||||||
|
COPY packages/shared-profile-ui ./packages/shared-profile-ui
|
||||||
|
COPY packages/shared-stores ./packages/shared-stores
|
||||||
|
COPY packages/shared-subscription-types ./packages/shared-subscription-types
|
||||||
|
COPY packages/shared-subscription-ui ./packages/shared-subscription-ui
|
||||||
|
COPY packages/shared-tailwind ./packages/shared-tailwind
|
||||||
|
COPY packages/shared-theme ./packages/shared-theme
|
||||||
|
COPY packages/shared-theme-ui ./packages/shared-theme-ui
|
||||||
|
COPY packages/shared-types ./packages/shared-types
|
||||||
|
COPY packages/shared-ui ./packages/shared-ui
|
||||||
|
COPY packages/shared-utils ./packages/shared-utils
|
||||||
|
COPY packages/shared-vite-config ./packages/shared-vite-config
|
||||||
|
|
||||||
|
# Copy zitare content package
|
||||||
|
COPY apps/zitare/packages/content ./apps/zitare/packages/content
|
||||||
|
|
||||||
|
# Copy zitare web
|
||||||
|
COPY apps/zitare/apps/web ./apps/zitare/apps/web
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
# Build shared packages that need building
|
||||||
|
WORKDIR /app/packages/shared-vite-config
|
||||||
|
RUN pnpm build
|
||||||
|
|
||||||
|
WORKDIR /app/packages/shared-auth
|
||||||
|
RUN pnpm build || true
|
||||||
|
|
||||||
|
# Build zitare content package
|
||||||
|
WORKDIR /app/apps/zitare/packages/content
|
||||||
|
RUN pnpm build || true
|
||||||
|
|
||||||
|
# Build the web app
|
||||||
|
WORKDIR /app/apps/zitare/apps/web
|
||||||
|
RUN pnpm exec svelte-kit sync
|
||||||
|
RUN pnpm build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:20-alpine AS production
|
||||||
|
|
||||||
|
# Keep same directory structure as builder so pnpm symlinks resolve correctly
|
||||||
|
WORKDIR /app/apps/zitare/apps/web
|
||||||
|
|
||||||
|
# Copy the pnpm store that symlinks point to (at /app/node_modules/.pnpm)
|
||||||
|
COPY --from=builder /app/node_modules/.pnpm /app/node_modules/.pnpm
|
||||||
|
|
||||||
|
# Copy the app's node_modules (contains symlinks to the pnpm store)
|
||||||
|
COPY --from=builder /app/apps/zitare/apps/web/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy built application
|
||||||
|
COPY --from=builder /app/apps/zitare/apps/web/build ./build
|
||||||
|
COPY --from=builder /app/apps/zitare/apps/web/package.json ./
|
||||||
|
|
||||||
|
# Copy entrypoint script
|
||||||
|
COPY apps/zitare/apps/web/docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 5012
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=5012
|
||||||
|
ENV HOST=0.0.0.0
|
||||||
|
|
||||||
|
# Health check
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD wget --no-verbose --tries=1 --spider http://localhost:5012/health || exit 1
|
||||||
|
|
||||||
|
# Run the app
|
||||||
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
|
CMD ["node", "build"]
|
||||||
13
apps/zitare/apps/web/docker-entrypoint.sh
Normal file
13
apps/zitare/apps/web/docker-entrypoint.sh
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# This script injects runtime environment variables into the SvelteKit build
|
||||||
|
# SvelteKit builds env vars at build time, but we need to inject them at runtime
|
||||||
|
# for Docker deployments where the container runs in different environments
|
||||||
|
|
||||||
|
echo "Starting Zitare Web with runtime configuration..."
|
||||||
|
echo "PUBLIC_MANA_CORE_AUTH_URL_CLIENT: ${PUBLIC_MANA_CORE_AUTH_URL_CLIENT:-not set}"
|
||||||
|
echo "PUBLIC_ZITARE_API_URL_CLIENT: ${PUBLIC_ZITARE_API_URL_CLIENT:-not set}"
|
||||||
|
|
||||||
|
# Execute the main command
|
||||||
|
exec "$@"
|
||||||
27
apps/zitare/apps/web/src/hooks.server.ts
Normal file
27
apps/zitare/apps/web/src/hooks.server.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/**
|
||||||
|
* Server Hooks for SvelteKit
|
||||||
|
* - Injects runtime environment variables for client-side use
|
||||||
|
* - Auth is handled client-side via Mana Core Auth
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { Handle } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
// Get client-side URLs from environment (Docker runtime)
|
||||||
|
const PUBLIC_MANA_CORE_AUTH_URL_CLIENT =
|
||||||
|
process.env.PUBLIC_MANA_CORE_AUTH_URL_CLIENT || process.env.PUBLIC_MANA_CORE_AUTH_URL || '';
|
||||||
|
const PUBLIC_BACKEND_URL_CLIENT =
|
||||||
|
process.env.PUBLIC_ZITARE_API_URL_CLIENT || process.env.PUBLIC_ZITARE_API_URL || '';
|
||||||
|
|
||||||
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
|
return resolve(event, {
|
||||||
|
transformPageChunk: ({ html }) => {
|
||||||
|
// Inject runtime environment variables into the HTML
|
||||||
|
// These will be available on window.__PUBLIC_*__ for client-side code
|
||||||
|
const envScript = `<script>
|
||||||
|
window.__PUBLIC_MANA_CORE_AUTH_URL__ = "${PUBLIC_MANA_CORE_AUTH_URL_CLIENT}";
|
||||||
|
window.__PUBLIC_BACKEND_URL__ = "${PUBLIC_BACKEND_URL_CLIENT}";
|
||||||
|
</script>`;
|
||||||
|
return html.replace('<head>', `<head>${envScript}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -1065,6 +1065,32 @@ services:
|
||||||
retries: 3
|
retries: 3
|
||||||
start_period: 40s
|
start_period: 40s
|
||||||
|
|
||||||
|
zitare-web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: apps/zitare/apps/web/Dockerfile
|
||||||
|
image: zitare-web:local
|
||||||
|
container_name: mana-app-zitare-web
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
zitare-backend:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
PORT: 5012
|
||||||
|
PUBLIC_ZITARE_API_URL: http://zitare-backend:3007
|
||||||
|
PUBLIC_MANA_CORE_AUTH_URL: http://mana-auth:3001
|
||||||
|
PUBLIC_ZITARE_API_URL_CLIENT: https://zitare-api.mana.how
|
||||||
|
PUBLIC_MANA_CORE_AUTH_URL_CLIENT: https://auth.mana.how
|
||||||
|
ports:
|
||||||
|
- "5012:5012"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:5012/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
calendar-web:
|
calendar-web:
|
||||||
image: ghcr.io/memo-2023/calendar-web:latest
|
image: ghcr.io/memo-2023/calendar-web:latest
|
||||||
container_name: mana-app-calendar-web
|
container_name: mana-app-calendar-web
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue