From ae928bbb9b8341bb2d4c27d44f4ad930ad815927 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 6 Aug 2025 14:57:19 +0200 Subject: [PATCH] Update Dockerfile and docker-compose.yml to change application port to 6060; add health check endpoint. Add cookie dependency to package.json and create health check API endpoint. --- Dockerfile | 8 ++++---- docker-compose.yml | 6 +++--- package.json | 2 ++ server/api/health.get.ts | 29 ++++++++++++++++++++++++++++ workflows/create-and-push-image.yaml | 5 +++++ 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 server/api/health.get.ts diff --git a/Dockerfile b/Dockerfile index edd3c1c..524c008 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,8 @@ WORKDIR /app # Copy package files COPY package*.json ./ -# Install dependencies -RUN npm ci --only=production && npm cache clean --force +# Install all dependencies (including dev dependencies for build) +RUN npm install && npm cache clean --force # Copy source code COPY . . @@ -44,11 +44,11 @@ RUN mkdir -p /app/data && chown nuxt:nodejs /app/data USER nuxt # Expose port -EXPOSE 3000 +EXPOSE 6060 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})" || exit 1 + CMD node -e "require('http').get('http://localhost:6060/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})" || exit 1 # Use dumb-init to handle signals properly ENTRYPOINT ["dumb-init", "--"] diff --git a/docker-compose.yml b/docker-compose.yml index c0c08dc..255b154 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: container_name: monacousa-portal restart: unless-stopped ports: - - "3000:3000" + - "6060:6060" volumes: # Volume for persistent data (environment files, logs, etc.) - ./data:/app/data @@ -18,7 +18,7 @@ services: # Basic configuration - NODE_ENV=production - NUXT_HOST=0.0.0.0 - - NUXT_PORT=3000 + - NUXT_PORT=6060 # Keycloak Configuration (override with your values) - NUXT_KEYCLOAK_ISSUER=${KEYCLOAK_ISSUER:-https://auth.monacousa.org/realms/monacousa-portal} @@ -50,7 +50,7 @@ services: - WAIT_FOR_SERVICES=${WAIT_FOR_SERVICES:-false} healthcheck: - test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})"] + test: ["CMD", "node", "-e", "require('http').get('http://localhost:6060/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})"] interval: 30s timeout: 10s retries: 3 diff --git a/package.json b/package.json index 3363e83..2044820 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@nuxt/ui": "^3.2.0", "@vite-pwa/nuxt": "^0.10.6", + "cookie": "^0.6.0", "formidable": "^3.5.4", "mime-types": "^3.0.1", "minio": "^8.0.5", @@ -23,6 +24,7 @@ "vuetify-nuxt-module": "^0.18.3" }, "devDependencies": { + "@types/cookie": "^0.6.0", "@types/formidable": "^3.4.5", "@types/mime-types": "^3.0.1", "@types/node": "^20.0.0" diff --git a/server/api/health.get.ts b/server/api/health.get.ts new file mode 100644 index 0000000..f43b2b4 --- /dev/null +++ b/server/api/health.get.ts @@ -0,0 +1,29 @@ +export default defineEventHandler(async (event) => { + try { + // Basic health check - can be expanded to check database, storage, etc. + const health = { + status: 'healthy', + timestamp: new Date().toISOString(), + uptime: process.uptime(), + checks: { + server: 'healthy', + // Add more checks as needed + // database: await checkDatabase(), + // storage: await checkStorage(), + // auth: await checkAuth(), + }, + }; + + return health; + } catch (error) { + throw createError({ + statusCode: 503, + statusMessage: 'Service Unavailable', + data: { + status: 'unhealthy', + timestamp: new Date().toISOString(), + error: error instanceof Error ? error.message : 'Unknown error', + }, + }); + } +}); diff --git a/workflows/create-and-push-image.yaml b/workflows/create-and-push-image.yaml index e7c2645..7271517 100644 --- a/workflows/create-and-push-image.yaml +++ b/workflows/create-and-push-image.yaml @@ -6,6 +6,9 @@ jobs: docker: runs-on: ubuntu-22.04 steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Login To Registry uses: docker/login-action@v3 with: @@ -19,6 +22,8 @@ jobs: - name: Build And Push uses: docker/build-push-action@v6 with: + context: . + file: ./Dockerfile platforms: linux/amd64 push: true tags: |