From 9f3ee321811a802db1d2ebf7c6d656431c39d362 Mon Sep 17 00:00:00 2001
From: Shreyas Prabhu <shreyasprabhu26@gmail.com>
Date: Mon, 5 May 2025 11:54:34 +0530
Subject: [PATCH] Add Cloud Build configuration, Dockerfile, and Nginx setup
 for application deployment

---
 Dockerfile      | 31 +++++++++++++++++++++++++++++++
 cloudbuild.yaml | 32 ++++++++++++++++++++++++++++++++
 nginx.conf      | 23 +++++++++++++++++++++++
 3 files changed, 86 insertions(+)
 create mode 100644 Dockerfile
 create mode 100644 cloudbuild.yaml
 create mode 100644 nginx.conf

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..7de3c56
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,31 @@
+# Build stage
+FROM node:20-alpine AS builder
+
+WORKDIR /app
+
+# Copy package files
+COPY package*.json ./
+
+# Install dependencies
+RUN npm install
+
+# Copy source code
+COPY . .
+
+# Build the application
+RUN npm run build
+
+# Production stage
+FROM nginx:alpine
+
+# Copy nginx configuration
+COPY nginx.conf /etc/nginx/conf.d/default.conf
+
+# Copy built files from builder stage
+COPY --from=builder /app/dist /usr/share/nginx/html
+
+# Expose port 80
+EXPOSE 80
+
+# Start nginx
+CMD ["nginx", "-g", "daemon off;"] 
\ No newline at end of file
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
new file mode 100644
index 0000000..fbe1bf2
--- /dev/null
+++ b/cloudbuild.yaml
@@ -0,0 +1,32 @@
+steps:
+  # Install dependencies
+  - name: 'node:20'
+    entrypoint: npm
+    args: ['install']
+
+  # Build the application
+  - name: 'node:20'
+    entrypoint: npm
+    args: ['run', 'build']
+
+  # Build the container image
+  - name: 'gcr.io/cloud-builders/docker'
+    args: ['build', '-t', 'gcr.io/$PROJECT_ID/cloud-build-app:$SHORT_SHA', '.']
+
+  # Deploy to Cloud Run
+  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
+    entrypoint: gcloud
+    args:
+      - 'run'
+      - 'deploy'
+      - 'cloud-build-app'
+      - '--image'
+      - 'gcr.io/$PROJECT_ID/cloud-build-app:$SHORT_SHA'
+      - '--region'
+      - 'asia-east1'
+      - '--platform'
+      - 'managed'
+      - '--allow-unauthenticated'
+
+images:
+  - 'gcr.io/$PROJECT_ID/cloud-build-app:$SHORT_SHA' 
\ No newline at end of file
diff --git a/nginx.conf b/nginx.conf
new file mode 100644
index 0000000..1ebe8d8
--- /dev/null
+++ b/nginx.conf
@@ -0,0 +1,23 @@
+server {
+    listen 80;
+    server_name localhost;
+
+    root /usr/share/nginx/html;
+    index index.html;
+
+    # Handle SPA routing
+    location / {
+        try_files $uri $uri/ /index.html;
+    }
+
+    # Cache static assets
+    location /assets {
+        expires 1y;
+        add_header Cache-Control "public, no-transform";
+    }
+
+    # Security headers
+    add_header X-Frame-Options "SAMEORIGIN";
+    add_header X-XSS-Protection "1; mode=block";
+    add_header X-Content-Type-Options "nosniff";
+} 
\ No newline at end of file
-- 
GitLab